You need to sign in to do that
Don't have an account?

Trigger fires but does not create new record.
I was able to complete a trigger... athe only problem is, it doesn't actually show the commissions! I can tell the trigger is firing but nothing happens!
Here's the much cleaned up trigger:
trigger GenerateCommission on Revenue_Event__c (after insert) {
list <Account> CommissionList = new list<Account>([SELECT Id,
(SELECT id, Sales_Agent__C FROM Commission_Calculations__r WHERE Active__c = TRUE)
FROM Account where Id IN :Trigger.newMap.keySet() ]);
List<commission_Calculation__c> FinalCommissions = new list<Commission_Calculation__c>{};
For (Revenue_Event__c NewRevenueEvent : Trigger.new){
for(Account j: CommissionList){
for(Commission_Calculation__c cc : j.Commission_Calculations__r){
Commission__c NewCommission = new Commission__c();
NewCommission.Revenue_Event__c = NewRevenueEvent.id;
NewCommission.Sales_Agent__c = CommissionList[0].Commission_Calculations__r.get(0).Sales_Agent__c;
NewCommission.Commission_Percentage__c = CommissionList[0].Commission_Calculations__r.get(0).id;
FinalCommissions.add(cc);
}
}
}
Insert FinalCommissions;
}
I can't figure out why the trigger seems to fire, but doesn't update the commissions.
Please help, and thanks!
Your trigger is written on Revenue_Event__c object. But in query you are having where clause based on id...
ROM Account where Id IN :Trigger.newMap.keySet() ].. But this keyset will return Revenue event keyset not Account ids. So your query will not return anything.
You will have to put account ids from revenue event object into a set and then put that in where clause.
All Answers
Your trigger is written on Revenue_Event__c object. But in query you are having where clause based on id...
ROM Account where Id IN :Trigger.newMap.keySet() ].. But this keyset will return Revenue event keyset not Account ids. So your query will not return anything.
You will have to put account ids from revenue event object into a set and then put that in where clause.
Hi there, I've done as you suggested, Here's the relevant code:
set<Revenue_Event__c>DoctorID = new set<Revenue_Event__c>([Select r.Account__c From Revenue_Event__c r WHERE Revenue_Event__c.id IN: Trigger.new]);
if (DoctorID.size()>0){
list <Account> CommissionList = new list<Account>(
[SELECT Id,(Select Id, Practitioner_Account__c, Sales_Agent__c From Commission_Calculations__r WHERE Active__c = TRUE),
(Select Id, Name, Account__c From Revenue_Events__r)
FROM Account ]);
But I'm not sure how to pass the set into the WHERE clause. If you have thoughts I would be grateful!
Never mind, figured it out. :)
trigger GenerateCommission on Revenue_Event__c (after insert) {
set<account>DoctorID = new set<account>([Select ID from account where ID in (Select r.Account__c From Revenue_Event__c r WHERE Revenue_Event__c.id IN: Trigger.new)]);
if (DoctorID.size()>0){
list <Account> CommissionList = new list<Account>(
[SELECT Id,(Select Id, Practitioner_Account__c, Sales_Agent__c From Commission_Calculations__r WHERE Active__c = TRUE),
(Select Id, Name, Account__c From Revenue_Events__r)
FROM Account WHERE id in: DoctorID ]);