You need to sign in to do that
Don't have an account?
its never shows in description - error
trigger tiggercon on Account (before insert , before update)
{
for(Account a : trigger.new)
{
List<Contact> contact = [SELECT id , FirstName , LastName , Email
FROM Contact WHERE accountId = : a.Id];
for(Contact c : contact)
{
System.debug ('contact id [' + c.id + '] , FirstName[' + c.FirstName + '] , LastName[' + c.LastName + ']');
c.Description = c.FirstName + ' ' + c.LastName ;
update c;
}
}
}
i worte the code in account object , den created account and contact ,
once i saved contact field but it never shows the description box in the firstname and lastname
can u help me what problem ll happen
Regards,
Ganez
If you created the account and then the contact, the trigger won't fire when you create the contact, as its on an account. You'd need to update the account to get it to process the new contact.
trigger tiggercon on Account (before insert , before update)
{
for(Account a : trigger.new)
{
List<Contact> contact = [SELECT Description, id , FirstName , LastName , Email FROM Contact WHERE accountId = : a.Id];
for(Contact c : contact)
{
System.debug ('contact id [' + c.id + '] , FirstName[' + c.FirstName + '] , LastName[' + c.LastName + ']');
c.Description = c.FirstName + ' ' + c.LastName ;
}
update c;
}
}
and yes, as bob_buzzard says the trigger must be on contact
trigger tiggercon on Contact (before insert , before update)
{
for(Contact c : trigger.new)
{
c.Description = c.FirstName + ' ' + c.LastName ;
}
}
Hi,
your trigger will invoke on account insert or update.
You have written query within for loop, this voilates basic rules in apex. you should avoid query within for loop under all circumstances.