You need to sign in to do that
Don't have an account?
SFDC pv
How to convert comma separated number into a list
xx__c obj = [select xxnumber from xx__c];
in obj i will get the xxnumber's with comma seperated values (xxnumber = 12345,6789,09876). Here i need to split the comma's and add only the numbers to the list.
in obj i will get the xxnumber's with comma seperated values (xxnumber = 12345,6789,09876). Here i need to split the comma's and add only the numbers to the list.
<pre>
Xx__c obj = [SELECT XxNumber__c FROM Xx__c LIMIT 1];
List<Decimal> numbers = new List<Decimal>();
for ( String num : obj.XxNumber__c.split( ',' ) )
{
numbers.add( Decimal.valueOf( num ) );
}
</pre>
All Answers
HI SFDC pv,
Can you explain a bit more with example so that i can help you out with your requirement.
<pre>
Xx__c obj = [SELECT XxNumber__c FROM Xx__c LIMIT 1];
List<Decimal> numbers = new List<Decimal>();
for ( String num : obj.XxNumber__c.split( ',' ) )
{
numbers.add( Decimal.valueOf( num ) );
}
</pre>
My requirement is, User will enter the number's in Text field on xxx object with comma seperated values I want to make an API Call for each number and create records.Here i cannot send number with comma as a request so i need to split the comma and send only the number as request also API Call accepts only one number as a request at a time.
For eg.. User is giving the values like 12345, 67890,34567 . I want to get the response for each number and insert records on the YYY object.Since am sending three numbers as a request i need to get the response for 3 no's and insert 3 records.
Please let me know in case if you need any further details on this.
<pre>
List<String> numbers = obj.XXNumber__c.split( ',' );
List<String> numbers = obj.XXNumber__c.split( '\\s*,\\s*' );
</pre>
Thanks for your reply I tried both options provided above but unfortunately that doesn't help. I still get o/p like (12345, 67890,34567 )
I have tried the below code and its working fine
for ( String num : obj.XxNumber__c.split( ',' ) )
{
//Passed num directly to the response (Haven't add it to decimal like you mentioned above)
}