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;
    }
4
  • can you find trigger execution in debug logs? Please update your set declaration: Set<id> UpdatedAccountIds = new Set<id>();
    – Vignex
    Commented Feb 3, 2015 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? Commented Feb 3, 2015 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
    Commented Feb 3, 2015 at 17:32
  • @Vignex That worked! Commented Feb 3, 2015 at 17:45

1 Answer 1

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;
}
2
  • Please keep the formatting right Blair.. I do love the points though
    – EricSSH
    Commented Mar 6, 2015 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? Commented Mar 9, 2015 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .