You need to sign in to do that
Don't have an account?
Ashmi 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');
}
}
}
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');
}
}
}
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
If you are calling a method through its class name, then that method needs to be 'static'.
Try changing your code to following:
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
ERROR ::: unexpected token: 'static' at line 3 column 16
Use the following code :
Trigger:
Apex class:
Hope this helps!
bt how can u solve this error???
what was the mistake??
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
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