+ Start a Discussion
MC34MC34 

Need a trigger where when account gets inactivated then all contacts get inactivated too.

Hi, I have custom Status__c picklist field on Account. I have a need when account gets inactivated with value pick "Inactive" then all contacts related to the account should also get inactive (contact also have  picklist custom field Contact_Status__c with one of the value as "Active". Apparently, combination of PB and Flow is not working. I would like to tackle this with trigger.

*Also can this be reversble also if account her reactivated again then contacts gets active? 
Best Answer chosen by MC34
Christan G 4Christan G 4
Hi Natto, if the flow was created just for this purpose, than I suggest removing it as it is not needed. If it is used for something else, keep it and just add another action under "Immediate Actions". I have provided screenshots below of my PB configuration. 

PB - Active Account - Set Account status criteria to Active
PB - Active Accounts #1

PB - Active Account - Update related Contact status to Active
PB - Active Accounts #2

PB - Inactive Account - Set Account status criteria to Inactive
PB - Inactive Accounts #3

PB - Inactive Account - Update related Contact status to Inactive
PB - Inactive Accounts #4

If you have any questions, please feel free to reach out to me.

All Answers

Christan G 4Christan G 4
Good Evening Natto, I hope you are well. I don't think you will need both a PB and a Flow to automate this change. I think you would only need a PB to resolve this. It just depends on how you would configure it. If you prefer using code, I have written it below:

Apex Class:
public class AccTriggerHelper {

    public static void updateAssociateContact (Map <ID, Account> accNewMap)  {   
        
     List <Account> accListwCon = [SELECT ID, Name, Status__c, (SELECT ID, Name, Contact_Status__c FROM Contacts) FROM Account WHERE ID IN:accNewMap.keyset()];    
     
     List <Contact> conUpdate = new List <Contact>();   
        
        for (Account oneAcc : accListwCon) {
            
            if (oneAcc.Status__c == 'Inactive') {
                
                for (Contact oneCon : oneAcc.Contacts) {
                    
                    oneCon.Contact_Status__c = 'Inactive';
                    conUpdate.add(oneCon);
                }
            }
            
            else if (oneAcc.Status__c == 'Active') {
                
                for (Contact oneCon : oneAcc.Contacts) {
                    
                    oneCon.Contact_Status__c = 'Active';
                    conUpdate.add(oneCon);
                }
            }
        } 
        
        if (conUpdate.size() > 0) {
            
            update conUpdate;
        }
    }    
}

Apex Trigger:
trigger AccTrigger on Account (after update) {

    AccTriggerHelper.updateAssociateContact(Trigger.newMap);
    
}
Please test and inform me of your results. In the meantime, I am actually going to test to see if this can be done using a PB only.
Christan G 4Christan G 4
Hi Natto, I was able to fulfill your requirement by using one PB. This would be the preferred method compared to using code due to it being easier to manage. If you like, I can walk you through the process.
MC34MC34
Thanks Christian, I came on board to the new instance where this was already set up with combo of PB and Flw. Don't have any insight why they did that but certainly its not working. Not sure if somebody made the big data load and things went haywire. One thing to note is that we have Oracle EBS that where all accounts are housed if values changed there for accounts (active or inactive) it should flow in SFDC and in SFDC then contacts should act accordingly.  mm..not sure of PB alone can drive this. I will surely test this tommorow in snbx and let you know. :) 
nitin sharma 397nitin sharma 397
You can have another criteria node to reverse logic and this can easily be tackled with the Process builder and flow without any trouble....Try to use worbench tool to see if somebody made modifications to the fow etc...You  will see some info there about the process and changes.
MC34MC34
Hi Christan, is this can be done just via PB or Flw is needed too? 
Christan G 4Christan G 4
This can be done with just one PB.
MC34MC34
@Christan & Nitin, so current PB + Flow is set like this: Please see the screenshot - this is definately not working. 

User-added image

Flow: 

User-added image

Let me know if you need anything. Thank you. 
Christan G 4Christan G 4
Hi Natto, if the flow was created just for this purpose, than I suggest removing it as it is not needed. If it is used for something else, keep it and just add another action under "Immediate Actions". I have provided screenshots below of my PB configuration. 

PB - Active Account - Set Account status criteria to Active
PB - Active Accounts #1

PB - Active Account - Update related Contact status to Active
PB - Active Accounts #2

PB - Inactive Account - Set Account status criteria to Inactive
PB - Inactive Accounts #3

PB - Inactive Account - Update related Contact status to Inactive
PB - Inactive Accounts #4

If you have any questions, please feel free to reach out to me.
This was selected as the best answer
MC34MC34
Thanks Christian, this is working now also in reversal. :) 
Christan G 4Christan G 4
Hi Natto, I am glad that I was able to help in resolving your issue! When you get a chance, please mark my answer as the best solution so this issue can be deemed as solved. Thanks again!