0

I have written a very simple trigger, but when I am trying to call the class I get 2 errors:

BenchmarkProgressTriggerHandler Line 11 Expecting '}' but was: 'for'; BenchmarkProgressTriger Line 3 Constructor not defined: [BenchmarkProgressTriggerHandler].(List)

Trigger:

trigger BenchmarkProgressTriger on FGM_Base__Benchmark_Update__c (after insert, after update) {

     BenchmarkProgressTriggerHandler handler = new BenchmarkProgressTriggerHandler(trigger.new);
}

Class:

public class BenchmarkProgressTriggerHandler {

    List<FGM_Base__Benchmark_Update__c> triggerbenchmark = new List<FGM_Base__Benchmark_Update__c>();
    Set<id> benchmarksIdsSet = new Set <id>();

    public BenchmarkProgressTriggerHandler(List<FGM_Base__Benchmark_Update__c> fbbu){
        triggerbenchmark = fbbu;
    }

    //if (Trigger.isInsert || Trigger.isUpdate){     
        for (FGM_Base__Benchmark_Update__c bp : triggerbenchmark){
            benchmarksIdsSet.add(bp.FGM_Base__Benchmark__c);

        }
        System.debug('benchmarkIdsSet :' +benchmarksIdsSet);
    //}

    list<FGM_Base__Benchmark__c> benchmarkList = new List<FGM_Base__Benchmark__c>();

    for(FGM_Base__Benchmark__c bm:[select id, Number_Completed__c,(select id,FGM_Base__Number_Update__c from FGM_Base__Benchmark_Updates__r) 
                                  from FGM_Base__Benchmark__c where id IN:benchmarksIdsSet]){

    FGM_Base__Benchmark__c obj=new FGM_Base__Benchmark__c();
    obj.id = bm.id;
             for(FGM_Base__Benchmark_Update__c bbu:bm.FGM_Base__Benchmark_Updates__r){
                 if(obj.Number_Completed__c==null){
                     obj.Number_Completed__c=0;
                 }
                 obj.Number_Completed__c+=bbu.FGM_Base__Number_Update__c;
             }
             benchmarkList.add(obj);

    System.debug('bm :' + bm);
    System.debug('benchmarkList :' +benchmarkList);
    }

    if(benchmarkList.size()>0){
        try{
            update benchmarkList;
        } 
        catch(DMLException e){
            system.debug('Problem has occured!' +e.getMessage());
        }
        System.debug('updatedbenchmarkList :' +benchmarkList);
    }    
}

1 Answer 1

2

The } at line 8 closes the constructor, so the code after that is not inside it. Change your code to:

public class BenchmarkProgressTriggerHandler {

    List<FGM_Base__Benchmark_Update__c> triggerbenchmark = new List<FGM_Base__Benchmark_Update__c>();
    Set<id> benchmarksIdsSet = new Set <id>();

    public BenchmarkProgressTriggerHandler(List<FGM_Base__Benchmark_Update__c> fbbu){
        triggerbenchmark = fbbu;

        //if (Trigger.isInsert || Trigger.isUpdate){     
            for (FGM_Base__Benchmark_Update__c bp : triggerbenchmark){
                benchmarksIdsSet.add(bp.FGM_Base__Benchmark__c);

            }
            System.debug('benchmarkIdsSet :' +benchmarksIdsSet);
        //}

        list<FGM_Base__Benchmark__c> benchmarkList = new List<FGM_Base__Benchmark__c>();

        for(FGM_Base__Benchmark__c bm:[select id, Number_Completed__c,(select id,FGM_Base__Number_Update__c from FGM_Base__Benchmark_Updates__r) 
                                      from FGM_Base__Benchmark__c where id IN:benchmarksIdsSet]){

        FGM_Base__Benchmark__c obj=new FGM_Base__Benchmark__c();
        obj.id = bm.id;
                 for(FGM_Base__Benchmark_Update__c bbu:bm.FGM_Base__Benchmark_Updates__r){
                     if(obj.Number_Completed__c==null){
                         obj.Number_Completed__c=0;
                     }
                     obj.Number_Completed__c+=bbu.FGM_Base__Number_Update__c;
                 }
                 benchmarkList.add(obj);

        System.debug('bm :' + bm);
        System.debug('benchmarkList :' +benchmarkList);
        }

        if(benchmarkList.size()>0){
            try{
                update benchmarkList;
            } 
            catch(DMLException e){
                system.debug('Problem has occured!' +e.getMessage());
            }
            System.debug('updatedbenchmarkList :' +benchmarkList);
        }
    }
}
1
  • Darn it. I can not believe I missed that. Thanks.
    – Ivo Dimov
    Apr 8, 2019 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .