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
ramkramk 

create method in apex

public static void insert task

{

   For each agent in agent role

  instantiate task obj

populate task object

insert task

 

 

 

 }

 

how to write for each in apex.....

sfdcfoxsfdcfox

You'd use the for( datatype varname : collectionvar ) syntax. Given you've provided only pseudo-code, here's a hypothetical use case:

 

Task[ ] tasks = new Task[ 0 ];
for( user agent : [SELECT Id FROM User WHERE Role.Name = 'Some Role'] ) {
  tasks.add( new Task( OwnerId = agent.id, subject = 'To-Do', ActivityDueDate = Date.Today( ).addDays( 7 ) ) );
}
insert tasks;