You need to sign in to do that
Don't have an account?

Create 2 custom fields on account : 1. Contact Last updated ( date time ) 2. Contact Updating count ( number ) When ever a child contact record is updated, update the date/time field “Contact Last updated” field on parent account, also increment the cou
Create two custom fields on account :
1. Contact Last updated ( date time )
2. Contact Updating count ( number )
When ever a child contact record is updated, update the date/time field “Contact Last updated” field on parent account, also increment the counter field “Updating count” with plus one. So that if the child contact record is updated 3 times the counter field “Updating count” will have the value 3, and the “Contact Last updated” will have the value of the date/time it was last updated.
1. Contact Last updated ( date time )
2. Contact Updating count ( number )
When ever a child contact record is updated, update the date/time field “Contact Last updated” field on parent account, also increment the counter field “Updating count” with plus one. So that if the child contact record is updated 3 times the counter field “Updating count” will have the value 3, and the “Contact Last updated” will have the value of the date/time it was last updated.
Here is the solution:
Trigger:
trigger Contacttrigger on Contact (after update) {
if(trigger.isAfter && trigger.isupdate){
Updatecontact.Updatecontactaccount(trigger.new);
}
}
Apex Class:
public class Updatecontact {
public static void Updatecontactaccount(List<contact> contactlist){
Set<Id> accountIdset = new set<ID>();
for(Contact con:contactlist){
accountIdset.add(con.AccountId);
}
List<Account> acclist = new List<account>();
acclist = [select Id,Contact_Last_Updated__c,Contact_updating_count__c,Name from account where Id IN:accountIdset];
for(Account acc:acclist){
acc.Contact_Last_Updated__c = Datetime.now();
if(acc.Contact_updating_count__c !=null){
acc.Contact_updating_count__c = acc.Contact_updating_count__c+1;
}
else{
acc.Contact_updating_count__c= 1;
}
}
update acclist;
}
}