function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vijay kumar kvijay kumar k 

write trigger on contact to update account field based on contact field

parent object: account
   fields : contact country - Picklist values: India, Africa, America
   child object : contact
   field : Contact Area - Picklist values: Karataka, Andhra Pradesh, Kerala, South Africa, Nigeria, Kenya, California, San Fransisco, Texas

   when contact is inserted / updated, based the contact's Contact Area field the parents contact Country should change with respected country. wirte a trigger for insert, Update.
Raj VakatiRaj Vakati
Try this code
 
trigger ConnectA on Contact  (after insert,after update) {

    Map<Id,Contact> AccID = New Map<Id,Contact>();
Map<Id,Contact> oldCOn = trigger.oldMap ; 

    for(Contact con : Trigger.new){
        if( (con.contact_country__c!=oldCOn.get(con.Id).contact_country__c) || 
		   (con.Contact_Area__c!=oldCOn.get(con.Id).Contact_Area__c) ){
            AccID.add(con.AccountId);
        }
    }

    List<Account> accList = [SELECT Name, BillingStreet FROM Account WHERE id in :AccID.keySet()];

    for(Account a :accList){
		Contact c = AccID.get(a.Id) ; 
		a.Contact_Area__c = c.Contact_Area__c ; 
		a.contact_country__c = c.contact_country__c ; 
		
	}

    update accList;
}