You need to sign in to do that
Don't have an account?
meghanadh G
Whenever contact is inserted/updated, and if contact first name is blank, then auto populate the contact first name with Account name. I've written the following trigger code. can you suggest the best approach for it
Trigger poppulateFirstNameFromAccount on Contact (before insert, before update)
{
for(Contact Con: trigger.new)
{
if(String.isBlank(contact.FirstName))
{
contact.FirstName = contact.Account.Name;
}
}
}
{
for(Contact Con: trigger.new)
{
if(String.isBlank(contact.FirstName))
{
contact.FirstName = contact.Account.Name;
}
}
}
you can use the following code, It will work as per your request.
Create one trigger and one handler class having the name "poppulateFirstNameFromAccountHandler".
Please mark it as Best Answer if the above information was helpful.
Thanks.
Hi Meghanadh,
You can refer to the below code:
At the time of writing code you should avoid SOQL queries inside the loop. It may exceed the govener limit.
Please mark it as best answer if it helps.
Thanks,