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
LloydSilverLloydSilver 

How to do complex calculation automatically

I have a custom object called Insurance Commissions with the following fields:

 

1. Agent

2. Commission Rate

3. Case (Master-Detail to the Case custom object which has a field called Premium)

 

In addition there are 2 record types: Base and Bonus.

 

Multiple Insurance Commissions records are added to each case. And for the record type Base, Commission Rates are what I'd call inclusive which is what makes it more complicated.

 

Here's an example:

 

Insurance Case 12345, premium of $1,000, with the following Insurance Commissions records associated with it:

 

1. Agent 1 - Base - 15%

2. Company 1 - Base - 20%

3. My Company - Base - 30%

4. Agent 1 - Bonus - 5%

 

To calculate the commissions we can start with the Base:

 

1. Agent 1 -- $1,000 * 15% = $150

2. Company 1 - $1,000 * (20% - 15% from Agent 1) = $50

3. My Company - $1,000 * (30% - 15% from Agent 1 - 5% from Company) = $100

4. Agent 1 - $1,000 * 5% = $50 which comes from My Company so My Company's net commission would be $50

 

If the Insurance Case changes (e.g. the premium changes), or if any of the Insurance Commissions records associated with a case change (or are added/removed), then the calculations need to be re-done.

 

It can get much more complicated with multiple agents and companies but this is a simplification. 

 

Is this an Apex thing?

 

Vinita_SFDCVinita_SFDC

Hello,

I would suggest you to create the field Agent1, company 1 and my company with the data type formula. In the formula first check the record type and if the insurance case is changed and accordingly assign the values, like:

IF(RecordType == 'Base' && Ischanged(Insurance_Case) == true,1,000 * 15
       IF(RecordType == 'Bonus' && Ischanged(Insurance_Case) == true, 1,000 * 5