function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MantoManto 

Custom JIT Handler

We are trying to Implement Custom JIT handler for one of our communities. Our main requirement isto create a community user, only when there is a contact record exists with 'student' record type. In ‘createUser’ method, before checking whether a contact exists, I need to make sure the request is for this particular community access. I was expecting communityId to be passed to the method and I can use that Id to verify the community. However communityId is null when createUser method gets called with NO existing user record. Here is the documentation link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_Auth_SamlJitHandler.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_Auth_SamlJitHandler.htm" style="color:#0563c1; text-decoration:underline)
communityId : The ID of the community. This parameter can be null if you’re not creating a community user.
This description is more confusing, as the decision to whether create a user or not is taken within this method. Since the SSO setup is same for other communities as well, I need to make sure I am creating new users for access top this community only.
Here is what my logic is:

global User createUser(Id samlSsoProviderId, Id communityId, Id portalId, String federationIdentifier, Map<String, String> attributes, String assertion) {

if(communityId != null && communityName == 'My New Community Name')
{
// Query User records with federation id = email, if found , return user
// if not, query contacts with email, if found create a new user and return newly created user (do not insert)
// return null if a matching contact not found
// note: I get community name using ConnectApi class, passing community Id
}
}

global void updateUser(Id userId, Id samlSsoProviderId, Id communityId, Id portalId, String federationIdentifier, Map<String, String> attributes, String assertion) {
   // get user with matching federation id and activate if inactive
}



Why is communityId null in createUser method?
In what other scenarios, createUser and updateUser methods gets called?
If communityId is null for createUser always, is it possible to pass this info as a key value pair in attributes map by the IDP provider? 
Please help