Sunday, 1 March 2015

how to use param tag in visualforce?

Hi guys,

Few days back , I was working on apex param tag. I had an requirement to insert a contact under the account I have clicked from different page. I don't have to provide the definition. to this as you know it is there on the internet .

Scenario: -  I have a custom page where I have the table which displays the account as command link. On clicking  any of the record of account should take me to a custom page where I can create contact. Contact which gets inserted should get associated to the account I clicked on.

Solution:-  We have to use the apex param tag in our page and have to send the ID to the url, when redirecting to to our custom contact page.

Lemme walk you through the code snippet:-

<apex:pageBlockTable value="{!Accounts}" var="item">
                           <apex:column headervalue="Account Name">
                                <apex:commandLink action="{!redirectPage}">
                                      <apex:param name="IdOfAccount" value="{!item.id}"/>
                                      {!item.Name}
                                </apex:commandLink>
                           </apex:column>
  </apex:pageBlockTable>

As you can see in the command link tag  have used apex param. In the param tag I have used name attribute and i have assigned it a name as 'IdOFAccount' , through this am sending the Id of account. which I have selected.

Lemme show How I am catching this parameter in code and redirecting to custom contact page.


    public PageReference redirectPage(){
        ID = apexpages.currentpage().getparameters().get('IdOfAccount');
        pagereference pr= new pagereference('/apex/CreateContac?IdOfAccount='+ID).setRedirect(true);
        return pr;
    }

As in command link in action attribute I have mentioned redirectPage. In the instance of pageref I have redirected it to createContact page with IdOfaccount from my visualforce page.


This How You can easily make the use of   Apex param tag.

Soon, I ll be uploading a video of demo.

cheers!

#happyCoding
ankushsalesforce@gmail.com


No comments:

Post a Comment

oAuth Use Case -  Headless API Explained in the Easiest way Wondering why? and When we use the Headless API flow Use case example: Imagine a...