You need to sign in to do that
Don't have an account?
Sanchivan Sivadasan
Override New Button and Pre-populate fields
Hi there,
I have an object called Options. This object has a field called Region and this field needs to default to the user's region. The User Object has a picklist value called region. We want to default this value to the user's region and then give them ability to change it if they want to if needed. We have lightning enabled. I want to make this work for classic and lightning if possible. I am trying to override the New Button for the Option Object and pre-populate the fields that I need to pre-populate and then redirect the user to the object which we need to redirect them to. How do I go about doing this?
This is what I have done so far and have not worked:
I created a Visualforce page called OptionNewBtnOverride
For the Option Object's New Button override, I have selected, visualforce for classic and for lightning and mobile I have selected use salesforce classic override. Can someone tell me what I am doing wrong here? Thanks
I have an object called Options. This object has a field called Region and this field needs to default to the user's region. The User Object has a picklist value called region. We want to default this value to the user's region and then give them ability to change it if they want to if needed. We have lightning enabled. I want to make this work for classic and lightning if possible. I am trying to override the New Button for the Option Object and pre-populate the fields that I need to pre-populate and then redirect the user to the object which we need to redirect them to. How do I go about doing this?
This is what I have done so far and have not worked:
I created a Visualforce page called OptionNewBtnOverride
<apex:page standardController="Option__c" extensions="OptionExtension" action="{!pageDirect}"> <script> window.onLoad = function() { var defaultValues = { 'Region__c' : {!region} }; sforce.one.createRecord('Option__c', null, defaultValues); } </script> </apex:page>I also have an extension class called OptionExtension as follows:
public class OptionExtension { public String region {get; set;} public OptionExtension(ApexPages.StandardController controller) { } public void pageDirect() { string region = [Select Region__c From User Where Id = :UserInfo.getUserId()][0].Region__c; } }
For the Option Object's New Button override, I have selected, visualforce for classic and for lightning and mobile I have selected use salesforce classic override. Can someone tell me what I am doing wrong here? Thanks
Here is how my vf looks:
Here is the extension class:
All Answers
Check this post: http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html
Here is how my vf looks:
Here is the extension class: