Skip to main content
Tweeted twitter.com/StackSalesforce/status/753111355092336640
edited title
Link
Adrian Larson
  • 152.6k
  • 38
  • 249
  • 434

How to find out form which context the utility apex method was invoked Dynamically Determine Calling Context?

added 99 characters in body
Source Link
Pranay Jaiswal
  • 36.7k
  • 17
  • 82
  • 138

We have various ways of invoking apex. Triggers, Inbound Webservices, @InvocableMethod,@RemoteAction and what not. Often we call some or other utility methods from these execution contexts. I have some generic utility method,that should behave differently from the context it is called?

I know about Trigger.isExecuting but it only tells if its running in trigger context or not. I have a utility method that creates lead from Webservices, VF button click and via Lightning . Whenever we create a lead I want some special operations to be done via the source it was originated.(Its not just updating a simple field. leadSource, I have some methods that creates some childs and update other records of other type) . I can achieve this by passing an extra parameter to utility method to tell about source, but i have then to edit hundred of other class that uses this utility method. If i could dynamically find out via which context this piece of code is running,then i would have to change only one class to satisfy my requirement.

Is there something in APEX that tells in what context the apex method was called?

We have various ways of invoking apex. Triggers, Inbound Webservices, @InvocableMethod,@RemoteAction and what not. Often we call some or other utility methods from these execution contexts. I have some generic utility method,that should behave differently from the context it is called?

I know about Trigger.isExecuting but it only tells if its running in trigger context or not. I have a utility method that creates lead from Webservices, VF button click and via Lightning . Whenever we create a lead I want some special operations to be done via the source it was originated.(Its not just updating a simple field.) . I can achieve this by passing an extra parameter to utility method to tell about source, but i have then to edit hundred of other class that uses this utility method. If i could dynamically find out via which context this piece of code is running,then i would have to change only one class to satisfy my requirement.

Is there something in APEX that tells in what context the apex method was called?

We have various ways of invoking apex. Triggers, Inbound Webservices, @InvocableMethod,@RemoteAction and what not. Often we call some or other utility methods from these execution contexts. I have some generic utility method,that should behave differently from the context it is called?

I know about Trigger.isExecuting but it only tells if its running in trigger context or not. I have a utility method that creates lead from Webservices, VF button click and via Lightning . Whenever we create a lead I want some special operations to be done via the source it was originated.(Its not just updating a simple field leadSource, I have some methods that creates some childs and update other records of other type) . I can achieve this by passing an extra parameter to utility method to tell about source, but i have then to edit hundred of other class that uses this utility method. If i could dynamically find out via which context this piece of code is running,then i would have to change only one class to satisfy my requirement.

Is there something in APEX that tells in what context the apex method was called?

added 4 characters in body
Source Link
Pranay Jaiswal
  • 36.7k
  • 17
  • 82
  • 138

We have various ways of invoking apex. Triggers, Inbound Webservices, @InvocableMethod,@RemoteAction and what not. Often we call some or other utility methods from these execution contexts. I have some generic utility method,that should behave differently from the context it is called?

I know about Trigger.isExecuting but it only tells if its running in trigger context or not. I have a utility method that creates lead from Webservices, VF button click and via Lightning . Whenever we create a lead I want some special operations to be done via the source it was originated.(Its not just updating a simple field.) . I can achieve this by passing an extra parameter to utility method to tell about source, but i have then to edit hundred of other classto edit hundred of other class that uses this utility method. If i could dynamically find out via which context this piece of code is running,then i would have to change only one class to satisfy my requirement.

Is there something in APEX that tells in what context the apex method was called?

We have various ways of invoking apex. Triggers, Inbound Webservices, @InvocableMethod,@RemoteAction and what not. Often we call some or other utility methods from these execution contexts. I have some generic utility method,that should behave differently from the context it is called?

I know about Trigger.isExecuting but it only tells if its running in trigger context or not. I have a utility method that creates lead from Webservices, VF button click and via Lightning . Whenever we create a lead I want some special operations to be done via the source it was originated.(Its not just updating a simple field.) . I can achieve this by passing an extra parameter to utility method to tell about source, but i have then to edit hundred of other class that uses this utility method. If i could dynamically find out via which context this piece of code is running,then i would have to change only one class to satisfy my requirement.

Is there something in APEX that tells in what context the apex method was called?

We have various ways of invoking apex. Triggers, Inbound Webservices, @InvocableMethod,@RemoteAction and what not. Often we call some or other utility methods from these execution contexts. I have some generic utility method,that should behave differently from the context it is called?

I know about Trigger.isExecuting but it only tells if its running in trigger context or not. I have a utility method that creates lead from Webservices, VF button click and via Lightning . Whenever we create a lead I want some special operations to be done via the source it was originated.(Its not just updating a simple field.) . I can achieve this by passing an extra parameter to utility method to tell about source, but i have then to edit hundred of other class that uses this utility method. If i could dynamically find out via which context this piece of code is running,then i would have to change only one class to satisfy my requirement.

Is there something in APEX that tells in what context the apex method was called?

added 576 characters in body
Source Link
Pranay Jaiswal
  • 36.7k
  • 17
  • 82
  • 138
Loading
Source Link
Pranay Jaiswal
  • 36.7k
  • 17
  • 82
  • 138
Loading