You need to sign in to do that
Don't have an account?

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>
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>
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 :
The edit records 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
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
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
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 :
The edit records 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