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
Nikhil Singhal 22Nikhil Singhal 22 

split a SOQL query

Hi Everyone,

problem statement: 
I am passing a SOQL query through a textArea of my Visualforce page. I want my controller to split the query and get a list of the queried coloums:

For ex. : InputQuery : 'Select Id, Name, Rating from Account' or 
'Select Id,Name,Rating from Account'(without space in fields)

Output result : List<String>= ['id', 'Name','Rating'];

I tried with InputQuery.split(' ') method but unable to get desired result. Please help me with this.
Best Answer chosen by Nikhil Singhal 22
Abdul KhatriAbdul Khatri
Hi Nikhil

Please try this 
String InputQuery = 'Select Id, Name, Rating from Account';
String fields = InputQuery.substringAfter('Select ').substringBefore(' from');
List<String> fieldList = fields.split(',');

I hope this helps