function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rafarafa 

conditional trigger

I have developed a custom VF page for manipulating Opportunity Product sObject in addition to default page, which is also being used. I want to be able to fire after update trigger only if update to the record is originating from default page. I have created a custom field on the object that keeps track of the originating page but I'm not sure how to enforce setting field value when the update is originating from default page. Perhaps there is a better way for controlling the logic? Thanks
Best Answer chosen by Admin (Salesforce Developers) 
Ronak PatelRonak Patel

You Can make one Custom Bolean Field (By Default false) in the opp. product.

when update is called from Standard page trigger runs(Make one Condition in Trigger for this Field).

 

When using Custom VF page make that field true and run the trigger. that will not runs your Logic

 

That's it

 

 

All Answers

Ronak PatelRonak Patel

You Can make one Custom Bolean Field (By Default false) in the opp. product.

when update is called from Standard page trigger runs(Make one Condition in Trigger for this Field).

 

When using Custom VF page make that field true and run the trigger. that will not runs your Logic

 

That's it

 

 

This was selected as the best answer
Navatar_DbSupNavatar_DbSup

Hi,


You have to simply read the URL inside your trigger code to identify weather the updating is through the VF page or Default page. Try the below code as reference:
Trigger MyTest on Objectname(after update)
{
String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
System.debug('Current request URL: ' + currentRequestURL);
if(!currentRequestURL.contains('apex'))
{
Not put your entire code inside this condition so that it will execute for default page only.
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

rafarafa

Thanks!

WorkhardWorkhard

Hi,

You can try the navatar solution also, you dont have to create any bollean field in that case.

rafarafa

I tired it as well.  It worked flawlessly. It is a simpler implementation, and it is the solution that I stuck with.