• Mike MacLeod
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 12
    Replies

I have this trigger written, which passed validation no problem. THe trigger works in Sandbox but will not deploy in production;

 

Below are the warnings:

 

 

Commission_Calculation__c.Practitioner_Account__cCustom Field Definition7313cannot create two master detail fields with the same domain on one objectGenerateCommissionApex Trigger139Didn't understand relationship

 

 

'Commission_Calculations__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

 

Here is the trigger:

 

trigger GenerateCommission on Revenue_Event__c ( after insert )
{
    //  build a set of Accounts (doctors) related to each Revenue Event in this trigger
    Set<Id> set_AccountIDs = new Set<Id>();

    for ( Revenue_Event__c event : Trigger.new )
    {
        set_AccountIDs.add( event.Account__c );
    }

    //  query the Account records (doctors) related to the Revenue Events in this trigger
    Map<Id,Account> map_Doctors = new Map<Id,Account>
    (   [   SELECT  Id, (SELECT Id, Practitioner_Account__c, Sales_Agent__c FROM Commission_Calculations__r WHERE Active__c = true)
            FROM    Account
            WHERE   Id IN :set_AccountIDs
        ]
    );
    if ( map_Doctors.isEmpty() ) return;

    List<Commission__c> list_Commissions = new List<Commission__c>();

    //  for each Revenue Event,
    for ( Revenue_Event__c event : Trigger.new )
    {
        //  look up the associated Account (doctor)
        Account doctor = map_Doctors.get( event.Account__c );

        //  for each Commission Calculation related to the Account (doctor),
        for ( Commission_Calculation__c calculation : doctor.Commission_Calculations__r )
        {
            //  create a new Commission record
            list_Commissions.add
            (   new Commission__c
                (   Revenue_Event__c            = event.Id,
                    Sales_Agent__c              = calculation.Sales_Agent__c,
                    Commission_Percentage__c    = calculation.Id
                )
            );
        }
    }
    //  insert the new Commission records into the database
    insert list_Commissions;
}

 

 

If anyone has thougths, I would appreciate them!

I'm so close to being done with this trigger, I can smell it. THe trigger works, but when it updates, it creates the correct number of Commission objects. Hoever, it just creates the correct number with itdentical  entriies. 

 

I know this is because somehow I'm not iterating correctly, but I can not figure out the error. HELP!

 

Here's the code: 

 

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)
FROM Account WHERE id in: DoctorID ]);

if (CommissionList.size()>0){
List<commission__c> FinalCommissions = new list<Commission__c>();

For (Revenue_Event__c NewRevenueEvent : Trigger.new){
for(Account j: CommissionList){

for(Commission_Calculation__c cc : j.Commission_Calculations__r){              
Integer i=0;
              Commission__c NewCommission = new Commission__c();
              NewCommission.Revenue_Event__c = NewRevenueEvent.id;                      
              NewCommission.Sales_Agent__c = CommissionList[i].Commission_Calculations__r.get(i).Sales_Agent__c;
              NewCommission.Commission_Percentage__c = CommissionList[i].Commission_Calculations__r.get(i).id;
              FinalCommissions.add(NewCommission);    
  i++;                 


            }    

 
       }

Insert  FinalCommissions;
}
}
}

 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!

Hi Everyone!

 

I am writing an apex trigger. The trigger is designed to fire when a revenue event is created. The trigger is suposed to perform a query on Accounts to find an item called Commission Calculation. If the Commission Calculation is active, the trigger gets the Sales Agent's ID and the Commission Calculation ID, which it uses to populate fields in the Commission record. 

 

My problem is I can't see to find a way to get the For loop to operate correctly. Below is the trigger in all its glory. If anyone can help it would be deeply appreciated!

 

trigger GenerateCommission on Revenue_Event__c (after insert) {

For (Revenue_Event__c NewRevenueEvent : Trigger.new){

If (NewRevenueEvent != null)
{
list <Account> CommissionList = [SELECT Id,
(SELECT id, Sales_Agent__C FROM Commission_Calculations__r WHERE Active__c = TRUE)
FROM Account];

Integer i = CommissionList.size();

list <Commission__c> NewCommission = new list <Commission__c>();

for (Account j : NewCommissionList) {
NewCommission[0].Revenue_Event__c = NewRevenueEvent.id;
NewCommission[0].Sales_Agent__c = CommissionList[0].Commission_Calculations__r.get(0).Sales_Agent__c;
NewCommission[0].Commission_Percentage__c = CommissionList[0].Commission_Calculations__r.get(0).id;
}
// Insert NewCommission[0];
}

}
}

I have this trigger written, which passed validation no problem. THe trigger works in Sandbox but will not deploy in production;

 

Below are the warnings:

 

 

Commission_Calculation__c.Practitioner_Account__cCustom Field Definition7313cannot create two master detail fields with the same domain on one objectGenerateCommissionApex Trigger139Didn't understand relationship

 

 

'Commission_Calculations__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

 

Here is the trigger:

 

trigger GenerateCommission on Revenue_Event__c ( after insert )
{
    //  build a set of Accounts (doctors) related to each Revenue Event in this trigger
    Set<Id> set_AccountIDs = new Set<Id>();

    for ( Revenue_Event__c event : Trigger.new )
    {
        set_AccountIDs.add( event.Account__c );
    }

    //  query the Account records (doctors) related to the Revenue Events in this trigger
    Map<Id,Account> map_Doctors = new Map<Id,Account>
    (   [   SELECT  Id, (SELECT Id, Practitioner_Account__c, Sales_Agent__c FROM Commission_Calculations__r WHERE Active__c = true)
            FROM    Account
            WHERE   Id IN :set_AccountIDs
        ]
    );
    if ( map_Doctors.isEmpty() ) return;

    List<Commission__c> list_Commissions = new List<Commission__c>();

    //  for each Revenue Event,
    for ( Revenue_Event__c event : Trigger.new )
    {
        //  look up the associated Account (doctor)
        Account doctor = map_Doctors.get( event.Account__c );

        //  for each Commission Calculation related to the Account (doctor),
        for ( Commission_Calculation__c calculation : doctor.Commission_Calculations__r )
        {
            //  create a new Commission record
            list_Commissions.add
            (   new Commission__c
                (   Revenue_Event__c            = event.Id,
                    Sales_Agent__c              = calculation.Sales_Agent__c,
                    Commission_Percentage__c    = calculation.Id
                )
            );
        }
    }
    //  insert the new Commission records into the database
    insert list_Commissions;
}

 

 

If anyone has thougths, I would appreciate them!

I'm so close to being done with this trigger, I can smell it. THe trigger works, but when it updates, it creates the correct number of Commission objects. Hoever, it just creates the correct number with itdentical  entriies. 

 

I know this is because somehow I'm not iterating correctly, but I can not figure out the error. HELP!

 

Here's the code: 

 

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)
FROM Account WHERE id in: DoctorID ]);

if (CommissionList.size()>0){
List<commission__c> FinalCommissions = new list<Commission__c>();

For (Revenue_Event__c NewRevenueEvent : Trigger.new){
for(Account j: CommissionList){

for(Commission_Calculation__c cc : j.Commission_Calculations__r){              
Integer i=0;
              Commission__c NewCommission = new Commission__c();
              NewCommission.Revenue_Event__c = NewRevenueEvent.id;                      
              NewCommission.Sales_Agent__c = CommissionList[i].Commission_Calculations__r.get(i).Sales_Agent__c;
              NewCommission.Commission_Percentage__c = CommissionList[i].Commission_Calculations__r.get(i).id;
              FinalCommissions.add(NewCommission);    
  i++;                 


            }    

 
       }

Insert  FinalCommissions;
}
}
}

 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!

Hi Everyone!

 

I am writing an apex trigger. The trigger is designed to fire when a revenue event is created. The trigger is suposed to perform a query on Accounts to find an item called Commission Calculation. If the Commission Calculation is active, the trigger gets the Sales Agent's ID and the Commission Calculation ID, which it uses to populate fields in the Commission record. 

 

My problem is I can't see to find a way to get the For loop to operate correctly. Below is the trigger in all its glory. If anyone can help it would be deeply appreciated!

 

trigger GenerateCommission on Revenue_Event__c (after insert) {

For (Revenue_Event__c NewRevenueEvent : Trigger.new){

If (NewRevenueEvent != null)
{
list <Account> CommissionList = [SELECT Id,
(SELECT id, Sales_Agent__C FROM Commission_Calculations__r WHERE Active__c = TRUE)
FROM Account];

Integer i = CommissionList.size();

list <Commission__c> NewCommission = new list <Commission__c>();

for (Account j : NewCommissionList) {
NewCommission[0].Revenue_Event__c = NewRevenueEvent.id;
NewCommission[0].Sales_Agent__c = CommissionList[0].Commission_Calculations__r.get(0).Sales_Agent__c;
NewCommission[0].Commission_Percentage__c = CommissionList[0].Commission_Calculations__r.get(0).id;
}
// Insert NewCommission[0];
}

}
}