You need to sign in to do that
Don't have an account?

trigger on account
Hi,
I am new to triggers. I wanted to assign FirstName and LastName to customFields, which I have tried as follows.
PLease improve the code. Any help will be appreciated.
trigger copyFirstNameLastName on Account (before insert) { for(Account ac:trigger.new){ List<Account> acc = new List<Account>([Select id,FirstName,LastName from Account Where id IN :Trigger.new]); for(Account a:acc){ if(acc.IsPersonAccount==true){ if(!acc.isEmpty()){ acc.First_Name__pc = acc.FirstName; acc.Last_Name__pc = acc.LastName; } } update acc; } } }
-- Thanks in Advance --
Because you're doing this as a "before insert" trigger, you don't need to use the update function. You could just do it like this:
All Answers
Because you're doing this as a "before insert" trigger, you don't need to use the update function. You could just do it like this:
for(Account acc:trigger.new){
if (acc.IsPersonAccount == true) {
acc.First_Name__c = acc.FirstName;
acc.Last_Name__c = acc.LastName;
}
}
}