Monday, August 29, 2011

Query String Parameters in Apex Salesforce And Param Visualforce Component.

Hello guys.....
Its much interesting topic for the beginner of salesforce developer.

Have a look on Qurey String Parameter  :
Create a visualforcve page with Account as Standard Controller to show the All contact link and their phone no detail for a single account Id.

I am creating a simple visualforce standard controller of Account Object.
<apex:page standardController="Account">
    <apex:pageBlock title="Contacts">
        <apex:form>
         <apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4" border="1">
         <apex:column><apex:facet name="header">Name</apex:facet>
            <apex:commandLink>
                     {!contact.Name}<apex:param name="cid" value="{!contact.id}"/>
            </apex:commandLink>
         </apex:column>
           <apex:column>
              <apex:facet name="header">Phone</apex:facet>
                  {!contact.Phone}
               </apex:column>
         </apex:dataTable>
        </apex:form>
    </apex:pageBlock>
    <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
</apex:page>
After creating the visualforce page ur URL would be somthing like this..
https://ap1.visual.force.com/apex/QueryStringParameters
put any of salesforce Account SFDC id which contains number of contact  in query string like this ..  ?id=00190000005g1db
Now url would be
https://.visual.force.com/apex/QueryStringParameters?id=00190000005g1db

this is ur account Id starting from 001

Now will can see the details Contact Name in First Column and Phone in second column.
Now Name column is a link when u click on this link ...u can see the detail of that particular contact. Now the thing is how is this happening.

When u click on that link u r passing a query stinng parameter through Apex Param tag.
<apex:param name="cid" value="{!contact.id}"/>

Its send the contact Id to the cid parameter which pass in to the 
 <apex:detail subject={!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
Visualforce Tag. U can see {!$CurrentPage.parameters.cid} is the standard format to get the query string as parameter.



Cheers.............................

1 comment:

  1. hi, i want create 2 visualforce page with a controller using custom object.In the first page, i want to select the one record and pass it's id to another visual force page which will show it's details using query string.

    ReplyDelete