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
SFDC@ErrorSFDC@Error 

Update Parent based on related Child record

Hi All
How can i update  parent based on related child.I have 2 object Contact and Boutique__c.
Contact is Parent and Boutique is child.
Chilld object has one picklist field with value HOT,COLD and Others.
Need to update this value in parent object.Means if i am creating one child with picklist value HOT then it will update the parent HOT
If i am creating another record with COLD vlaue it will update COLD.Like this....I have created a trigger but its working only one child record .
trigger UpdateContact on Boutique__c (after insert, after update) {
 List <contact> OppList = new List<contact>();
  for(Boutique__c DDL : Trigger.new){

    contact oppty=new contact(id=DDL.Customer_Name__c,Contact_Type__c=DDL.Visit_Type__c);
    OppList.add(oppty);
  }
  try{
  update OppList;
  }catch(DmlException de ){
   System.debug(de);
  }
}

 
Dave Pattison 6Dave Pattison 6
Is this meant to create a new Contact every time? If so the 'try' block should say 'insert OppList'. 
 
SFDC@ErrorSFDC@Error
No , Update contact every time when new child record is creating .But here the issue is update contact based on related child picklist value. Ex.I am creating new child with picklist value HOT then parent will update with this picklist value. If i am creating again new child record with value COLD then parent will update with this value..Like this
HARSHIL U PARIKHHARSHIL U PARIKH
Are you asking most recent Boutique__c record's picklist value (either HOT or COLD or Others) should be replicated on its parent contact correct?

Eg., if contct name is John Doe entered and then if someone enters 3 records of Boutique__c with HOT, HOT, and COLD then John Doe should have "COLD" as in his picklist value.

Let me know if this is the behavior you are looking for?