Skip to content

Instantly share code, notes, and snippets.

@nhocki
Last active November 2, 2023 21:22
Show Gist options
  • Save nhocki/a4f135350b812930b8ba616da0d3ebf9 to your computer and use it in GitHub Desktop.
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
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