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
Geoffrey CGeoffrey C 

Using assignment rules after criteria I trigger.

I rarely code, so please bear with me if I'm way off....

I found this 'Auto Champion' article on creating a class and running it from the Process Builder.  https://automationchampion.com/tag/run-case-assignment-rules-for-process-builder/.  The process builder does not work when the record is edited by the pardot connector user.  My first questions is why doesnt the ProcessBuilder work when the record is edited by the PardotConnectorUser?  My second question is, will a trigger work?  If so something like this:   

Apex Trigger (not working):

trigger AssignWamLead on Lead (After Update) {
  for( lead l : trigger.new){
  if(l.rating == 'Warm' || 
     l.rating == 'Hot')
     AssignLeadsUsingAssignmentRules.LeadAssign(l.Id);
    }
}


Calls this Apex class: 

public class AssignLeadsUsingAssignmentRules
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            Lead Leads=[select id from lead where lead.id in :LeadIds];
            Leads.setOptions(dmo);
            update Leads;
   }
}

- Geoff