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
Krishna Sahu 1Krishna Sahu 1 

I want to update parent account object picklist field when child education field is update as completed

 public static void updateJourneyStatus(Map<Id,Education_Request__c> newMap, Map<Id,Education_Request__c> oldMap){
        Map <  Id,  Education_Request__c > mapAccount = new Map < Id, Education_Request__c >();
        List < Account > listAccount = new List< Account >();
        
        for ( Education_Request__c acct : newMap.values() ) {
            
            if (acct.education_status__c != oldMap.get( acct.Id ).education_status__c && acct.education_status__c=='Completed'){
                mapAccount.put( acct.Id, acct );
            }
            if ( !mapAccount.isEmpty() ) {
                for  ( Education_Request__c edRequest : mapAccount.values() )  {
                    if(edRequest.education_status__c=='Completed'){
                        Account acc=new Account();
                        acc.Name=edRequest.Id;
                        acc.journey_stage__c='Psych Evaluation';
                        listAccount.add(acc);
                    }
                }
                update listAccount;
            }
        }
    }
Best Answer chosen by Krishna Sahu 1
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Krishna,

You can use the below Class for the same. I hope you are using after Update context for the trigger
public static void updateJourneyStatus(Map<Id,Education_Request__c> newMap, Map<Id,Education_Request__c> oldMap){
        List < Account > listAccount = new List< Account >();
		Set<id> Accountids= new Set<Id>();
    
        for ( Education_Request__c acct : newMap.values() ) {
            
            if (acct.education_status__c != oldMap.get( acct.Id ).Education_Status__c  && acct.Education_Status__c =='Completed'){
                Accountids.add(acct.Account__c );
            }
        }
           List<Account> acclist= [select id,journey_stage__c  from Account where id in :Accountids];
            
            For(Account acc:acclist){
                acc.journey_stage__c='Psych Evaluation';
                listAccount.add(acc);
            }
    if(listAccount.size()>0)
        update listAccount;
            
        
    }

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Krishna,

Can you confirm if Account is the Parent object to the Education Request object. Can you confirm the Name of the Account field on the Education Request object so I can try the logic for the same.

Thanks,
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Krishna,

You can use the below Class for the same. I hope you are using after Update context for the trigger
public static void updateJourneyStatus(Map<Id,Education_Request__c> newMap, Map<Id,Education_Request__c> oldMap){
        List < Account > listAccount = new List< Account >();
		Set<id> Accountids= new Set<Id>();
    
        for ( Education_Request__c acct : newMap.values() ) {
            
            if (acct.education_status__c != oldMap.get( acct.Id ).Education_Status__c  && acct.Education_Status__c =='Completed'){
                Accountids.add(acct.Account__c );
            }
        }
           List<Account> acclist= [select id,journey_stage__c  from Account where id in :Accountids];
            
            For(Account acc:acclist){
                acc.journey_stage__c='Psych Evaluation';
                listAccount.add(acc);
            }
    if(listAccount.size()>0)
        update listAccount;
            
        
    }

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Krishna Sahu 1Krishna Sahu 1
Hi sai praveen
yes account is parent object and education is child object.
On account object journey stage is field which i want to update when child object education status field updated as completed.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Krishna,

Can you try the above code which I have shared. Replace Account__c with the API name of Account field on the Education_Request__c object.

Thanks,
 
Krishna Sahu 1Krishna Sahu 1
Hi Sai Praveen,

Thank you for the code it is working.
Thank you
Berta RogersBerta Rogers
Hi. We also recently had to recover our daughter's account because she blocked all her devices after an incident at school. She still cannot understand that ideal people do not exist and the standards imposed on social networks are nothing more than bullying. Now she is passionate about writing, and the argumentative essays at https://sunnypapers.com/paper-samples/body-image/ helped her with her homework and changed her mind on many things. Every parent wants their child to be happy, so we must not only monitor academic performance and help the child learn to love his body and himself.