So here is what we are trying to do;

We have a set up where the user enters five primary variables and from these variables we can generate another 30 variables.

Example, the user enters Qty.5 and selects the product. From this our apex code calculates the number of bolts and screws and what have you and displays them in the record.

From here we want the user to be able to edit the calculated field and the calculations use the newly entered variables. For this to work we need to be able to compare the value of the field prior to its update.

Current Trigger Setup:

trigger Basin_Calcs on Basins__c (before insert, before update) 
    List<Basins__c> calcs = Trigger.new;
    for (Basins__c p:calcs){
        Basins__c pOld = System.Trigger.oldMap.get(p.Id);

        if (p.Basin_Geometry__c == 'Channel'){

Current Class Setup:

public class BasinCalcClass{
    public static void recBasinCalc(List<Basins__c> calcs, Map<ID, Basins__c> pOld){

        for (Basins__c p:calcs){
           Basins__c beforeupdate = pOld.get(p.Id);

           double L = p.Rectangular_Length__c;

So I believe this is semi-correct so far. The first issue is calling the class in the trigger.


I have also tried to pass both calcs and pOld though and neither work? Maybe it has to do with it being map?

We want to pass the old variables through to the class so we can compare them to the new variables and make a decision on what code to run.

The second issue will be comparing the old to the new. I am guess I could do it this way;

if(p.Rectangular_Length__c == pOld.Rectangular_Length__c){blah}

Is this correct?

We have been using these for reference;

Apex - Checking Trigger.OLD versus Trigger.NEW


But I cant seem to figure out the passing of the variables through to the class.

  • Your static function is called recBasinCalc and expects two parameters but you're calling chaBasinCalc with just one. – FrankZ Nov 22 '13 at 21:34

Calling recBasinCalc

The first thing I notice is that recBasinCalc is defined with two parameters but your trigger is calling it with only one. You might be able to get away with just one parameter, depending on your full class definition.

On the value comparison:

Yes, that should work. Keep in mind that when using == on primitives Apex does a value comparison but for reference-types it checks the memory location instead (so if you implement a custom class you may want to provide your own equals() method.)

  • Mike, what would the trigger look like with the two variables? I think that is where I am getting lost. I should want to call both seeing as I am comparing them right? – Jordan Klepper Nov 22 '13 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.