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
admin1.3957598082281821E12admin1.3957598082281821E12 

Problem with URL function passing parameter to a lookup field

Hi guys,
I'm a newbie force.com developer: I'm triyng to implement a VF page using URL function passing parameter based on the selected record from a list in the previous VF page, but I have a problem with the autopopulating of a lookup field: can anyone help me, please?

This is the code for my VF page: 


<apex:page controller="Sebi_ControllerSelezionaMacchina">

  <apex:outputLabel value="{!exec_message}" id="msg"/>
<apex:pageBlock >

<apex:PageBlockTable value="{!ListaCar}" var="c" columns="3">
   <apex:column value="{!c.Name}"/>
   <apex:column value="{!c.AvailabilityLights__c}"/>
   <apex:column value="{!c.RatingCar__c}"/>
   <apex:column >
       <apex:form >
         
             <apex:commandButton value="Select" action="{!URLFOR($Action.Journey__c.New,null
,['Car_Select' = '{!$c.Id}' ])}" />


<!-- 'lookupRecordId'= '{!currName.Id}'  ['lookupFieldId'=value]  ['Car_Select__c' = '{!c.Id}' ] -->

          
       </apex:form>
   </apex:column>   
</apex:PageBlockTable>
</apex:pageBlock>

</apex:page>

Best Answer chosen by admin1.3957598082281821E12
Ankit GuptaAnkit Gupta
Hi,

So, do u mean to auto-populate the lookup of the new record that you would be creating??
Then you will have to use URL Hacking technique. You can right click on the lookup and inspect element and then search for the value present in
the name="" in the developer tool in your browser.
I am able to prepopulate the lookup in my new record .Here are a few snapshots that might help you.

First VF Page :
First VF Page
The edit records Page : 
Edit Record Page


<apex:commandButton value="Select" action="{!URLFOR($Action.Rule__c.New,null,[CF00Nf0000000hxZG = c.Contact__r.Name])}"/>

CF00Nf0000000hxZG is the name of the file you will get by inspect element.Do remember to query the name of the lookup contact in your SOQL Query like [SELECT Contact__r.Name from Rule__c].
Hitch : There should be no spaces between the names of the lookup record else it will throw an error.So "TestCon" should be passed instead of "Test Con" through this.

Regards,
Ankit Gupta
  

All Answers

Ankit GuptaAnkit Gupta
Hi ,


Kindly use  :
<apex:commandButton value="Select" action="{!URLFOR($Action.Journey__c.New,null,[Car_Select = c.Id ])}" />

There is no need for single quotes and formula expression as they are variables.So u can directly assign values.You will get the 18 digit Id.

Hope this helps:)


Thanks,
Ankit Gupta
admin1.3957598082281821E12admin1.3957598082281821E12
Hi Ankit,

it doesn't work,  I have no problem with this notation if the custom field isn't a lookup field, but with this look up field (  Car_Select__c  ) this notation doesn't work.

Thank you,
Salvatore
Ankit GuptaAnkit Gupta
Hi,

So, do u mean to auto-populate the lookup of the new record that you would be creating??
Then you will have to use URL Hacking technique. You can right click on the lookup and inspect element and then search for the value present in
the name="" in the developer tool in your browser.
I am able to prepopulate the lookup in my new record .Here are a few snapshots that might help you.

First VF Page :
First VF Page
The edit records Page : 
Edit Record Page


<apex:commandButton value="Select" action="{!URLFOR($Action.Rule__c.New,null,[CF00Nf0000000hxZG = c.Contact__r.Name])}"/>

CF00Nf0000000hxZG is the name of the file you will get by inspect element.Do remember to query the name of the lookup contact in your SOQL Query like [SELECT Contact__r.Name from Rule__c].
Hitch : There should be no spaces between the names of the lookup record else it will throw an error.So "TestCon" should be passed instead of "Test Con" through this.

Regards,
Ankit Gupta
  
This was selected as the best answer
admin1.3957598082281821E12admin1.3957598082281821E12
perfect,now it works, you really helped me, thank you so much Ankit :))))