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
Hari@RockzsHari@Rockzs 

How to pass multiple recordids in query string parameter

 

Hai,

 

 Can u any one help me to pass selected record id  as query string parameters

 

 

ThanX

SFDC bluefish

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

 

// Controller
public with sharing class theController {
  public list<wrapper> records;
  public class wrapper {
    public wrapper(boolean selected, account record) {
      this.selected = selected;
      this.record = record;
    }
    public boolean selected { get; set; }
    public account record { get; set; }
  }
  public theController() {
    records = new list<wrapper>();
    for(account a:[select id,name from Account]) {
      records.add(new wrapper(false,a));
    }
  }
  public ApexPages.PageReference nextPage() {
    return Page.page2;
  }
  public integer getSelectedCount() {
    integer i = 0;
    for(wrapper w:records) {
      if(w.selected) {
        i++;
      }
    }
    return i;
  }
}

<!-- page1 -->
<apex:page controller="theController">
  <apex:form>
    <apex:pageBlock>
      <apex:dataTable value="{!records}" var="record">
        <apex:column headerValue="Select"><apex:inputCheckbox value="{!record.selected}"/></apex:column>
        <apex:column headerValue="Account Name" value="{!record.record.name}"/>
        <apex:pageBlockButtons location="bottom">
          <apex:commandButton value="Next" action="{!nextPage}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>

<!-- page2 -->
<apex:page controller="theController">
  You have selected {!selectedCount} records.
</apex:page>

This is not a particularly functional example, but it does demonstrate the idea behind the concept of view state passing.

 

All Answers

aalbertaalbert

Can you please elaborate or post a code snippet? Apex? Visualforce? API? 

sfdcfoxsfdcfox

Apex Code does not fare well with multiple parameters with the same name (the normal HTML form specifications). A normal web developer would expect the query to be /apex/MyCustomPage?id=Record1&id=Record2&id=Record3. In order to make life less awkward, most languages require the developer to do extra work to make this happen. PHP, for example, requires "[]" to be added to the form's field name. There is no such documented way in Apex Code to do this, so your best option is to do something like this: /apex/MyCustomPage?id=Record1,Record2,Record3. Once your controller has grabbed the parameter, you can use String.split to get the values into an array. As to how to generate this list, the path you take will be largely dependent on your method. I presume you'll be using JavaScript, so array.join is a quick and easy way to accomplish this goal.

Pradeep_NavatarPradeep_Navatar

You can use Pagereference class to set the parameter as query string and get the parameters as well.


Example:


ApexPages.currentPage().getParameters().put('id','your_id');        // set the parameter's value
String idParam = ApexPages.currentPage().getParameters().get('id');           // get the parameter's value
ApexPages.currentPages() returns the reference of currentpage (Pagereference type), and getParameters() method of pagereference class returns the map of parameters and their respective values.

Hari@RockzsHari@Rockzs

Thanks for reply to all,

 

Scenario is,

 

                         I have Datatable containing two columns , one is checkbox ,second column is AccountName

 

   like                       []              India

                                []              USA

                                []             Srilanka

 

now i want to select any of them,then selected records ids are passed to next  VF page and selected account names are display in that VFPAGE.

 

sfdcfoxsfdcfox

If you're going between VF pages, you can use the same controller and extensions to automatically pass the data between the pages without the need for URL parameters.

Hari@RockzsHari@Rockzs

Hai,

 

Thanks for reply 

 

Can u provide any example code snippet.

 

 

SfdcBluefish

 

 

sfdcfoxsfdcfox

 

// Controller
public with sharing class theController {
  public list<wrapper> records;
  public class wrapper {
    public wrapper(boolean selected, account record) {
      this.selected = selected;
      this.record = record;
    }
    public boolean selected { get; set; }
    public account record { get; set; }
  }
  public theController() {
    records = new list<wrapper>();
    for(account a:[select id,name from Account]) {
      records.add(new wrapper(false,a));
    }
  }
  public ApexPages.PageReference nextPage() {
    return Page.page2;
  }
  public integer getSelectedCount() {
    integer i = 0;
    for(wrapper w:records) {
      if(w.selected) {
        i++;
      }
    }
    return i;
  }
}

<!-- page1 -->
<apex:page controller="theController">
  <apex:form>
    <apex:pageBlock>
      <apex:dataTable value="{!records}" var="record">
        <apex:column headerValue="Select"><apex:inputCheckbox value="{!record.selected}"/></apex:column>
        <apex:column headerValue="Account Name" value="{!record.record.name}"/>
        <apex:pageBlockButtons location="bottom">
          <apex:commandButton value="Next" action="{!nextPage}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>

<!-- page2 -->
<apex:page controller="theController">
  You have selected {!selectedCount} records.
</apex:page>

This is not a particularly functional example, but it does demonstrate the idea behind the concept of view state passing.

 

This was selected as the best answer
Hari@RockzsHari@Rockzs

Thank u sfdcFox

 

For  sharing u r knowledge with us, I have another issue please help me regarding this,

 

  Scenario:-

 

       Generic trigger for all objects. trigger will work on all objects in organization,while doing operations with  objects.

 

Thanx IN Advance

sfdcfoxsfdcfox

You can't write just one trigger to hook onto every single sObject. You'd have to write one for each and every object you want to process.