You need to sign in to do that
Don't have an account?
raj jordan
trigger to update the related fields?
i want to create description custom fields on account and contact object
now i want to create a trigger on account object such that when i insert a record on account object contact shoul also be created with with the custom field updated same as account
please help me to achieve this
now i want to create a trigger on account object such that when i insert a record on account object contact shoul also be created with with the custom field updated same as account
please help me to achieve this
Description is already standard field on Account object and as well as on Contact object. You don't need to create this field on both objects. Mark this best answer if this helps.
Thank you.
i have done this and am getting the required result
but when am updating account another contact is being created but i want the same inserted contact to get updated
help me to achoeve this
Thanks,
Jordan
{
List<Contact> con = new List<Contact>();
Set<Id> setOfAccounts = new Set<Id>();
for(Account acc :Trigger.New)
{
setOfAccounts.add(acc.Id);
}
List<Contact> accountContacts = [Select id,name,description from contact where accountid in :setOfAccounts]
for(Account a : Trigger.new)
{
if(!accountContacts.size()>0 && a.Description != null)
{
Contact ct = new Contact();
ct.lastname = a.name;
ct.AccountId = a.Id;
ct.Description = a.Description;
con.add(ct);
}
else if (a.Description != null){
for(Contact c : accountContacts)
{
c.Description = a.Description;
con.add(ct);
}
}
}
upsert con;
}
Mark this best answer if this helps.
Thank you.