1

Trigger should look at the Case record to determine if the "xyz__c" checkbox is true/false

-If True, go to #2

-If False, Trigger does nothing

Trigger should evaluate the Case record's associated Account record to determine if the "xyz__c" checkbox is true/false

-If True, Trigger does nothing

-If False, Trigger updates the field to True

BOTH OBJECT ACCOUNT AND CASE HAVE SAME FIELD XYZ__c

I have implemented this trigger but i am not sure this will work or not.

Map<Boolean, Boolean> MapCaseToGetNextRecordList = new Map<Boolean, Boolean>();

for(Case c : trigger.New){
    if(MapCaseToGetNextRecordList.containsKey(c.xyz__c) != true){
        break;
    }
}

for(Account acc : [select Id, xyz__c from Account]){
    if(acc.xyz__c != True){
        acc.xyz__c = true;
    }
}
0

You can query the accounts you need to update with a simple query, then update the field and commit the changes back to the database.

Account[] accounts = [select id from account where id in (select accountid from case where xyz__c = true and id in :trigger.new) and xyz__c = false];
for(account record: accounts) {
    record.xyz__c = true;
}
update accounts;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.