0

I am trying to execute anonymous apex block. The method which is used here is also used in a trigger. Trigger is working fine. I am writing this apex code to update a new field based on the values of these fields REAC_TAC_BUSINESS_AREA__c,Tier__c,REAC_TAC_CATEGORY__c,queue1__c.This logic is inside the method.

Getting following error

Line: 11, Column: 33 Method does not exist or incorrect signature: void handlerbeforeupdate(Case) from the type REAC_TAC_CaseTriggerHandler

Here is the Apex code

Date myDate = date.newinstance(2017,12,4);
integer cnum  = 0;

For (case c: [select 
id,REAC_TAC_BUSINESS_AREA__c,Tier__c,REAC_TAC_CATEGORY__c,queue1__c from 
case where createddate > :myDate])
{
 system.debug('c.id'+c.id);
 system.debug('c.id'+c.REAC_TAC_BUSINESS_AREA__c);
 system.debug('c.id'+c.Tier__c);
 system.debug('c.id'+c.REAC_TAC_CATEGORY__c);
 cnum = cnum +1;    
 REAC_TAC_CaseTriggerHandler.handlerbeforeupdate(c);

}
update c;
system.debug('total cases:' + cnum); 

Here is the class & method:

public class REAC_TAC_CaseTriggerHandler {
 -------
public static void handlerbeforeupdate(List<Case> cases) {
for (case c1 :cases){
  • You call it with single parameter, but method is defined with list of parameters – kurunve Dec 5 '17 at 12:14
1

Your trigger helper is expecting a list of Cases, but you try to call it with one case. Try this instead:

REAC_TAC_CaseTriggerHandler.handlerbeforeupdate(new List<Case>{c});

But be aware that it is not bulkified anymore, so you might consider passing the list you queried and not do it in the for loop.

Calling the trigger manually should actually not be necessary, since it should be called automatically when you do your dml update cases;

List<Case> cases = [select 
id,REAC_TAC_BUSINESS_AREA__c,Tier__c,REAC_TAC_CATEGORY__c,queue1__c from 
case where createddate > :myDate];

For (case c: cases)
{
 system.debug('c.id'+c.id);
 system.debug('c.id'+c.REAC_TAC_BUSINESS_AREA__c);
 system.debug('c.id'+c.Tier__c);
 system.debug('c.id'+c.REAC_TAC_CATEGORY__c);
 cnum = cnum +1;
}

//REAC_TAC_CaseTriggerHandler.handlerbeforeupdate(cases);

update cases;
  • I updated my post. I modified as you mentioned. But i got error. – Uma N Dec 5 '17 at 12:51
  • @UmaN you need to write update cases; instead of update c; fixed it in my answer. And please try to not post different question in one question, it will confuse people reading it afterwards. – Basti Dec 5 '17 at 12:58

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.