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
Ashmi PatelAshmi Patel 

Method does not exist or incorrect signature: op_trigger.op_check(List<Opportunity>) at line 2 column 1

when i save my trigger i m getting this error
ERROR ::: Method does not exist or incorrect signature: op_trigger.op_check(List<Opportunity>) at line 2 column 1

this my trigger code

trigger trigger_1 on Opportunity (before insert, before update) {
op_trigger.op_check(Trigger.New);
}



this is my class code

public class op_trigger
{
    public void op_check(List<Opportunity> ops)
        {
            Double Total_Amount = 0 ;
            for(Opportunity o1 : [select amount from Opportunity where CreatedDate = Today AND CreatedByID = :UserInfo.getUserID()])

                                    {
                                        Total_Amount = Total_Amount + o1.Amount;
                                    }
                                    
          for(Opportunity o2 : ops)
          {
              Total_Amount = Total_Amount + o2.Amount;
              
              if(Total_Amount > 1000000)
              o2.addError('out of Limit');
          }                          
        }

}
Best Answer chosen by Ashmi Patel
Apoorv Saxena 4Apoorv Saxena 4
Hi Ashmi,

 The reason it was not working(throwing error) is because 'op_check'  is not a static method and can not be called without first instantiating an instance of the class, therefore I instanitiated the class first and then used its reference to call the method.

Hope this helps!

If you feel that your question was answered then do flag the appropriate answer as the solution to your query.

Thanks,
Apoorv
 

All Answers

Apoorv Saxena 4Apoorv Saxena 4
HI Ashmi,

If you are calling a method through its class name, then that method needs to be 'static'.

Try changing your code to following:
 
public class op_trigger
{
    public static void op_check(List<Opportunity> ops)
        {
            Double Total_Amount = 0 ;
            for(Opportunity o1 : [select amount from Opportunity where CreatedDate = Today AND CreatedByID = :UserInfo.getUserID()])

                                    {
                                        Total_Amount = Total_Amount + o1.Amount;
                                    }
                                    
          for(Opportunity o2 : ops)
          {
              Total_Amount = Total_Amount + o2.Amount;
              
              if(Total_Amount > 1000000)
              o2.addError('out of Limit');
          }                          
        }

}

Hope this helps!

Please mark this question as Solved if it answers your question so that others can view it as a proper solution.

Thanks,
Apoorv

 
Ashmi PatelAshmi Patel
still getting error....

ERROR ::: unexpected token: 'static' at line 3 column 16
Apoorv Saxena 4Apoorv Saxena 4
Ok, 

Use the following code :

Trigger:
 
trigger trigger_1 on Opportunity (before insert, before update) {
    op_trigger ob = new op_trigger();
    ob.op_check(Trigger.New);
}

Apex class:
 
public class op_trigger
{
    public void op_check(List<Opportunity> ops)
        {
            Double Total_Amount = 0 ;
            for(Opportunity o1 : [select amount from Opportunity where CreatedDate = Today AND CreatedByID = :UserInfo.getUserID()])

                                    {
                                        Total_Amount = Total_Amount + o1.Amount;
                                    }
                                    
          for(Opportunity o2 : ops)
          {
              Total_Amount = Total_Amount + o2.Amount;
              
              if(Total_Amount > 1000000)
              o2.addError('out of Limit');
          }                          
        }

}

Hope this helps!

 
Ashmi PatelAshmi Patel
thnxxx...solved.....
bt how can u solve this error???
what was the mistake??
Apoorv Saxena 4Apoorv Saxena 4
Hi Ashmi,

 The reason it was not working(throwing error) is because 'op_check'  is not a static method and can not be called without first instantiating an instance of the class, therefore I instanitiated the class first and then used its reference to call the method.

Hope this helps!

If you feel that your question was answered then do flag the appropriate answer as the solution to your query.

Thanks,
Apoorv
 
This was selected as the best answer
Ashmi PatelAshmi Patel
thnkuuuuu so much.
Apoorv Saxena 4Apoorv Saxena 4
Hi Ashmi,

Glad to be of help.
Could be please mark this is as Solved, so as other community members could also be benefitted from it if they face a similar issue.

Thanks,
Apoorv