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
Hardik Baldania 4Hardik Baldania 4 

how to get SOQL query output in different rows

Hello All,

I've a situation in where I have to get the SOQL query output in all different rows. So how can we do it ? 

Can we use <br> tag in apex class? 

I'm use to apex and I dont know how to do that. Can anyone please explain with some examples and codes.

Regards,
Hardik B.
Hardik Baldania 4Hardik Baldania 4
UPDATE: 

Actually, I want the output of the query elements, Like this :

Account acc = [Select Name,
                                    Phone,
                                    Industry,
                                    Description
                         From Account];

So how all the fileds are written the output should be the same way.

Thanks,
Hardik B.
Saket Sharma 37Saket Sharma 37
Hi Hardik,

As when you query on any sObject it returns List of the sObject

which is like this 

List<Account> allAcc=[select name, Phone, Industry from Account];

as it is returning list so you can iterate the list through for each loop means you are accessing each rows of the query returns

for(Account acc: allAcc){
     System.debug(acc.Name+'  '+acc.Industry);


If the soql query return only one row then it automatically get type cast into returned sObject

Account acc=[select name, Industry from Account limit 1];// this query return only one row.

Thanks
Saket Sharma
Hardik Baldania 4Hardik Baldania 4
Hi Saket, 

This is working by debug, but it is not actually fiving me the output as desired. Also to make more clear I want this to work through @RemoteAction. I have already done this through Reactjs codes. but how can I use it through @RemoteAction to get the desired output as earlier. 

Thanks,
Hardik B. 
Saket Sharma 37Saket Sharma 37
Hi Hardik,

@RemoteAction is asyncrhronous process so it will run this method only when resource will be available try using any synchronous method like action function if you want to call controller method from javascript ,to see the output in real time. As Asynchronous methods are not executed in real time so it will not refresh the view state of the page.

Thanks 
Saket Sharma
Hardik Baldania 4Hardik Baldania 4
Hi Saket,

But how can I use action function in apex class. I know we can do that through VF but is there any workaround to do in apex class ?

Thanks, 
Hardik B.
Saket Sharma 37Saket Sharma 37
Hi I thought u are using with vf page because , The RemoteAction annotation provides support for Apex methods used in Visualforce to be called via JavaScript. This process is often referred to as JavaScript remoting. see the link below 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_RemoteAction.htm

If you are not using vf then I dont y u r using @remoteAction 
if you want some asynchronous call there are other options available like future methods,etc.
Hardik Baldania 4Hardik Baldania 4
Hi, I have eventually using VF Page but all the RemoteAction code construction I'm doing it in Apex and VF is just being used for my Static Resource files to give the output for my webpage.