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
crusader2016crusader2016 

Pass Parameter in $Action New

Hi All,


Can anyone share an idea on how to pass a parameter in the $Action New. I am using commandbutton in a custom vf page in a related list that is when click it will be redirected to the creation of new record with its parent object being autopopulated in the lookup. Here's my code:

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New)}" value="New Tutor Session" id="theButton" />

 

I need to pass something in the action of commandbutton so that it will autopopulate the lookup in the new page when redirected.

 

Please advise.

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
crusader2016crusader2016

Hi Bhawani,

 

I just got it right. Thank you so much. :)

 

One more thing, why is it that when I got redirected to that page to create new tutor session, when I press the cancel, it redirects to its own page, instead it should redirect to its parent page since that is only a related list.

 

Once again, thank you

All Answers

Bhawani SharmaBhawani Sharma

 

<apex:outputLink value="{!URLFOR($Action.Account.New, null, ['lookupFieldId'=value])}">
    New
</apex:outputLink>

 

 

crusader2016crusader2016

Hi Bwahani,

 

I tried your suggestion something like this but its not working please correct if I'm missing something

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,['Tutor_Id__c'='a04T0000006BGNt'])}" value="New Tutor Session" id="theButton"/>

 

Thanks in advance

crusader2016crusader2016

Hi All,

 

I getting almost of it. I have just only a problem in the code

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,['CF00NA0000006EWy0'= '{!currName.Name}'])}" value="New Tutor Session" id="theButton"/>

 

What is happening is that salesforce treat that red mark part as a string when loaded in Salesforce it returns the exact '{!currName.Name}' string not the actual value . If I remove the single quote it raises a syntax error. Please advise.

 

 

Devendra NataniDevendra Natani

 

<apex:outputLink value="{!URLFOR($Action.Account.New,null,[retURL=$Page.TestPage+'?id='+obj.id], true)}">New</apex:outputLink>

Please try this. You can replace "obj.id" with your values.

 

Thanks

Devendra

 

 

crusader2016crusader2016

Hi Devenda,

 

I tried my code as per your advise something like this
<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,[retURL=$Page.Tutor_Session__c+'?id='+'{!currName.Id}'], true)}" value="New Tutor Session" id="theButton"/>

 

Nothing happens. My goal is to autopopulate a lookupfield when the new tutor session button is click since it was click in the related list. The parent object should be populated in the lookup.

Devendra NataniDevendra Natani

Instead of  this

 

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,[retURL=$Page.Tutor_Session__c+'?id='+'{!currName.Id}'], true)}" value="New Tutor Session" id="theButton"/>

 Please try this one.

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,[retURL=$Page.Tutor_Session__c+'?id='+currName.Id], true)}" value="New Tutor Session" id="theButton"/>

 Thanks

Devendra

 

crusader2016crusader2016

Hi Devendra,


Sorry I was not clear enough. Another issue is that Tutor_Session__c says it does not exist because this is not a vf custom page, It is a standard tab for a custom object. Is there another way to address that?

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,[retURL=$Page.Tutor_Session__c+'?id='+currName.Id], true)}" value="New Tutor Session" id="theButton"/>
Bhawani SharmaBhawani Sharma

Each lookup field rendeded on UI with a hidden field to grab the ID of looked up record.

I mean, If I select an Account on Contact page then there will be two field to hold this information

Field1 to hold the Account Name

Field2 to hold the Account Id

 

You need to grab the id of your lookupfield and hidden id field from view source and then pass the value in the URL for that.

like

 

<apex:commandButton action="{!URLFOR($Action.Contact.New,null

,['lookupNameId'= '{!currName.Name}','lookupRecordId'= '{!currName.Id}'])}" value="New Tutor Session" id="theButton"/>

 

 

Bhawani SharmaBhawani Sharma

Use this

 

<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null,[retURL=$Action.Tutor_Session__c.Tab+'?id='+currName.Id], true)}" value="New Tutor Session" id="theButton"/>

 

crusader2016crusader2016

Hi Bhawani,

 

I'm almost there, Yes I can see that in the source but the problem right now is Salesforce does not load the {!currName.Name} , and its proper value, instead it loads the whole string of '{!currName.Name}'


<apex:commandButton action="{!URLFOR($Action.Tutor_Session__c.New,null

,['CF00NA0000006EWy0'= '{!currName.Name}'])}" value="New Tutor Session" id="theButton"/>

 

I tried removing the single quote but it says syntax error

Bhawani SharmaBhawani Sharma

Use only currName.Name instead of '{!currName.Name}'.

Remove singlequote('), bracket({}) and ! mark

Devendra NataniDevendra Natani

If we are using $Page then we will have to give the valid visualforce page name with it. Can you please tell me what exactly do you want to pass as parameters?

 

Thanks

Devendra

crusader2016crusader2016

Hi Bhawani,

 

I just got it right. Thank you so much. :)

 

One more thing, why is it that when I got redirected to that page to create new tutor session, when I press the cancel, it redirects to its own page, instead it should redirect to its parent page since that is only a related list.

 

Once again, thank you

This was selected as the best answer
crusader2016crusader2016

Hi Devendra,

I was planning to the pass the name or id parameter in which it autopopulates a lookup field when you click a new button in the related list.

 

Regards

Bhawani SharmaBhawani Sharma

You only need to create a command with action="{!cancel}" . Don't need to do ant coding for this. It will redirect you from where you came.

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