3

I am using database.query to extract records. I am passing a query from the front end.The query can be anything. But I am not getting the records properly in return.

For example, if I am passing the below query:

String query = 'SELECT fax FROM Account LIMIT 5';
Sobject[] objData = Database.query(query);
system.debug('myData::'+objData);

On debug I am getting this:

(
 Account:{Fax=905-882-5801, Id=0013000000BcUfoAAF}, 
 Account:{Fax=415-683-2349, Id=0013000000BcUfpAAF}, 
 Account:{Id=0013000000BcUfqAAF}, 
 Account:{Fax=+61-292-417954, Id=0013000000BcUfrAAF}, 
 Account:{Fax=408-588-1296, Id=0013000000BcUfsAAF}
 )

As you can see, the third record does not have Fax column inside. I need it to be like this: Account:{Fax=null, Id=0013000000BcUfqAAF}

How to acheive that? Can it be done using something else other than Database.query. I want max 50,000 records.

2 Answers 2

6

The field is there, but it's not being printed out by default. If you try

system.debug('myData::'+JSON.serialize(objData));

you will get the null value as well. So for your intents, all the data is in place.

1
  • nice answer !!!Wish i had one more vote to vote this! Oct 21, 2013 at 13:24
4
String query = 'SELECT fax FROM Account LIMIT 5';
Sobject[] objData = Database.query(query);
system.debug('myData::'+objData[2].fax);//Changed the line

Please note even in the log you will not get Fax=null if field has no value but when you access this into a variable it will be null .

Please see the change i have done to the code in debug line .

2
  • I need the column names also, to pass in my jqery table. How can I get all the columns from the results? Oct 21, 2013 at 12:03
  • 1
    can you post the jquery code of you dont mind ? Oct 21, 2013 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .