function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kevin.chileskevin.chiles 

Commissions calculation across several objects

Hello!  I have a few things I am trying to do but I cannot seem get my head around this correctly.  Firstly, to explain my plight, I am trying to get data populated from a few different tables into one.  I am also trying to auto generate the record that would host all of this inforation.  Basically, I have an incentives object, and a commissions object.  The incentives object has several products in  a related list (incentive products) associated to it.  Incentives also has User associated to them (another related list)  I need to look at my payment objects and say. Ok, when payment comes in pull the related User(commissionable user) and auto calculate a commission based on what incentive prog.  he is assigned. to.  This sounds nuts so implementation  will be a snow storm im sure.  Thanks!

 

What I have so far, but is probably wrong

 

trigger IncentiveAssociation on Commission__c (after insert) {

for(Assigned_User__c AU: trigger.new){
[Select Id from Assigned_User__c ];

for (Incentive_Plan__c IP: trigger.new){
[Select Id from Incentive_Plan__c];

for (Commissionable_User__c CU : trigger.new) {
[Select Id From User Where CU.Commissionable_User__c = AU.User__c];

for (Incentive_Products__c ICP: trigger.new){
[Select Id from Incentive_Products__c.Product__c]


Id recId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('New InstallBase').getRecordTypeId();
for (Commission__c C : trigger.new){
if(trigger.isInsert){
C.RecordTypeId=recId;
C.Incentive_Plan__c=IncentivePlan;
C.Percentage__c=IP.of_Commissionable_Price__c;
C.Spiff__c=IP.Spiff__c;
C.Product=[Select Id from P.Product
}