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
Gopesh Vardhan Singh 8Gopesh Vardhan Singh 8 

Updating Parent Object's field on the basis of Child Object's Checkbox field.

Suppose I have to Objects , ACCOUNT and CONTACT , I want to update one of the field of Account(COUNTRY) as same as field  of the Contact's field(COUNTRY NAME) ,on the basis  of one of the  field of Contact which is of CheckBox Type.

If checkbox is ticked , only then the updation  is required.

They are related to each other through relationship.
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Gopesh, 

Relatioship is master-detail OR Lookup.

If Master-detail - 
Then simply you can have workflow with entry criteria "When checkbox is cheked" to update the value on parent.

If the relationship is not master-detail, then have look at this - 
https://success.salesforce.com/answers?id=90630000000CswgAAC


Thanks,
Sumit Kumar Singh

 
Rupal KumarRupal Kumar
Hi Gopesh,
             You  create Workflow with entry criteria "checkbox is cheked" to update the value on parent.

Or Use Trigger-
trigger UpdateAccAddress on Contact (after insert, after update) {
  Map<ID, Account> parentOpps = new Map<ID, Account>();
  List<id> listIds = new List<id>();

  for (Contact childObj : Trigger.new ){
    listIds.add(childObj.Accountid);
   
  }

  
  parentOpps = new Map<Id, Account>([SELECT id, ShippingCountry,(SELECT ID, upate_adress__c,MailingCountry FROM Contacts ) FROM Account WHERE ID IN :listIds]);

  for (Contact quote: Trigger.new){
   if(quote.upate_adress__c==True && quote.upate_adress__c !=null){
     Account myParentOpp = parentOpps.get(quote.accountid);
     myParentOpp.ShippingCountry = quote.MailingCountry ;
  }
}
  update parentOpps.values();
}


ShippingCountry- Account field
MailingCountry--contact field
upate_adress__c - Checkbox field
 Account field update to contact field when  Checkbox field is check.


Thanks,
Rupal Kumar.
http://www.mirketa.com