You need to sign in to do that
Don't have an account?
Can you Tell me why My code is working ?
When Primary Contact is True then only selected Contact address is same as Account address
trigger UpdateAddress on Contact (after update) {
Set<Id> contactIds = new Set<Id>();
for (Contact a : Trigger.new) {
Contact old = Trigger.oldMap.get(a.Id);
if (a.BillingStreet != old.BillingStreet || ...) {
contactIds.add(a.Id);
}
}
if (contactIds.size() > 0) {
Account[] updates = [
select Id, AccountId
from Account
where AccountId in :contactIds
];
for (Account c : updates) {
Contact a = Trigger.newMap.get(c.ContactId);
c.BillingStreet = a.BillingStreet;
...
}
update updates;
}
}
Are you trying to copy the address from Account to Contact or contact to Account. The logic looks like updating the contact address with Account address and written the logic on Contact After context which would be wrong.
Thanks,
Thanks for the update
Contact to Account // while Updates or deleted
Hi Sai,
I am new in Salesforce
Could you please tell me the exact code
Can you check the below trigger on contact object. Here i am updating MailingStreet from contact to billingstreet on account. Same way you can update what ever field you need.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hi Mukesh,
Error showing in 10 Line
Please tell me
Your code is saved successfully but not working
Please use below:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Hello Mukesh
I think problem is Primary_contact__c is Contact Field not Account Field
Please use below code and according to this code you should have Primary_Contact__c field on contact object
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Tha above code which I shared will copy the MailingStreet from Contact to billingstreet on Account. Can you check it. I have checked and it is working as expected. You have to edit the MailingStreet on contact such that old value is not equal to new value.
Thanks,
Hi Mukesh,
I have created a Field same name Account as well as Contact and
I have created also Check Box Field Name - Primary_contact__c on Contact Object
but Error only 10 line
It's my mistake because i am using notepad for type the code , I hope this should be work
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh