Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I want to execute different logic in an update Trigger, depending on whether the Trigger was invoked by an operation through:

  • a Visualforce page

vs. others like

  • standard Page Layout
  • external application using the API
  • future calls or scheduled Apex.

Is there any way to check whether we initially entered the current Execution Context by an operation through a particular Visualforce page.

The Visualforce page is part of a third party Managed Package, so I can't access the code.

share|improve this question

2 Answers 2

How about hidden check boxes/picklist that will be set depend on what source caused it? then you can find information about source in for example trigger.new (before action) list.

share|improve this answer
    
I guess you refer to a hidden checkbox/picklist on the Visualforce page? I can't change anything on the VF page, it is contained in a third party Managed Package. –  Intigris Feb 15 at 13:43
    
No, on object. I think thst's the only way to pass this information –  Artur Kępczyński Feb 15 at 13:47
    
How do I then get this field on the Object populated with the source that invoked the trigger? –  Intigris Feb 15 at 14:04
    
My idea was to set varible in code (future method - apex code, controller - apex code, external application - apex code, standard layout - no value), but as you said - no access to page/controller.... In such case I have no idea. Can't you replace this page? –  Artur Kępczyński Feb 15 at 14:21
    
no, unfortunately not, I can't access the code or replace the page, but I need to know if the Trigger was invoked by this page. Thanks for your effort. –  Intigris Feb 15 at 14:38
  • System.currentPageReference() - What is the current page? It will most likely be null for the external API.
  • System.isBatch() - Is the code currently executing inside a batch Apex job?
  • System.isFuture() - Is the code currently executing inside a method annotated with future (or being called by it)?
  • System.isScheduled() - In the code currently being executed inside a scheduled Apex job?
share|improve this answer
1  
I tried System.currentPageReference(), but it is null when the Trigger is invoked by a record update through the VF page unfortunately.... –  Intigris Feb 18 at 11:29
    
Did you try ApexPages.currentPage() as well? –  beamso Feb 19 at 12:30
    
unfortunately 'null' as well –  Intigris Feb 20 at 20:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.