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
Saurabh Bisht 19Saurabh Bisht 19 

Using Trigger design pattern and trigger on opportunity

Make two address fields in opportunity , correspondence address and permanent address. We have to fill both the fields with different addresses, if anyone of them is empty then generate message, and if the checkbox is selected then both the addresses should be same.

pls code it asap
wesegi marrywesegi marry

The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.Dairy Queen Happy Hour
AnkaiahAnkaiah (Salesforce Developers) 
Hi Saurabh,

try with below code. modify the field names as per your org.
trigger OpportunityTrigger on Opportunity (before insert,before update) {

if( trigger.Isbefore && (trigger.Isinsert || trigger.Isupdate)){
    
    for(opportunity opp: trigger.new){
        
        If(opp.correspondence_address__c=='' || opp.correspondence_address__c== NULL || opp.permanent_address__c=='' || opp.permanent_address__c==NULL ){
            
            opp.adderror('correspondence_address__c and permanent_address__c can not be blank!!');
        }else if(opp.sameAddress__c==true){
           
          opp.correspondence_address__c= opp.permanent_address__c;
        }
    }
}

}
If this helps, Please mark it as best answer.

Thanks!!