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
BMillBMill 

How do I blank out a look-up field?

I'm quite new to Visualforce and hoping for some advice.  I want to blank out the "Primary Campaign Source" field on our opportunities page.  Initially my thought was to run a field update and blank out that field upon creation, but it is not available to update through workflow. 

 

How do I blank out this field, only upon creation of the opportunity, using Visualforce or APEX?

 

Thanks in advance,

Brook

JimRaeJimRae

I am assuming by "blank out" you mean clear the current value (what would be passed in from a lead for example).

You could use an Opportunity Trigger for this.  Make it a before insert, this will only fire on insert (creation) of the new record.

 

Fairly trivial, I believe it would look something like this (untested):

 

 

trigger clearPCS on Opportunity(before insert){ for(Opportunity o:Trigger.new){ o.Campaign=Null; } }