+ Start a Discussion
Ravi Dutt SharmaRavi Dutt Sharma 

Populate read-only field through url hacking

I have created a VF page and associated controller to override the standard New Button on lead page. In the controller, I am creating a PageReference and in the url, I am passing a parameter which populates a picklist field present on Lead record. This works fine, the picklist gets populated as expected. Now on the page layout, if I make the picklist field as read-only, the field no longer gets populated. Any hack to populate a read-only field through url params? Attaching the code for reference :

VF Page :
<apex:page standardController="Lead" extensions="LeadFieldsAutoPopulateCtrl" action="{!doRedirect}">

Apex Class :
public class LeadFieldsAutoPopulateCtrl {

    public LeadFieldsAutoPopulateCtrl(ApexPages.StandardController stdController){
    //Method gets called before the Visualforce page gets loaded. It redirects the user to the New Lead detail page.
    public PageReference doRedirect(){
        Pagelayout_FieldNames__c ownerGeographyFieldName = Pagelayout_FieldNames__c.getValues('Lead_OwnerGeographyPicklist');
        String redirectURL = '/00Q/e?retURL=%2F00Q%2Fo&nooverride=1';
        String userId = UserInfo.getUserId();
        List<User> userList = new List<User>();
            userList = [SELECT Geography__c FROM User WHERE Id =:userId];
        String userGeography = '';
        if(userList.size() > 0){
            userGeography = userList.get(0).Geography__c;
        if(String.isNotBlank(userGeography) && String.isNotBlank(ownerGeographyFieldName.PagelayoutFieldName__c)) {
            redirectURL = redirectURL + '&' + ownerGeographyFieldName.PagelayoutFieldName__c + '=' + EncodingUtil.urlEncode(userGeography,'UTF-8');
    	PageReference pageRef = new PageReference(redirectURL);
        return pageRef;