You need to sign in to do that
Don't have an account?
mhitt
Add if condition to code (new to apex)
Hello!
I have been using Salesforce for a couple of years now, but I am starting to dip my toes in Apex. In the past we have utalized offshore resources, but to make a long story short we don't want to soely rely on them for coding and instead call them for larger projects. I've found where the new condition needs to be added, but I'm not 100% sure what needs to be done. Basically, I want to say "if custom checkbox = true, dont update the owner field". Could I please have some help adding the new condition?
Thanks a bunch!
Here is the current code block:
I have been using Salesforce for a couple of years now, but I am starting to dip my toes in Apex. In the past we have utalized offshore resources, but to make a long story short we don't want to soely rely on them for coding and instead call them for larger projects. I've found where the new condition needs to be added, but I'm not 100% sure what needs to be done. Basically, I want to say "if custom checkbox = true, dont update the owner field". Could I please have some help adding the new condition?
Thanks a bunch!
Here is the current code block:
//Set the Order Owner with Order Sales Rep public static void UpdateOrderOwner(list<Order> listNew, map<id,Order> mapOld){ RTT_Setting__mdt DefOwnSett = [SELECT Id, DeveloperName, Value__c FROM RTT_Setting__mdt where DeveloperName='Default_Residential_Order_Owner' limit 1]; for(Order rec: listNew ){ if(rec.RecordTypeId==vResOrderRecTypeId){ if(mapOld.isEmpty() ||rec.Primary_Sales_Rep__c <> mapOld.get(rec.Id).Primary_Sales_Rep__c){ if(rec.Primary_Sales_Rep__c == null ){ rec.OwnerId=DefOwnSett.value__c; } else { rec.OwnerId=rec.Primary_Sales_Rep__c; } } }
Just add your condition in existing if condition itself like below:
for(Order rec: listNew ){
if(rec.RecordTypeId==vResOrderRecTypeId && rec.New_Custom_Field__c == False){
if(mapOld.isEmpty() ||rec.Primary_Sales_Rep__c <> mapOld.get(rec.Id).Primary_Sales_Rep__c){
if(rec.Primary_Sales_Rep__c == null ){
rec.OwnerId=DefOwnSett.value__c;
}
else {
rec.OwnerId=rec.Primary_Sales_Rep__c;
}
}
}
}
Thanks,
Maharajan.C