0

This should update the account once a case with the Customer Save record type is saved. The trigger does not work, but there is no error.

    Trigger UpdateLEStatus on Case (after insert) { 
    Set UpdatedAccountIds = new Set();
    Id recordTypeId = Schema.SObjectType.Case.RecordTypeInfosByName.get('Customer Save').RecordTypeId;

    for (Case c: Trigger.new) {
        if (c.RecordTypeId == recordTypeId) {
            UpdatedAccountIds.add(c.accountid);
        }    
    }
    List<Account> AccountForUpdating = [SELECT LE_Status__c
                                                       FROM Account
                                                       WHERE Account.Id IN: UpdatedAccountIds];
    for (Account item: AccountForUpdating) {
        item.LE_Status__c = 'Red';
    }
    update AccountForUpdating;
    }
  • can you find trigger execution in debug logs? Please update your set declaration: Set<id> UpdatedAccountIds = new Set<id>(); – Vignex Feb 3 '15 at 17:26
  • @Vignex I will see if I can find it in the logs and change the declaration. How does the trigger know that I need account ids from that declaration? Do I need something else in there? – Blair Kristin Feb 3 '15 at 17:30
  • 1
    Set is just a collection. In your logic, you're collecting account Ids and then querying it in second half section of the code. and Please update your SOQL Query to : List<Account> AccountForUpdating = [SELECT LE_Status__c FROM Account WHERE Id IN: UpdatedAccountIds]; – Vignex Feb 3 '15 at 17:32
  • @Vignex That worked! – Blair Kristin Feb 3 '15 at 17:45
1

@Vignex provided this answer

Trigger UpdateLEStatus on Case (after insert) { Set<id> UpdatedAccountIds =    new Set<id>();

    Id recordTypeId =Schema.SObjectType.Case.RecordTypeInfosByName.get('Customer Save').RecordTypeId;

for (Case c: Trigger.new) {
    if (c.RecordTypeId == recordTypeId) {
        UpdatedAccountIds.add(c.accountid);
    }    
}
List<Account> AccountForUpdating = [SELECT LE_Status__c FROM Account WHERE Id IN: UpdatedAccountIds];
for (Account item: AccountForUpdating) {
    item.LE_Status__c = 'Red';
    item.LE_Status_Notes__c = 'Customer Save Case';
}
update AccountForUpdating;
}
  • Please keep the formatting right Blair.. I do love the points though – EricSSH Mar 6 '15 at 21:34
  • @EricSSH whenever I paste code in, it is in the right formation but the output at the bottom always looks different. How can I make sure my formatting is in the output on this site? – Blair Kristin Mar 9 '15 at 13:42

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.