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
praveenkumarpraveenkumar 

How to set standard field to a Default value

Hi All,

 

I am trying to set a field to a default value, if i take a text field and assign it to some default value but it can be editable, I want the field to set as default and it cant be editable...

 

Please give me some suggestions to do this...

 

Its urgent.....

 

Thanks in advance..

 

Praveen K.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

If you want to make the field non-editable with a default value, then is there any purpose to show it in edit page?

 

All Answers

Rahul SharmaRahul Sharma

I think you are using formula field for it, 

if its the case, workflow, field update will be useful for your task.

shruthishruthi

If you want to use a default value which can be editable for a custom field - Create new Custom field [newField__c] and have a default value there. When creating a new record, the field value will be filled with the default value - if needed you can edit it as well.

 

If you want to use a default value which can be editable for a standard field - Create a WFR which will update the field value each time a record is created. In this case, the field value will be defaulted each time you create but you can modify this when required. Note: you can have the WFR to check for a condition if the standard field is null do a field update - so that you do not have to edit the record each time after you create it.

 

Hope this helps!

praveenkumarpraveenkumar

Hi Rahul,

 

Thanks for responding quickly, Yes i am using formula filed for this but it is updating when the page is submitted.

 

But my requirement is to set the fleld ( Standard or Custom ) value to default before submitting the page that means when i click on New button the page should have the field with defaulted value and which can not be editable...

 

 

Please look for this and suggest me...

 

Thank you,

 

Praveen K

praveenkumarpraveenkumar

Hi Shruthi,

 

Thank you for responding me, When i use the workflow for this it will update after the page is submitted....

 

But i need to set this field  to a default value and it should not be editable by the user..

 

Please look forward for this and suggest me...

 

Thank you,

Praveen K

 

 

Rahul SharmaRahul Sharma

If you want to make the field non-editable with a default value, then is there any purpose to show it in edit page?

 

This was selected as the best answer
praveenkumarpraveenkumar

Hi Rahul,

 

It is working like what i am exactly expecting..

 

Thanks for your help...

 

Praveen K.

Rahul SharmaRahul Sharma

I guess, you used formula field.

praveenkumarpraveenkumar

Hi Rahul ,

 

Please look forward on to my requirement...

 

I need to assign the Case Owner ( Standard field ) value to a default value from the queue, for this i used workflow rule.

 

But with workflow rule field update action it is updating after the page is submitted, i need this case owner field sholud be defaulted before submitting that is when the page gets loaded.

 

Please share your ideas on this requirement.

 

Thanks,

praveen k

raseshtcsraseshtcs

I am not sure if this applies in your context or not but for the information of the rest of the people. If we want to default a standard field like 'Name' which is also mandatory for a record to be saved. We can override the New button with VF page and then redirect the user to a manually created URL:

PAGE

<apex:page standardController="Opportunity" extensions="DefaultOpportunityNameControllerExt" action="{!putDefault}">

</apex:page>

 CLASS

public class DefaultOpportunityNameControllerExt{   
 public DefaultOpportunityNameControllerExt(ApexPages.StandardController controller) {
    }
    public PageReference putDefault() {     
//creating a page reference    PageReference pageRef;        
//Variables to hold the URL parameters    String retURL =  ApexPages.currentPage().getParameters().get('retURL');        
string defaultName='This field will be overwritten on save';
pageRef = new PageReference('/006/e?retURL='+retURL+'&opp3='+defaultname);    
//adding nooverride to prevent infinite loop     
pageRef.getParameters().put('nooverride', '1');             
//pageRef.setRedirect(true);            
 return pageRef;    
 }

 In the URL opp3 represents the HTML id of the Name field of the opportunity

 

Rahul SharmaRahul Sharma

raseshtcs, Nice trick.

 

This method  works for input fields, Since owner appears as output text it doesn't works, but there must be some workaround.

We can do this, overide new button to redirect user to url like:

Enter id of contact here, Eg : contactid = 003K0000003Pgd3

https://cs9.salesforce.com/003K0000003Pgd3/e?name_lastcon2=Test123 

(Try executing above url with your contact Id)

 

here, name_lastcon2 is html value of the input field last name, and if you assign it value as Test123, it comes prepopulated.

So, no need to overide whole page, just change the url of new button.

Try it, hope it help a bit.

raseshtcsraseshtcs

True.. this wont work here as the owner is not editable.... but what can be done is remove the owner field from the page layout, create a new custom field called owner and prepopulate that with whatever  value needed and in the backend write a workflow to make the owner as we need. Also write a validation rule to prevent the users from changing the value of our custom field.

 

Praveen.KPraveen.K

Hi Rasesh,

 

I can assign the default value for a custom field but when the case is submitted, the person who is working on that case can able to change the owner to himself..

 

So i hope if we use the custom field this functionality wont work....

 

What exactly the requirement is, we need to change the existing functionality of Case owner like instead of displaying username we should make it to prepopulate the value from the queue...

 

Please share your ideas as soon as possible....

 

Thank you,

 

Praveen K

raseshtcsraseshtcs

Yes... so we can write a validation rule on that field which prevents the user from making any change to it. And we can use a workflow rule to populate the owner field with whatever we want to.

Geetanjali kondaGeetanjali konda
Hi ,
Even I have a requirement where i have to default the standard language picklist field based on logged in user language while creating a record. Can anyone suggest the solution.
Thanks
Geet