You need to sign in to do that
Don't have an account?
GoForceGo
Does a trigger know whether it is being called from a webservice call or through salesforce UI.
Is there anyway for a trigger to know if is being executed in the context of a user interface or a web service?
What i want to do is this:
I am extracting pdf data and putting it in salesforce objects through a client application using webservice. I don't want to give errors -
I want to just insert the data and send an e-mail to the user and letting them know if there are errors. When they go into salesforce, they will see the data.
When they edit the data, saving it would require fixing the errors - I would use .addError when used in the UI context.
What i want to do is this:
I am extracting pdf data and putting it in salesforce objects through a client application using webservice. I don't want to give errors -
I want to just insert the data and send an e-mail to the user and letting them know if there are errors. When they go into salesforce, they will see the data.
When they edit the data, saving it would require fixing the errors - I would use .addError when used in the UI context.
You may use the trigger context variable 'isExecuting'.
From the Apex Developers Guide:
"isExecuting
Returns true if the current context for the Apex script is a trigger, not a Visualforce page, a
Web service, or an executeAnonymous call."
Maybe this helps. I never used it, though.
I will try playing around with it.
I am still wondering what does Trigger.isExecuting means.
Obviously the trigger is executing when you look at the variable within the context of a trigger...
A general Apex script (a webservice method or any other method in an Apex class) has no access to the trigger object, so Trigger.isExecuting is meaningless in that context.
An apex script can look at whether it is being called from within a trigger.
As an example, an Apex class might have a method. Within the method one can check whether this method is being called from a trigger
public class foo {
public static void MemberMethod() {
boolean IsExecuting = system.trigger.isExecuting.
}
What I really need is for a trigger to know whether it is being called from salesforce UI or a webservice method.
One hack would be to have a field on every object called "isSalesForceUI". When called from Web service, I would set it as false.
I would output my addError messages only when isSalesForceUI is true.
The only probably with above is that a user would have to explicitly select isSalesForceUI as true (in the salesforce UI) to see the error messages....don't sound good.
The trigger for Foo would check if iswebService is true:
Yes, this would work, but you should change your function to make sure that the variable is set back to false in any case of a failure.
now in the middle of executing a trigger.
In other words, if a web service inserts a record in the database, the insert trigger can't tell whether web service caused the trigger to execute or was it
done from UI.