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
timomertimomer 

Trigger, before edit?

Hi,

 

I need a trigger to run before a user edit to set the value of some fields.

 

The need...

When a new line item is added, at the point of the multilineitem.jsp page ("Add Product" > "Select" product/s > THIS PAGE) - I want a controlling List box to be set to the same name as the product, so its controlling lists can be pre filtered.

 

Salesforce support say this is possible with a trigger, but "OpportunityLineItem (before insert)" runs after the user clicks save and before the record is inserted into the DB - not before the edit page appears.

 

Can this be done!?

 

thanks,

tim

_Prasu__Prasu_

That can be done in the trigger after user clicks save, which fires a trigger. It will not be possible to set the value before user clicks save.

 

You can write a trigger, which will set that value, It will override the value set by the user.

sfdcfoxsfdcfox

Strictly speaking, there is no "before edit", but you can instead do the following:

 

Create a new VF page with the following content:

 

 

<apex:page standardController="Account">
<script>
window.top.location.href =
    '{!URLFOR($Action.Account.New,null,["acc2"="some value"],true)}'
</script>
</apex:page>

 

 

Next, go to Setup > App Setup > Customize > Accounts > Buttons and Links, and Override the New button with your Visualforce page. When you click on New Account from the Create New dropdown, or any other page, "Account Name" will be defaulted to "some value".

 

Here's how to make it work:

 

1) Set StandardController to the object you wish to override.

2) Change $Action.Account.New to the object and verb (ex. $Action.Contact.Edit, $Action.Certificate__c.Delete).

3) Replace "null" with an ID replacement if not using New (ex. Contact.Id, Certificate__c.Id).

4) Inside the square brackets, you can add as many fields as you want; use commas to separate values. Use quotes for litral values, or merge fields without quotes. The "acc2" in my example is Account Name; you need to view the source code to figure out the correct field name to use.

 

You can use this method for the foreseeable future as a way to default values for any object.

timomertimomer

Hi sfdcfox, eprasu

 

Yes, I thought a VP page maybe my only option. The only issue with your approach sfdcfox is that between the page with the button press (Opportunity) and the page I need to set the default value (multilineitem.jsp) there is a page where you pick the products you wish to add.

 

I already know how to pass variables in the URL with a button override, to the next page - but not to the page after that.

 

Does that make sense?

 

Thanks!