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
Myra Wilson 9Myra Wilson 9 

Need to incorporate record type into code for round robin

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';
Saad Ansari 13Saad Ansari 13
Add condition 
c.RecordTypeId != Trigger.oldmap.get(c.Id).RecordTypeId

Also will need to add RecordTypeId column in SOQL