+ Start a Discussion
@taani.ax1426@taani.ax1426 

how to set default value for required Field.

HI,

 

I want to set default value for Required field of standard object. Before insert trigger is not working on that. Help me.

 

Eg: There is Last name in Lead, which is required field, what my business requirement is when i click on save without entering the field value in "Last Name",trigger would update "XYZ" value in that standard field.

 

Hope my requirement is clear. any help would be appreciated.

 

regards,

Taani

Best Answer chosen by Admin (Salesforce Developers) 
PrakashbPrakashb

one option might be to override the new buton and redirect to your standard page , passing the default value for the last name field.

 

You can try the below URl for populating the last name field on lead.

 

https://your instance /00Q/e?name_lastlea2=test

All Answers

sourav046sourav046

I dont think you can do this using Standard Configuration .Moreover on Standard Sobjects required fields are uneditable to change property .

 

The best thing you can do is to write a trigger .Gimme some time  I am working on it :)

 

Rahul SharmaRahul Sharma

@taani

 

You cannot get rid of required field validation check on Lead.LastName with use of trigger.

AFAIK, The validation is of client side and only after you save the record, the record is saved thus invoking trigger.

PrakashbPrakashb

one option might be to override the new buton and redirect to your standard page , passing the default value for the last name field.

 

You can try the below URl for populating the last name field on lead.

 

https://your instance /00Q/e?name_lastlea2=test

This was selected as the best answer
@taani.ax1426@taani.ax1426

Hi Prakashb,

 

The option you gave would be best for this issue, but the main concern is we added some custom field too, and we cant ignore that. :(

 

regards,

taani

PrakashbPrakashb

Yes but any way you are redirecting only to the standard page...Just that you are sending the last name for it .

@taani.ax1426@taani.ax1426

Yea, but i am unable to find my custom field on the pagelayout.

PrakashbPrakashb

As long as you are redireccting to the same page layout , all the fields on the page layout should be visible.

 

Can you post the URL you are redirecting to??

@taani.ax1426@taani.ax1426

Hi,

 

Thats worked!! grt!!, however i need to give default value for Company too...is that possible both at same time?

Rahul SharmaRahul Sharma

For prepopulating using URL you need to pass values in parameter where parementer name represent HTML ID of your field:

Lead.Company HTML Id is lea3

PrakashbPrakashb

Yeah you can pass both in the same URL.

 

The id for Company field is lea3.

@taani.ax1426@taani.ax1426

Superb...Thanks...!!!

@taani.ax1426@taani.ax1426

HI,

 

how to override the standard page to that standard page with default values? Guide me

 

Thanks

PrakashbPrakashb

When you click on the standard New button, note down the URL you are redirected to,

 

https://your URL /001/e?

 

In that URL set the default values has specified.

 

Create a new VF page wih the object for which you are going to override the button as the controller. Eg Lead.

 

Set action method on your page and on the action method use the below code.

 

public pagereference redirect(){

Pagereference p = new Pagereference(your URL);

p.setredirect(true);

return p;

}

@taani.ax1426@taani.ax1426

Hi,

 

Check my code, getting error:(

 

public class thecontroller {

public pagereference redirect(){

PageReference p = new PageReference(https://cs12.salesforce.com/00Q/e?name_lastlea2=test&lea3=XYZ);

p.setredirect(true);

return p;

}

}

 

pls help me..

Rahul SharmaRahul Sharma

@taaniPagereference accepts a url in String.

@taani.ax1426@taani.ax1426

So, what can be done now..as i am new for this...

PrakashbPrakashb

You should put your url within quotes.

 

PageReference p = new PageReference('https://cs12.salesforce.com/00Q/e?name_lastlea2=test&lea3=XYZ');

@taani.ax1426@taani.ax1426

I already put,

 

The error i got : Compile Error: line 5:36 no viable alternative at character '"' at line 5 column 36

PrakashbPrakashb

Can you post your latest code??

@taani.ax1426@taani.ax1426

Oh sorry, by mistake i put double quote instead of single..could you please write down the code snippet for VF page for this controller..

Thanks

PrakashbPrakashb

You can use the below code.

 

<apex:page controller="Lead" extension="thecontroller" action="{!redirect}">

</apex:page>

@taani.ax1426@taani.ax1426

I am not getting option under 'buttons and link" to override existing page with new page. In drop down my page is not coming..any reason?

PrakashbPrakashb

Your controller has to be the same object in which you are overriding the button.

 

<apex:page standardcontroller="Lead">

@taani.ax1426@taani.ax1426

<apex:page controller="leadcontroller">
<apex:form >
<apex:commandButton action="{!redirect}" value="New"/>
</apex:form>
</apex:page>

 

this is my code, but I am unable to find this page in Buttons and link tab..what changes should be done?

 

Regards

PrakashbPrakashb

If leadcontroller is your class then it has to be your extension and not a controller

 

<apex:page standardcontroller="Lead" extension="leadcontroller">
<apex:form >
<apex:commandButton action="{!redirect}" value="New"/>
</apex:form>
</apex:page>

@taani.ax1426@taani.ax1426

Error: Unsupported attribute extension in <apex:page> in Lead_Page at line 1 column 65

nagalakshminagalakshmi

Hi Prakash,

 

I did the same thing in my code. Its working fine.. But now i got one issue with this. These fields are not populating if i use mozilla version 21. Can you please help me how to solve this.

 

Thanks,

Lakshmi

vahidkhan lodhivahidkhan lodhi
<apex:page standardController="Lead" action="{!URLFOR($Action.Lead.New,$ObjectType.Lead,[lea3=$User.companyname],true)}"> </apex:page>