You need to sign in to do that
Don't have an account?
Sindhu Ambarkar
After update event issue
Hi,
Iam trying to copy the address field of account to contact whenever the contact is inserted or updated.It is working fine when the contact is created but when iam trying to update the contact getting the DML exception.CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
Please help me
* After the contact is created shipping address fields of account should be copied to contacts */
trigger ShippingAddresscopytoContact on Contact (after insert,after update)
{
if(trigger.isInsert||trigger.isUpdate)
{
List<Contact> Listofcontacts=[SELECT id,OtherStreet,OtherCity,OtherCountry,OtherPostalCode,OtherState,Account.shippingStreet,Account.shippingCity,Account.shippingState,Account.shippingCountry,Account.shippingPostalCode FROM Contact WHERE ID IN:trigger.new];
for(Contact c:Listofcontacts)
{
System.debug('c.Account.shippingStreet;'+c.Account.shippingStreet);
c.OtherStreet=c.Account.shippingStreet;
c.OtherCity=c.Account.shippingCity;
c.OtherState=c.Account.shippingState;
c.OtherCountry=c.Account.shippingCountry;
c.OtherPostalCode=c.Account.shippingPostalCode;
} //End of for loop
Database.update(Listofcontacts);
} //End of if
Iam trying to copy the address field of account to contact whenever the contact is inserted or updated.It is working fine when the contact is created but when iam trying to update the contact getting the DML exception.CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
Please help me
* After the contact is created shipping address fields of account should be copied to contacts */
trigger ShippingAddresscopytoContact on Contact (after insert,after update)
{
if(trigger.isInsert||trigger.isUpdate)
{
List<Contact> Listofcontacts=[SELECT id,OtherStreet,OtherCity,OtherCountry,OtherPostalCode,OtherState,Account.shippingStreet,Account.shippingCity,Account.shippingState,Account.shippingCountry,Account.shippingPostalCode FROM Contact WHERE ID IN:trigger.new];
for(Contact c:Listofcontacts)
{
System.debug('c.Account.shippingStreet;'+c.Account.shippingStreet);
c.OtherStreet=c.Account.shippingStreet;
c.OtherCity=c.Account.shippingCity;
c.OtherState=c.Account.shippingState;
c.OtherCountry=c.Account.shippingCountry;
c.OtherPostalCode=c.Account.shippingPostalCode;
} //End of for loop
Database.update(Listofcontacts);
} //End of if
If you want to manipulate the fields ON a contact when it is being updated - you need to do it in a before update trigger - and all you need to do then is set the values of "c" in the before update trigger (which runs before the contact is commited to the database) and then those values you add will be sent in with the update as it happens anyway (ie. you don't need to do Database.update(listofcontacts).
you can still keep that all in the same trigger. just drop the update line and change the trigger event to before update. You might larely be there straight away.
I need to use update statement because of after insert event.Iam not able to get it.
Thanks,
Sindhu
they won't ever "clash"