+ Start a Discussion
doudou 

get a list of parameters in url

Hi !

I'm getting trouble when passing a list of parameters in the url and getting them.
I have a visualforce page where i can check some checkboxes, and when one ore more checkboxes are selected i want to retrive them in another visualforce page.

this code works only when i check one checkbox, but i want to be able to check more checkboxes and retrive them...

here is the code of my apex class for my second page (where i want to show the selected elements)

    public List<Commande__c> listeCommandes {get; set;}
    public Commande__c selectedComm{get; set;}

    public String commandeList = System.currentPagereference().getParameters().get('commandeList');
     
    public ExtranetV2_TransfertsCommController2(){

    	System.debug('#### commandeList ' + commandeList);

        if (commandeList != null){
        	selectedComm = [select Id, Code_commande__c, Date_de_commande__c, Type_de_commande__c, Montant_total_calcule__c, Statut_de_la_commande__c
                                from Commande__c
                                WHERE Id = :commandeList
                                ORDER BY Date_de_commande__c DESC
                                LIMIT :transfereesList_size 
                                OFFSET :transfereesCounter];
        }
i thin the problem come from the clause where in my soql query but i can't find how fix that... maybe whith a 'where id in ....' but i don't understand how it works ...

here is how i call it in my visualforce page :
 
<apex:repeat value="{!selectedComm}" var="c">
                                                <div class="tr">
                                                    <span class="cell">
                                                        <apex:outputLink target="_top" value="{!URLFOR($Action.Commande__c.View, c.id)}">{!c.Code_commande__c}</apex:outputLink>
                                                    </span>
(etc...)
                                            </apex:repeat>

thank you for your help :)
 
Best Answer chosen by dou
hitesh90hitesh90
Hello elicec,

You have to take one set variable, add all ids (from parameter) in to that and use that variable in your SOQL query.
see below example:
public String commandeList = System.currentPagereference().getParameters().get('commandeList');

set<Id> sCommandeId = new set<Id>();
if (commandeList != null){
	String[] arrcommandeList = commandeList.split(',');
	for(String str: arrcommandeList){
		sCommandeId.add(str);
	}
	selectedComm = [select Id, Code_commande__c, Date_de_commande__c, Type_de_commande__c,  Montant_total_calcule__c, Statut_de_la_commande__c
                            from Commande__c
                            WHERE Id IN: sCommandeId
                            ORDER BY Date_de_commande__c DESC
                            LIMIT :transfereesList_size 
                            OFFSET :transfereesCounter];
}


Thank You,
Hitesh Patel
SFDC Certified Advanced Developer & Administrator
Email :- hiteshpatel.aspl@gmail.com

All Answers

hitesh90hitesh90
Hello elicec,

You have to take one set variable, add all ids (from parameter) in to that and use that variable in your SOQL query.
see below example:
public String commandeList = System.currentPagereference().getParameters().get('commandeList');

set<Id> sCommandeId = new set<Id>();
if (commandeList != null){
	String[] arrcommandeList = commandeList.split(',');
	for(String str: arrcommandeList){
		sCommandeId.add(str);
	}
	selectedComm = [select Id, Code_commande__c, Date_de_commande__c, Type_de_commande__c,  Montant_total_calcule__c, Statut_de_la_commande__c
                            from Commande__c
                            WHERE Id IN: sCommandeId
                            ORDER BY Date_de_commande__c DESC
                            LIMIT :transfereesList_size 
                            OFFSET :transfereesCounter];
}


