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
Ravindra reddy MRavindra reddy M 

in @future method parameters we cannot use object as parameters.if i need to updated 10 users so it fires 10 times but the requirement is all the 10 records updated at a time means method was called only one time in salesforce

HI all,
 in @future method parameters we cannot use object as parameters.if i need to updated 10 users so it fires 10 times but the requirement is all the 10 records updated at a time means method was called only one time 
plz help  to reloslove this ,thanks in advance .

Thanks & Regards
Ravindra
Best Answer chosen by Ravindra reddy M
Nagendra ChinchinadaNagendra Chinchinada
Hi Ravindra,

You can call that method once and pass all 10 Ids of users atonce in a Set<Id>. In future metode, use an SOQL query to fetch records of all thses 10 users in update the required fields, Update the entire list.

Call below method only once by passing  all 10 Ids of users at once in a Set<Id>
 
global class FutureMethodUserRecordProcessing
{
    @future
    public static void updateUsers(List<ID> userIds)// Pass all user user Ids as one Set
    {   
         // Get those records based on the IDs
         List<User> usersList = [SELECT id,email FROM User WHERE Id IN :userIds];
          
		  // Process records
		 for(User usr : usersList){
		 //Update required fields here
		 }
		 
		 Update usersList; //Update entire list at a time
		
    }
}
Please let me know if it helps.

Thanks,
Nagendra
 

All Answers

Akhil AnilAkhil Anil
Hi Ravindra,

I am a bit confused about what you are trying to achieve. Still, to address the first question that you asked regarding using objects as parametes, the answer is that even though objects cannot be used as paramaters, you can still use IDs or List of IDs as parameters in the future method and then query the object data within the future method using the list of IDs. That should work out for you !

Kindly mark it as an answer if that resolves your problem.
Nagendra ChinchinadaNagendra Chinchinada
Hi Ravindra,

You can call that method once and pass all 10 Ids of users atonce in a Set<Id>. In future metode, use an SOQL query to fetch records of all thses 10 users in update the required fields, Update the entire list.

Call below method only once by passing  all 10 Ids of users at once in a Set<Id>
 
global class FutureMethodUserRecordProcessing
{
    @future
    public static void updateUsers(List<ID> userIds)// Pass all user user Ids as one Set
    {   
         // Get those records based on the IDs
         List<User> usersList = [SELECT id,email FROM User WHERE Id IN :userIds];
          
		  // Process records
		 for(User usr : usersList){
		 //Update required fields here
		 }
		 
		 Update usersList; //Update entire list at a time
		
    }
}
Please let me know if it helps.

Thanks,
Nagendra
 
This was selected as the best answer