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
Santro652Santro652 

Pre populating field values using URL over ride and record type

Hi,

 

I have a custom object named 'Process_Unit__c' :

1) The user clicks on the Process unit tab.

2) Then clicks on the 'New' button and goes to record type selection and selects the record type.

3)  then he goes and creates a new record, when the new record shows up i want to populate a default value named "Please do not type here" in a mandatory field called 'process unit name' and make it read only is this possible?

 

I did try it but i am not able to override the new button of the object it self any idea of how this  can be done or should i use a apex class and trigger to populate this default value in the field in the edit mode:

 

I did this URL over ride, but i am able to put this button in the page layout and this is visible in saved mode only, i am not able to override the 'New' button with button i created:

 

https://cs1.salesforce.com/a3A/e?RecordType={!Process_Unit__c.RecordType}&retURL=%2F{!Process_Unit__c.Id}

 

Help ias higly appreciated.

 

raseshtcsraseshtcs

To override the new button you need to use VF page and a controller. Visit this link and if you still are not able to get it... let me know.

http://boards.developerforce.com/t5/General-Development/How-to-set-standard-field-to-a-Default-value/m-p/333877#M60400

 

Santro652Santro652

I dont want to use a VF page is there any other method to do this, reason being i have short time line and the page is really very long with reccord types.

Saurabh DhobleSaurabh Dhoble

A. You need to override the "New" button - you can do this from the "Buttons & Links" section for the object.

B. You need to pass the default value for your field in the URL - cannot make it read-only from the URL, but you can definitely pass in the value.

 

Refer to this series of posts for details - http://writeforce.blogspot.com/2012/12/prepopulating-fields-using-url-hacking.html

Shreyas Shah 9Shreyas Shah 9

Hi

This will help you with  auto populate filed with reporttype and the populate record on new create page. 

global static string getPrefixID(){
    return OBJECT_API_NAME.sObjectType.getDescribe().getKeyPrefix();
}
global static string getObjectId(){
    FieldDefinition listofMetadataPrj =[SELECT QualifiedApiName,DurableId,EntityDefinitionId,Id,Label FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'OBJECT_API_NAME' and QualifiedApiName ='FIELD_API_NAME'];         
           string completeField = listofMetadataPrj.DurableId;
           string[] finalstr =completeField.split('\\.');
            string ObjectId = finalstr[0]; 
           return ObjectID;
}
global static string getDurableIdforField(){
        FieldDefinition listofMetadataPrj =[SELECT QualifiedApiName,DurableId,EntityDefinitionId,Id,Label FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'OBJECT_API_NAME' and QualifiedApiName ='FIELD_API_NAME'];          
               string completeField = listofMetadataPrj.DurableId;
               string[] finalstr =completeField.split('\\.');
                string DurableIdforField = finalstr[1]; 
               return DurableIdforField;
    }
VF page - JS function (call on button action)
 function Record(PrefixID,DurableIdforField,RecordId,RecordName,ObjectID){
    var baseUrl="https://"+ document.domain +"/setup/ui/recordtypeselect.jsp?ent="+ObjectID+"&retURL=/"+PrefixID+"/o&save_new_url=/"+PrefixID+"/e&retURL=/"+PrefixID+"/o&CF"+DurableIdforField+"="+RecordName+"&CF"+DurableIdforField+"_lkid="+RecordId;
    if ((typeof sforce != 'undefined') && sforce != null) {
        baseUrl="/setup/ui/recordtypeselect.jsp?ent="+ObjectID+"&retURL=/"+PrefixID+"/o&save_new_url=/"+PrefixID+"/e&retURL=/"+PrefixID+"/o&CF"+DurableIdforField+"="+RecordName+"&CF"+DurableIdforField+"_lkid="+RecordId;
        sforce.one.navigateToURL(baseUrl);
    } else {
        window.open(baseUrl ,'_blank');
    }

{tushar-sharma}{tushar-sharma}
Hi Santro,

Now URL hack is supported in Lightning Experience. You can override Record type as well and can set default RecordType and set other fields. Check below post for detail and code sample: 
https://newstechnologystuff.com/2020/06/03/salesforce-url-hack-in-lightning/