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
jlimjlim 

Question: Is it possible to update field when viewing record using VF?

On the Opportunity Line item view page, I've a custom List_Price__c field. I want to set up a VF page that does the following:

 

1. If List_Price__c is null then populate with Pricebook ListPrice

2. If List_Price__c is not null, then check if Opportunity contains the word "Closed". If it does, then leave it alone. If not, update it with the Pricebook ListPrice.

 

I've setup a workflow that will do this, but only if the record is edited or created. Since we have existing records that existed before the workflow, List_Price__c could be null. I could export all the Opportunity Line Item IDs and mass populate this field, but I would like to know how to do this with a VF page.

 

I've tried with a formula, but a formula cannot refer to itself.

 

Also, can I update the List_Price__c directly using VF, or do I need to write the corresponding Apex code? Or do I have to actually simulate a quick save which then triggers the workflow rule?

 

Thanks.