[SalesForce] System.LimitException: Too many future calls: 51

We have an DataLoad activity.Query users where KCS Role /= null For any users that Knowledge License / TRUE.

Thanks in Advance

Best Answer

Salesforce imposes a governor limit that states no more than 50 future calls may be made in a single request. Take a look at the docs. The governor limit is not about 51 records being called/processed inside a future call, it's about the number of future calls in a single request. In your case here you are calling the future method for each user.

....
for(User u:trigger.new){
    if(u.Synchronize_with_Flexera_Member__c == true && !system.isbatch() && !system.isfuture() && !system.isScheduled()){
        FlexeraMemberCreationHandler.FlexeraMemberCreation(u.id); 
    }
}  
....

You will need to modify your future method to accept a list of these user ids and call once from your UserMasterTrigger. You will end up with something like the following in UserMasterTrigger after modifying FlexeraMemberCreationHandler.FlexeraMemberCreation method:

List<Id> userIds =  new List<Id>();
for(User u:trigger.new){
    if(u.Synchronize_with_Flexera_Member__c == true && !system.isbatch() && !system.isfuture() && !system.isScheduled()){
        userIds.add(u.Id);
    }
} 
if (userIds != null) FlexeraMemberCreationHandler.FlexeraMemberCreation(userIds);
Related Topic