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
Srikanth sfdc 32Srikanth sfdc 32 

Split Method in apex class

How to get the multiple ids from the url through split method in apex class .. can anyone help me out from this scenario
Vinod ChoudharyVinod Choudhary
Hi,

Use Like:
 
String yourURLString=YOUR_URL_STRING_HERE;
string[] spilt= address.split(' / ');   

//Use your (Whaterever you have in your String) separator

Thanks
Ashif KhanAshif Khan

Hi Srikanth,

Pass multiple ids in URL as below (semicolon separated, Or you can use your separator use the same when splitting).
/apex/YOUR_PAGE?ids = XXXXXXXXXX;XXXXXXXXYY;DFDFDFDFDRXX;

the get the url parameter in a variable using ApexPages.currentPage().getParameteres().get('ids');

lets say you took into below variable.

 

String allIds = ApexPages.currentPage().getParameteres().get('ids');
 

Then split the allIds using split method of String class see below.
 

List<String> allIdList = allIds != null ? allIds.split(';') ? new List<String>();
 

If your ids are coming with different url parameters i.e. /apex/YOUR_PAGE?id1 = XXXXXXXXXX&id2=XXXXXXXXYY&id3=DFDFDFDFDRXX;

 

List<String> allIdList = new List<String>();

for(String urlParamKey : ApexPages.currentPage().getParameteres().get('ids').keyset()){
allIdList.add(ApexPages.currentPage().getParameteres().get('ids').get(urlParamKey));

}
 



Hope that will resolve your queries.

Thanks!
Ashif

Srikanth sfdc 32Srikanth sfdc 32
Here Is my Code 

public class DisplaySelectrecords 
{
   public ApexPages.StandardController setCon;

   public list<Opportunity> opptlist{set;get;}
   
   public opportunity opp {set;get;}
   
      public opportunity oppt {set;get;}

   
   public list<string> oppids{get;set;}
   
     public string id{get;set;}
    

    public DisplaySelectrecords(ApexPages.StandardController controller) 
    {
       setcon = Controller;  
        
        this.oppt = (Opportunity)controller.getrecord();
        
            
        oppIds = ApexPages.currentPage().getParameters().get('id').split(';',-2);

       opptList = [select id,name,Amount,closedate from opportunity where id IN:oppids];
       
       

    }
    
}


 Note :  I am getting Error : Attempt  to dereference a null object In the line of Split();


 
Ashif KhanAshif Khan
Hi

Try as
 

String allIds = ApexPages.currentPage().getParameteres().get('id');
 
oppIds = allIds != null ? allIds.split(';') ? new List<String>();

Regards
Ashif
 
Srikanth sfdc 32Srikanth sfdc 32
I am getting Attempt to dereference a null Object in the split() method ..


 String allIds = ApexPages.currentPage().getParameters().get('id');

  oppIds = allIds.split(';');
Ashif KhanAshif Khan
Hi Srikanth,

Can you please share your URL?
So That I can make sure my code is fit in your requirement or not.

Regards
Ashif
Srikanth sfdc 32Srikanth sfdc 32
Hi Asif

I have list Button on Opportunity Object when ever i selected the records and click on this list button it will redirect to the vf page . In vfpage it will show only selected records. 

can u try the code.. 
Ashif KhanAshif Khan
Hi Srikant

I created a list view button on Account Object 

I created a list view button as TestButton1 and added VF page AccountList

User-added image


Then added TestButton1 in List View of Account And select 2 Account Record Then click on button

User-added image

It will populate Selected Account On VF Page

User-added image

AccController.apxc
 
public with sharing class AccController 
{
    private ApexPages.StandardSetController standardController;

    public AccController(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    public PageReference selectAcc()
    {       
        List<Account> selectedCases = (List<Account>) standardController.getSelected();
        return null;        
    }
}

AccountList.vfp
 
<apex:page standardController="Account" extensions="AccController" recordSetVar="accounts" action="{!selectAcc}">
   <apex:form >
       <apex:pageBlock title="">
           
            <apex:pageBlockTable value="{!selected}" var="acc">
                <apex:column value="{!acc.Name}"/>
               
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>    
</apex:page>


You Don't need to split ID

I hope this is the solution to your question If it works, close the question as best.

Regards
Ashif