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
Akansha GuptaAkansha Gupta 

.getParameters().put() not working

I have the following method which opens a new record page from a VF page. "Account" is a lookup field in the record page which has to be populated from the TR1__Account__c field in the Closing Report object. How do I achieve this? Here is the method I wrote.
public PageReference create() {
        id = ApexPages.currentPage().getParameters().get('id');
           cr = [Select TR1__Account__c from TR1__Closing_Report__c where Id =: id];
        accountId = cr.TR1__Account__c;
        PageReference pageRef = new PageReference('https://foiberia--devv11.cs88.my.salesforce.com/a2w/e?retURL=%2Fa2w%2Fo');
        pageRef.getParameters().put('Account',String.valueOf(accountId));
        return pageRef.setRedirect(true);
    }
Best Answer chosen by Akansha Gupta
Shruti SShruti S
Here are few steps through which you can achieve this -

Inspect your lookup field and 3,4 line above the element, search for this code - 
<input type="hidden" name="con4_lkid" id="con4_lkid" value="">

User-added image

User-added image

And then collect the name value from the input tag which contains "lkid" in the name value. In my case, since I am using Standard Object, the name value is "con4_lkid". But in your case it might not be con4, but some 15 digit id with "_" and "lkid" (XXXXXXXXXXXXXXX_lkid) . So you have to take that value and prefix "CF" with it.

Once you get that, in the URL, after the retURL, type this 
&con4_lkid=<ACCOUNT-ID>&con4=<ACCOUNT-NAME>
where con4_lkid will contain an Accounts Id and the con4 parameter will contain the same Account's Name.

For your case, here is an example how your URL will look like after the retURL value - 
&CFXXXXXXXXXXXXXXX_lkid=<ACCOUNT-ID>&CFXXXXXXXXXXXXXXX=<ACCOUNT-NAME>
Here is a link for reference - http://forcewizard.com/blog/url-hack-prepopulate-lookup-fields-parent-data

All Answers

Shruti SShruti S
I am sorry I didn't understand the usage "Not Working". Can you expand on that a little more ?

Are you unable to see the URL Parameter called "Account" ?
Amit Chaudhary 8Amit Chaudhary 8
Please try to update your code like below
public PageReference create() {
        id = ApexPages.currentPage().getParameters().get('id');
           cr = [Select TR1__Account__c from TR1__Closing_Report__c where Id =: id];
        accountId = cr.TR1__Account__c;
       
        return new PageReference('https://foiberia--devv11.cs88.my.salesforce.com/a2w/e?retURL=%2Fa2w%2Fo&Account='+accountId);
    }

 
Akansha GuptaAkansha Gupta
@Amit it gives the Account ID in the URL but I need the lookup field value to be populated.User-added image
Shruti SShruti S
Here are few steps through which you can achieve this -

Inspect your lookup field and 3,4 line above the element, search for this code - 
<input type="hidden" name="con4_lkid" id="con4_lkid" value="">

User-added image

User-added image

And then collect the name value from the input tag which contains "lkid" in the name value. In my case, since I am using Standard Object, the name value is "con4_lkid". But in your case it might not be con4, but some 15 digit id with "_" and "lkid" (XXXXXXXXXXXXXXX_lkid) . So you have to take that value and prefix "CF" with it.

Once you get that, in the URL, after the retURL, type this 
&con4_lkid=<ACCOUNT-ID>&con4=<ACCOUNT-NAME>
where con4_lkid will contain an Accounts Id and the con4 parameter will contain the same Account's Name.

For your case, here is an example how your URL will look like after the retURL value - 
&CFXXXXXXXXXXXXXXX_lkid=<ACCOUNT-ID>&CFXXXXXXXXXXXXXXX=<ACCOUNT-NAME>
Here is a link for reference - http://forcewizard.com/blog/url-hack-prepopulate-lookup-fields-parent-data
This was selected as the best answer
Akansha GuptaAkansha Gupta
Thanks @Shruti...Its working