+ Start a Discussion

Apex Trigger Help

HI Guy

I have a problem and i am hoping you will be able to advise me of the best solution
I have three fields “FDGL Lease Term, FDGL Monthly Terminal Payment, FDGL Equipment”. From these fields i am trying to populate a field called “FDGL Commission”
i have created a formula which “is below” Which works perfectly fine, however there are 300 different combinations of the formula, and i know that i have a maximum character length of 5000 per formula field, and the formula below is 170 characters long in length
How can i get all the different combinations into a formula field ? someone has suggested using APEX , but i never experimented with this before.
Has anyone got any ideas, or sample coding , which will can point me in the correct direction
VALUE(IF(AND(ISPICKVAL( FDGL_Lease_Term__c ,"24"),ISPICKVAL( FDGL_Monthly_Terminal_Payment__c , "21.95"), ISPICKVAL( FDGL_Equipment__c, "930BCC Contactless")),"300", ""))



If you are wanting to use formula field then apex cannot be of any help, you will have to write the formula like how you have done. But as you said you might exceed the limit of  characters


Other option  is


You can have this field as numeric field and use triggers/apex to update this field.


Hi prady-cm


Thank you for your swift response

Yes if i do it via formula then  i will exceed the limitation characters


I think the best solution is to go down the apex/trigger route


If i had to write apex code for the formula , how would i go around this ?

(ps-  i am new to this apex coding)


You can write before insert and before update trugger


trigger calculatevalue on Contact (before insert, before update) {

for (Contact c: Trigger.New)
              c.value = c.field2 + c.field3; // use your calculation
          else if (c.field1=='Something else'
              //do some other calculation

 Pls read the documentation to understand and learn apex