Thank You,
Hitesh Patel
SFDC Certified Advanced Developer & Administrator
Email :- hiteshpatel.aspl@gmail.com
This was selected as the best answer
doudou
Thank you for the answer hitesh ! :)
I undrestand better the 'in' in the clause 'where', but when i try to put this code into my apex code it still doesn't work : if i select one checkbox it works, if i select two or more checkbox it dosen't... and i still don't understand why !
hitesh90hitesh90
Post your full code here.
doudou
here is my full code :
public without sharing class ExtranetV2_TransfertsCommController2 {
    private integer TransfereesCounter = 0;  //keeps track of the offset
    private integer TransfereesList_size = 10; //sets the page size or number of rows
    public integer TransfereesTotal_size; //used to show user the total size of the list
    
    public User currentuser{get;set;}
    public Account personContact;
    
    public String livraison {get; set;}

    set<Id> sCommandeId = new set<Id>();
    public Commande__c selectedComm{get; set;}

    public String commandeList = System.currentPagereference().getParameters().get('commandeList');

     
    public ExtranetV2_TransfertsCommController2(){

    	System.debug('#### commandeList ' + commandeList);

        currentuser = new User();
        currentuser = [Select Id, Name, ContactId, Code_Cegid__c from User where Id = :userinfo.getuserId()];
        
        String Iduser = String.ValueOf(userinfo.getuserId()).substring(0,15);

        if (currentuser.ContactId == null) {
            personContact = [SELECT Pays__c, Name FROM Account WHERE Code_conseillere__c = :currentuser.Code_Cegid__c LIMIT 1];
        } else {
            personContact = [SELECT Pays__c, Name FROM Account WHERE Tech_PartnerId__c = :Iduser];
        }

        System.debug('#### personContact ' + personContact);
        
        TransfereesTotal_size = [select count() from Commande__c WHERE Statut_de_la_commande__c = 'En cours' AND Type_de_commande__c = 'Démonstration' AND Conseill_re__c = :personContact.Id];
  
        if (commandeList != null){
        	String[] arrcommandeList = commandeList.split(',');
        	for(String str: arrcommandeList){
        		sCommandeId.add(str);
    		}

        	selectedComm = [select Id, Code_commande__c, Date_de_commande__c, Type_de_commande__c, Montant_total_calcule__c, Statut_de_la_commande__c
                                from Commande__c
                                WHERE Id IN: sCommandeId
                                ORDER BY Date_de_commande__c DESC
                                LIMIT :transfereesList_size 
                                OFFSET :transfereesCounter];
        }

I have made the changes you indicate at line 11 and 36.
hitesh90hitesh90
Please post visualforce page code from where you are passing selected ids..
doudou
Ok here it is :
<apex:repeat value="{!selectedComm}" var="c">
                                                <div class="tr">
                                                    <span class="cell">
                                                        <apex:outputLink target="_top" value="{!URLFOR($Action.Commande__c.View, c.id)}">{!c.Code_commande__c}</apex:outputLink>
                                                    </span>
                                                    <span class="cell">
                                                        <apex:outputText value="{0,Date,dd/MM/YYYY}">
                                                            <apex:param value="{!c.Date_de_commande__c}"/>
                                                        </apex:outputText>
                                                    </span>
                                                    <span class="cell">{!c.Type_de_commande__c}</span>
                                                    <span class="cell">{!c.Statut_de_la_commande__c}</span>
                                                    <span class="cell">{!c.Montant_total_calcule__c}</span>
                                                     <span class="cell">
                                                        <apex:outputLink target="_top" value="{!URLFOR($Action.Commande__c.Edit, c.id)}" styleClass="pen"></apex:outputLink>
                                                    </span>
                                                    <span class="cell">
                                                        <apex:outputLink target="_top" value="{!URLFOR($Action.Commande__c.Delete, c.id, [retURL='/apex/commande1'])}" onclick="return window.confirm('Êtes-vous sûr de vouloir supprimer ?');" styleClass="delete"></apex:outputLink>
                                                    </span>
                                                </div>
                                            </apex:repeat>

It is at the first line.
It is a table of values that I get from my soql query. 
doudou
I come back to tell that i resolve my problem ! 
My error was the declaration of 'selectedComm ' : i wrote 
public Commande__c selectedComm{get; set;}

but it is a List ! So i correct it by writting :
public List<Commande__c> selectedComm{get; set;}

and it work perfectly ! 

Thanks again hitesh, your answer was really helpfull ! :)