function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Trigger on Account object to handle insert and update. trigger insertcontact on Account (before insert,after insert,after update) { if(trigger.isbefore && trigger.isinsert) { ContactNameUpdate.accountmethod(Trigger.new); } if(trigger.isafter && trigger.isinsert) { ContactNameUpdate.contactMethod(Trigger.new); } }
public class ContactNameUpdate { // Method to handle the contact inserts. public static void contactMethod(List<Account> accList){ List<Contact> conList = new List<Contact>(); for(Account acc : accList) { Contact con = new Contact(AccountId = acc.Id); List<String> nameStr = acc.Name.split(' '); if(nameStr.size()>0) con.LastName = nameStr[0]; if(nameStr.size()>1) con.FirstName = nameStr[1]; conList.add(con); } insert conList; } }
Below is the sample which you can modify to your needs.
Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.
Best Regards,
Sandhya