You need to sign in to do that
Don't have an account?

How to terminate a running trigger based on a condition.
Hi, I've a trigger and a service class.
I need to check for a condition in service class and if that matches i need to terminate that event(terminate), not that just function but whole process
How can i do that?
Trigger--> Service Class Function
Thanks
I need to check for a condition in service class and if that matches i need to terminate that event(terminate), not that just function but whole process
How can i do that?
Trigger--> Service Class Function
Thanks
for eg.
public string myName(list<custom__c> myrec) // suppose you are calling this method from trigger(using class)
{
myrec[0].adderrr('your error message') // will work
}
Please acced this link (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_exceptions.htm) for more information
You can use return for this. In your service class function, you can set some static varaible as true and check it in trigger in the next line where you are calling the service class method.
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks for your reply. However what i need is not to give an error message, but to terminate whole trigger, without giving any output.
In C we have system.exit(0). Dont we have something like that in APEX?
Thank you
It would be good if you share your code also. This will help to better understand the issue.
myTrigger{
myServiceClass.method(with map and list)
myServiceClass.method2();//=====> if i use return this will be called, i need to terminate from whole process
}
myServiceClass{
public static method(parameters) {
if(someCondition == true){
return;// ===> After i terminate method2 also should not be called
}
}
}
Thankssssssss
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.