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
Gerald HarmensGerald Harmens 

How To Make an Apex Trigger from a Custom Field Formula?

Hello, I have a custom date field formula that will calculate when the sales commission should be paid next month.

If the customer pays between the 1st and the 15th of this month, the Sales Rep will receive their commission on the 1st of next month.
If the customer pays between the 16th and the 31st of this month, the Sales Rep will receive their commission on the 15th of next month.

The problem is that I need this field for each product which means that I have to create the field mutiple times. I gather this field and other fields for a Page View Report. Salesforce gives me this error when I create more than 5 of these formula fields:

Query is either selecting too many fields or the filter conditions are too complicated. 
An unexpected error has occurred. Your solution provider has been notified. (i360)


I was wondering if I can create an Apex Trigger for these formulas? The one below is for the product blinds.

PAGE VIEW REPORT FIELD:
IF(NOT(CE4B__c = 0.0) && (B1C__c = TRUE), 
"Amount: " & "$" & Text (CE4B__c) & BR() & 
"Owed On: " & Text (Blinds_Commissions_Owed_On__c) , "")

Object Name: i360__Sale__c
Field Name: Blinds 1st Check
API Name: B1C__c
Formula: IF(DAY(Costco_Paid_On_Blinds__c) <= 15,TRUE,FALSE)

Object Name: i360__Sale__c
Field Name: Blinds Commissions Owed On
API Name: Blinds_Commissions_Owed_On__c
Formula: IF (DAY ( Costco_Paid_On_Blinds__c) <= 15, BCOO1__c,BCOO15__c)

Object Name: i360__Sale__c
Field Name: Blinds Commissions Owed on the 1st
API Name: BCOO1__c
Formula: IF(DAY(Costco_Paid_On_Blinds__c) <= 15, 
DATE(YEAR(Costco_Paid_On_Blinds__c), MONTH(Costco_Paid_On_Blinds__c) + 1,01), 
DATE(YEAR(Costco_Paid_On_Blinds__c) + 1,MONTH(Costco_Paid_On_Blinds__c) - 10,01))

Object Name: i360__Sale__c
Field Name: Blinds Commissions Owed on the 15th
API Name: BCOO15__c
Formula: IF(DAY(Costco_Paid_On_Blinds__c) >= 16, 
DATE(YEAR(Costco_Paid_On_Blinds__c),MONTH(Costco_Paid_On_Blinds__c) + 1,15), 
DATE(YEAR(Costco_Paid_On_Blinds__c) + 1,MONTH(Costco_Paid_On_Blinds__c) - 10,01))