You need to sign in to do that
Don't have an account?
sooraj babu
how to write a class for trigger
trigger copyaddresstrigger on Contact (before insert,before update) {
for(contact address : trigger.new)
{
if(address.Copy_Address__c ==True)
{
address.OtherStreet = address.MailingStreet ;
address.OtherCity = address.MailingCity;
address.OtherState = address.MailingState;
address.OtherPostalCode = address.MailingPostalCode;
address.OtherCountry = address.MailingCountry;
}
else
{ address.OtherStreet = null ;
address.OtherCity = null;
address.OtherState = null;
address.OtherPostalCode = null;
address.OtherCountry = null;
}
}
}
for(contact address : trigger.new)
{
if(address.Copy_Address__c ==True)
{
address.OtherStreet = address.MailingStreet ;
address.OtherCity = address.MailingCity;
address.OtherState = address.MailingState;
address.OtherPostalCode = address.MailingPostalCode;
address.OtherCountry = address.MailingCountry;
}
else
{ address.OtherStreet = null ;
address.OtherCity = null;
address.OtherState = null;
address.OtherPostalCode = null;
address.OtherCountry = null;
}
}
}
In order to write an Apex class from the trigger, you need to pass the Trigger. New in the trigger class.
Please check the below post to learn about Trigger Framework.
1) http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Please refer to the code
Create Trigger Like below
Handler like below
I have gone through your problem. Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora