You need to sign in to do that
Don't have an account?
subodh chaturvedi 17
How to change the value of child Record field (checkbox) Based on the parent Record Text Field
I have a field on parent (Card Program__c) object i.e card_processor_status__c & have a Child (Solution_participation__c) Object which has Active__c checkbox Field I want to Update the Checkbox Field Whenever the card_processor_status__c changes to either Active or Inactive .
I tried to update this with process builder But it is No Success .How we can Update this through Code?
I tried to update this with process builder But it is No Success .How we can Update this through Code?
Please check once below sample code ,In the place of ParentFieldApiName add parent record API name.:
Hope it helps you.
Thanks
Varaprasad
All Answers
Please check once below sample code ,In the place of ParentFieldApiName add parent record API name.:
Hope it helps you.
Thanks
Varaprasad
I tried Your Code But the Child Record field Active__c ( i.e Checkbox ) is not changed to uncheck when i changed my card_processor_status__c from Active to Inactive .
my requirement is when i changed my card_processor_status__c from Inactive to Active then all child records Active__C (Checkbox) field should get check automatically & if My card_processor_status__c changed from Active to Inactive then Active__c should get Uncheck.
there are already a records present in object which i need to change the Statuses & update the child record Accordingly.
Modified code
Public class CardProgramsolparticipationcheck{
Public Static Void CheckFieldstatus(List<Card_Program__c> card){
Map<id,Card_Program__c> programIds = new Map<id,Card_Program__c>();
for(Card_Program__c cp : card){
if(cp.card_processor_status__c != null){
programIds.put(cp.id,cp);
}
}
List<Solution_participation__c> updChildrecs = new List<Solution_participation__c>();
List<Solution_participation__c> childrecs = [select id,Active__c,Card_Program__c from Solution_participation__c where Card_Program__c IN : programIds.keyset()];
if(childrecs.size()>0){
for(Solution_participation__c sp : childrecs){
if(programIds.get(sp.Card_Program__c).card_processor_status__c == 'ACTIVE'){
sp.Active__c = TRUE;
}else {
sp.Active__c = FALSE;
}
updChildrecs.add(sp);
}
if(updChildrecs.size()>0){
update updChildrecs;
}
}
}
}
Trigger
trigger SolutionParticipationCheckboxUpdate on Card_Program__c (after Update) {
CardProgramsolparticipationcheck.CheckFieldstatus(trigger.new);
}
The Code is Working fine My bad I havn't Activate the trigger