+ Start a Discussion
KS KumaarKS Kumaar 

Working with <apex;param> component in visualfoce along with controller

User-added image

As the above page showing, If i click on the button, the corresponded output should be taken to respected detailed page. But it does not taking into respected output. I tried with following Controller and VF page.
Controller :
public class Redirect_Main1 {

   public List<Account> accs { get; set; }
   public ID aid;
    
    public void access(){
        accs = [select id,name,phone,Industry from account];
        for(Account acc:accs){
            aid = acc.id;
        }
        }
       public String getAccess2(){
         return 'https://ap2.salesforce.com/'+aid;
         }
   }
 
VF Page :
<apex:page Controller="Redirect_Main1" action="{!access}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column >
                    <apex:commandButton value="Click" action="{!access}"/>
                        <apex:param name="account" assignTo="{!aid}" value="{!access2}"/>
               </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
I have tried maximum up to my best, but i could not get respected output. May be i think so, i committed wrong with <apex;param> component. Please let me know where i did mistake.
Best Answer chosen by KS Kumaar
Nagendra Prasad ChNagendra Prasad Ch
Hi Kumar,

Try this simple way which works on onClick JS function,

Controller,
public class Redirect_Main1 {

   public List<Account> accs { get; set; }
    public void access(){
        accs = [select id,name,phone,Industry from account];       
        }
        }
     
   }

VF page,
<apex:page Controller="Redirect_Main1" action="{!access}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column >
                    <apex:commandButton value="Click" onclick="window.open('/{!a.Id}','Link', 'scrollbars=yes, resizable=yes, height=800px,width=1300px')"/>                       
               </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Let me know if it works.

Thanks,
Nagendra
 

All Answers

Nagendra Prasad ChNagendra Prasad Ch
Hi Kumar,

Try this simple way which works on onClick JS function,

Controller,
public class Redirect_Main1 {

   public List<Account> accs { get; set; }
    public void access(){
        accs = [select id,name,phone,Industry from account];       
        }
        }
     
   }

VF page,
<apex:page Controller="Redirect_Main1" action="{!access}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column >
                    <apex:commandButton value="Click" onclick="window.open('/{!a.Id}','Link', 'scrollbars=yes, resizable=yes, height=800px,width=1300px')"/>                       
               </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Let me know if it works.

Thanks,
Nagendra
 
This was selected as the best answer
KS KumaarKS Kumaar

Hi....
Thank you Nagendra. You made me so relief. The provided sample is working. But the respected output is coming in new window. Can you provide sample like output will open in new tab only.

Rohit K SethiRohit K Sethi
Hi,

Replace the button code with this code :
 
<apex:commandButton value="Click" onclick="window.open('/{!a.Id}','_blank')"/>    

Note:
actually the issue is that whenever we set the third argument then it open in new window, because the third argument define the configuration of newly open window like width,height,toolbar etc.

Thanks.
KS KumaarKS Kumaar

Hi Rohit K Sethi,

Finally i got my requirement. But i have one doubt. Could you please explain it?
1. Why we are using using onclick="window.open('/{!a.Id}' '_blank')" ?

@Nagendra, if you know about this query, you can also explain...Please do not neglet to answer this query... 

Thanking you

Kumaar

Nagendra Prasad ChNagendra Prasad Ch
Hi Kumar,
  1. onClick  :-  is an event(which tells when action should be executed, ex. onclick, onChange ..etc)
  2. widow.open() :- is an action(What should be executed when event occurs). It takes URL,window type, size ..etc as parameters and opens the given url in same or different window depending on window type.
  3. /{!a.Id} :- is URL which contains Id of account. We no need to append SF org url(https://ap2.salesforce.com/) here. It will automatically take it and append to the url passed as parameter. Ex, if we pass account id(0012800000jkgh6R) then window.open opens an url 
    https://ap2.salesforce.com/0012800000jkgh6R
  1. _blank :-  It is an type of winow to open .
Example,
 
  • _blank - URL is loaded into a new window. This is default
  • _parent - URL is loaded into the parent frame
  • _self - URL replaces the current page
Refer below link for more info,
http://www.w3schools.com/jsref/met_win_open.asp

Hope I answered ur question. If it works please select above one as best answer which will help others searching for the same.

Thanks,
Nagendra
KS KumaarKS Kumaar

Hi Nagendra Prasad

As you said, we no need to append our salesforce org url and it will takes to url  passed as parameter which takes to https://ap2.salesforce.com/followed by id. 

Here i comes with another doubt, we are just passing id of an object record. then how it will take to https://ap2.salesforce.com/followed by id automatically even if are not passing full url

please feel free to clear my doubt and don't hasitate towards me. I am new to work with SFDC along with JS...


Thanking you 

KS Kumaar

Nagendra Prasad ChNagendra Prasad Ch
Hi Kumaar,
That is salesforce out of box feature. We no need to pass our org URL(https://ap2.salesforce.com), salesforce takes it from org and append it. 
If we pass entire URL, then also it will work. But it is not best practice since URL changes from sandbox to sandbox and production. So if we hard code it, code developed in sandbox may not work in Production.
KS KumaarKS Kumaar

Thank you Nagendra. Your answers makes me some understandable. 
Thanks for support. Hope we will continue in future too.

KS KumaarKS Kumaar

Can you please provide any other way for directly contact to you like skype, LinkedIn or any other. Because this forums site unable to conatct you directly or may take long time to contact you(that to if you see my query). So, Please provide any easy way to contact you. If you are feeling any secuirity issues for giving your details here, please take my email id: kumarks337@gmail.com. you can mail to it.

Thanking you
KS Kumaar