You need to sign in to do that
Don't have an account?
Help with Apex code in trigger
Hey guys some background into my prob. I need a lookup field, Account__c, to auto-populate with an account name on update of an event payment object.
The relavent schema looks like this:
Account
Id
Opportunity
AccountId
opportunity child Event Payment
Account__c
So heres what I got so far:
trigger accountRename on Event_Payment__c (after update) {
Set<Id> accIDs = new Set<Id>();
for(Event_Payment__c a: Trigger.new){ accIDs.add(a.Id); }
List<Account> accountList = [SELECT Id FROM Account WHERE Id in :accIDs];
for(Event_Payment__c a : Trigger.new){
for(Account i : accountList){ a.Account__c = i.Id;
} update accountList; } }
Any ideas?
As others pointed out, there may be some inconsistencies in your trigger that do not allow it to work as you intend.
See if you can follow the logic here:
Hope that helps
All Answers
This line:
looks problematic to me - the id that you are adding to the accIds list is actually that of the Event_Payment__c object that you are processing.
What account id are you trying to copy to each Event_Payment__c object?
I am looking for the account with the same id as in the opportunity AccountId, if that makes sense. Thanks for the help !
Your trigger doesn't mention opportunities - should it?
yeah I am working on this now as a solution: for (Event_Payment__c a : Trigger.new) { a.Account__c = a.Special_Event__r.Account.Id;}
the a.Special_Event__r. gets me to opportunities but the " a.Special_Event__r.Account.Id " code isnt working. Like if I hard code the id it works but not as the current code and I see no reason why it wouldnt... is there a parse issue or something that changes the id to another format maybe
As others pointed out, there may be some inconsistencies in your trigger that do not allow it to work as you intend.
See if you can follow the logic here:
Hope that helps
wow! I had to change opportunity to 'Special_Event', and then it worked! I can't believe the amount of code necessary just to update that one field.... LoL
thanks so much