Last active
November 2, 2023 21:22
-
-
Save nhocki/a4f135350b812930b8ba616da0d3ebf9 to your computer and use it in GitHub Desktop.
Salesforce connected app plugin to add the AccountID to SAML attributes for community users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class MyConnectedAppPlugin extends Auth.ConnectedAppPlugin { | |
global override Map<String,String> customAttributes(Id userId, Id connectedAppId, Map<String,String> | |
formulaDefinedAttributes, Auth.InvocationContext context) { | |
// Get the user's associated contact | |
User u = [SELECT Id, ContactId FROM User WHERE Id = :userId]; | |
if(u.ContactId != null){ | |
Contact c = [SELECT AccountId FROM Contact WHERE Id = :u.ContactId]; | |
// Add the AccountId to your custom attributes map | |
formulaDefinedAttributes.put('organization_ids', c.AccountId); | |
} | |
formulaDefinedAttributes.put('salesforce_integration_id', 'SALESFORCE_INTEGRATION_ID'); | |
return formulaDefinedAttributes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment