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
Shivom Verma 34Shivom Verma 34 

update parent status based on child status

3 Childs are different status then parent status should update with least child case status Ex: Child1='Status3', Child2='Status4', Child3='Status3' then parent status='Status3'

3 child are same status value then the parent should update with the same child status
ANUTEJANUTEJ (Salesforce Developers) 
Hi Shivom,

I think you can use a simple trigger that checks the maximum count for the selected picklist values in the child records and update the parent, this can be done before insert and update.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Shivom Verma 34Shivom Verma 34
Hii Anutej,
can u provide some references or any code
thanks
Malika Pathak 9Malika Pathak 9

Hi Shivom Verma,

Please find the solution.

public static void method1(List<Contact> contactList){
        
        List<Contact> contactList1 = new List <Contact>();
        contactList1 =[select id,accountid,name,Status__c from contact where accountid!=null and id IN :contactList];
        
        List<id> conId = new List<id>();
        for(Contact c:contactList1){
            conId.add(c.accountId);
        }
        
        List<Account> accountList1 = new List <Account>();
        accountList1 =[select id,name,Status__c from account where id IN :conId];
        
        for(Account a:accountList1){
            for(Contact cc:contactList1){
                if(a.id==cc.AccountId){
                    if(a.Status__c==null){
                         a.Status__c=cc.Status__c;   
                    }  
                    else if(cc.Status__c<a.Status__c)
                        a.Status__c=cc.Status__c;
 
                }
               
            }
        }
        if(accountList1.size()>0){
            update accountList1;
            system.debug('accountList1---->>>'+accountList1);
        }
     
    }


I hope it will help you.Please mark best answer if it will help you.

Thanlks

Shivom Verma 34Shivom Verma 34
Hii Malika thank you for your response
but in my case, I took the case object and  its related cases

so when related cases status changed same status should be updated to parent case status