• Myra Wilson 9
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I am trying to create a round robin assignment on contacts in my org. I found code online but I need to add a line for the code to trigger upon the change of the record type and I am unsure how to do that.

trigger contacttrigger on Contact (before insert) {
    if(Trigger.isBefore){
        Double roundRobinValue = 1;
        List<Contact> conList = [SELECT Id, Round_Robin_ID__c, CreatedDate FROM Contact where Round_Robin_ID__c  != null
                                 order by CreatedDate desc limit 1];
        if(conList != null && conList.size()>0){
            roundRobinValue = conList[0].Round_Robin_ID__c;
        }

        for(Contact c : Trigger.New){
            system.debug('###Round Robin Value : '+roundRobinValue);
            if(roundRobinValue == 18){
                roundRobinValue = 1;
                c.OwnerId = '0057F000002FrWT';
            }
            else if(roundRobinValue == 2){
                roundRobinValue++; 
                c.OwnerId = '0057F000005vkd1';
            }
            else if(roundRobinValue == 3){
                roundRobinValue++; 
                c.OwnerId = '0057F000005vkd1';