Apex trigger to set contact record detail same as account details - salesforce (i.e contact lastname = account lastname)
Handler class:
public class AccountTrigger {
public static void createContact(List<Account> accounts) {
List<Contact> contact = new List<Contact>();
for(Account acc : accounts){
Contact con = new Contact(LastName = acc.name,
AccountId=acc.id,
MailingStreet=acc.BillingStreet,
MailingCity=acc.BillingCity,
MailingState=acc.BillingState,
MailingPostalCode=acc.BillingPostalCode,
MailingCountry=acc.BillingCountry,
Fax=acc.Fax);
contact.add(con);
}
insert contact;
}
}
public class AccountTrigger {
public static void createContact(List<Account> accounts) {
List<Contact> contact = new List<Contact>();
for(Account acc : accounts){
Contact con = new Contact(LastName = acc.name,
AccountId=acc.id,
MailingStreet=acc.BillingStreet,
MailingCity=acc.BillingCity,
MailingState=acc.BillingState,
MailingPostalCode=acc.BillingPostalCode,
MailingCountry=acc.BillingCountry,
Fax=acc.Fax);
contact.add(con);
}
insert contact;
}
}
Trigger:
trigger AccountTrigger on Account (after insert , after update ) {
AccountTriggerHandler.createContact(Trigger.new);
}
AccountTriggerHandler.createContact(Trigger.new);
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment