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
Tyler HarrisTyler Harris 

Need to Bulkify Asynchronous Callout

I'm getting a Too many Async calls created on Class.userAddWorkround: line 8, column 1. I have a trigger making an async call to inactivate Contact and vice-versa. I created the class to receive a list of ids to process. I thought the list would 'bulky' enough to process all in 1 call. What am I missing?

Trigger flipPartnerAccess
trigger flipPartnerAccess on Contact (after update) {
	
    List<User> potentialUsers = [SELECT Id, ContactId FROM User WHERE Profile.userlicense.name = 'Partner Community Login'];
    Map<Id, User> emailToUserMap = new Map<Id, User>();
    List<Id> usersToDrop = new List<Id>();
    
    for(User u : potentialUsers){
        if(u != null){
        emailToUserMap.put(u.ContactId, u);
        }
        
    }

    for(Contact con : Trigger.new){
        if(con.Status__c =='Inactive'){
            usersToDrop.add(emailToUserMap.get(con.id).id);

    }
         
        }
    if(usersToDrop !=null){
            userAddWorkRound uak = new userAddWorkRound(usersToDrop);
    }

}

userAddWorkRound
Future
public class userAddWorkRound {
//Class is a workaround for the MIXED_DML_OPERATION, DML operation error on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User
    
    public userAddWorkRound(List<Id> uid){
        List<Id> UserID = uid;
        system.debug(UserID);
            if(!system.isFuture()){
            AddUserAccessObject(UserID);
            }
        
    }
    
@future
private static void AdduserAccessObject(List<id> uid){
    system.debug('running');
    List<User> u = [SELECT id FROM User WHERE id = :uid ];  
    system.debug(u);
    if(u.size() != null){
        for(User use:u){
            if(use.IsActive =true){
            use.IsActive =false;
            }
        }
         
  update u;

    }

}
}

Thanks for your help.
 
@Karanraj@Karanraj
Check whether the particular trigger is executed more than once in the same execution flow. Put a debug statement in the trigger code and see how many its trigger is called. There might be an another operation which fires this trigger code again. Check this link to see how to control recursive call - https://help.salesforce.com/apex/HTViewSolution?id=000199485&language=en_US
Tyler HarrisTyler Harris
Hi Karanraj, I put a System.debug('run') and when the trigger fires it only outputs once. 15:30:11:786 USER_DEBUG [3]|DEBUG|run