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
Piyush Sharma 6Piyush Sharma 6 

Redirect to vf page by selecting an account from a table

I have a scenario where the user has to slect the account and redirect to a new vf page but I am not able to pass the account id so that the new page displays the details about the selected account. I have posted the vf page and controller code.

Thanks in Advance!
 
<apex:page controller="pagination" tabStyle="Account">
<apex:form >
  <apex:pageBlock >
  Page No: {!pageNo} <br/><br/>
      <apex:pageBlockTable value="{!Accounts}" var="a" rows="10">
          <apex:column >
              <apex:actionSupport action="{!account}" event="onclick">
              <apex:outputtext value="{!a.id}"/>
              </apex:actionSupport>
          </apex:column>
          <apex:column >
          {!a.name}
          </apex:column>
      </apex:pageBlockTable>
  </apex:pageBlock>
  <apex:commandButton value="Previous" action="{!previous}" disabled="{!!hasPrevious}"/>
  <apex:commandButton value="Next" action="{!next}" disabled="{!!hasNext}"/>
  </apex:form>
</apex:page>
public class pagination {
    Public Integer size{get;set;}
    Public Integer noOfRecords{get; set;}
    Account accnt;
    Public Integer pageNo {
    get {
            if(pageNo == null) {
                return 1;
            }
        return pageNo;
        }
    set;
    }
    public ApexPages.Standardsetcontroller setcon {
    get {
        if(setcon == null) {
        size = 5;
        string querystring = 'select name,type from account order by name';
        setcon = new ApexPages.Standardsetcontroller(Database.getQueryLocator(querystring));
        setcon.setpagesize(size);
        noOfRecords = setcon.getResultSize();
        }
        return setcon;
    }
    set {}
    }
    public list<Account> getAccounts () {
        List<Account> accntList = new List<Account>() ;
        for(Account a: (List<Account>) setcon.getRecords()) {
            accntList.add(a);
        }
        return accntList;
    }
    public void setAccount (Account accnt) {
        this.accnt = accnt;
        System.debug('@@'+accnt);
    }
    public void next() {
        pageNo = pageNo+1; 
        setcon.next();
    }
    public void previous() {
        pageNo = pageNo-1;
        setcon.previous();
    }
    public Boolean hasNext {
        get {
            return setCon.getHasNext();
        }
        set;
    }
    public boolean hasPrevious {
        get {
            return setCon.getHasPrevious();
        }
        set;
    }
    public PageReference account() {
        //Account accnt;
        PageReference ref = new PageReference('/apex/wizard2?id='+accnt);
        ref.setRedirect(true);
        return ref;
    }
}


 
Best Answer chosen by Piyush Sharma 6
Harish RamachandruniHarish Ramachandruni
Hi,


Remove all colmns onli one colomn .

add inside colmn .
 
<apex:commandLink value="{!a.Name}" action="/apex/wizard2?id={!a.id}" target="_blank"/>


Any issue ask me .


Regards,
harish.R.
 

All Answers

Harish RamachandruniHarish Ramachandruni
Hi,


Remove all colmns onli one colomn .

add inside colmn .
 
<apex:commandLink value="{!a.Name}" action="/apex/wizard2?id={!a.id}" target="_blank"/>


Any issue ask me .


Regards,
harish.R.
 
This was selected as the best answer
Piyush Sharma 6Piyush Sharma 6
Thanks Harish. It worked.
But is there any way I can get this id in controller class?