You need to sign in to do that
Don't have an account?
sf_123
Apex triggere help
Hi , I have just started with salesforce and i wrote a basic trigger for Contacts. I have created a custom field "des" on Contacts and i want it to have a default value from a standard Account field: Description whenever a new contact is created.
The trigger code:
trigger copyvalue on Contact (before insert,before update) {
for(Contact a:Trigger.new)
{ a.Des__c=a.Account.Description; } }
This is not helping and i do not see the account's description value in the contact custom field. Please help!!!! Thanks a lot.
Please try the following:-
trigger copyvalue on Contact (before insert,before update)
{
for(Contact a:Trigger.new)
{
Account acc =[Select id, Description from Account where id=: a.Accountid];
a.Des__c=acc.Description;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
That is a good suggestion, but is not bulk safe.
If more than 20 contacts were inserted or updated in batch, the Query limit would be exceeded.
A better practice would be to leverage a map to hold the data.
you can also use a workflow rule with a field update, no need to create a trigger
Thanks guys!!!! The code works......but one small problem though,I want to see the value as default when i open a new contact......Is this possible??