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
Jennis AndelinJennis Andelin 

Process automation to create tasks - "too many SOQL queries"

I'm trying to create a process automation where a list of tasks is created when a project is created. Our project managers have a set list of tasks for their projects, and we want them to be able to create a project and automatically see the list of tasks they have to do, without putting in all the tasks manually for every project they have. We have about 35 tasks we want to put in, but when I do this on process builder it sends error messages about "too many SOQL queries." I talked to a Salesforce rep and they said I needed to get help from a developer about it, something about reducing the number of SOQL triggers fired. Is this something that can only be done by writing or modifying APEX code triggers (and if so, what specifically needs to be done - I don't know how to write APEX triggers) or is there something I can change in process builder to put in all the tasks we need and stop getting error messages?
Britto Fernandez 2Britto Fernandez 2
Please share current logic. 

Where are you maintaining 35 auto tasks?
sakhisakhi
Please share triggers written on task object so that optimization possibilities can be seen .
Jennis AndelinJennis Andelin
I'm just working in process builder. Since each task has to be associated with a milestone, I first created a process that makes milestones when a project is created, and now I'm working on a process that creates a list of tasks for each milestone.
User-added image
But I haven't been able to get over 9 tasks without getting these error messages
User-added image
sakhisakhi
Please paste code of your Milestone1_Milestone_trigger_utility to check SOQL optimizations .
Jennis AndelinJennis Andelin
Where do i find that?
Jennis AndelinJennis Andelin
So basically I'm needing to optimize the SOQL triggers so I can have the amount of tasks I need without getting the error messages about too many SOQL queries. Where can I do this? I'm not finding any kind of option in process builder to optimize SOQL. Please help!!!!
Jennis AndelinJennis Andelin
Or if someone could help me write the apex trigger I would need to create tasks
sakhisakhi
trigger CreateTaskOnProject on Project__c(after insert) {
    List<Task> lTask = new List<Task>();
      Task t;
      if(Trigger.isAfter) {
        if(Trigger.isInsert) {
           for(Project__c l: Trigger.new) {

               if(** YOUR process builder condition goes here ****){
                 t = new Task(); 
                 t.OwnerId = l.OwnerId;
                 t.Subject = 'Property';
                 t.Priority = 'Normal';
                 t.Status = 'Not Started';
                 t.Type = 'Action';
                 lTask.add(t);   
//Add any other fields value as needed 
               }
            }
            if(!lTask.IsEmpty())
                insert t;
           }        
      }
}
Please take reference from above sample .Replace with real object API name .It should help .