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
URVASHIURVASHI 

database.query(Srting query)

hi,

can some help me

 List<SObject> ObjectContents;

String query=Select name from contact;

 ObjectContents = database.query(query);

 

if my query returns 2 rows then size of objectcontents wll be how much?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
DevADSDevADS

Hello ,

 

If your query returns 2 rows then the size of ObjectContents will be 2.

You can check it by writing debug statement like System.debug('=====ObjectContents size====='+ObjectContents.size());

 

Best Practice : Try to put the Limit clause in queries though you have less number of records than Salesforce governor limits.

 

Let me know if you need any more information.

 

Thanks,

Amit Shingavi

 

All Answers

harry.freeharry.free
String query = 'Select name from contact';
List<SObject> ObjectContents = database.query(query);
system.debug(ObjectContents.size());

 Run the code in console.

harry.freeharry.free
should be 2
DevADSDevADS

Hello ,

 

If your query returns 2 rows then the size of ObjectContents will be 2.

You can check it by writing debug statement like System.debug('=====ObjectContents size====='+ObjectContents.size());

 

Best Practice : Try to put the Limit clause in queries though you have less number of records than Salesforce governor limits.

 

Let me know if you need any more information.

 

Thanks,

Amit Shingavi

 

This was selected as the best answer
URVASHIURVASHI

Hey can u tell me whats the limit clause?

DevADSDevADS

Use LIMIT to specify the maximum number of rows to return:


SELECT fieldList
FROM objectType
[WHERE conditionExpression]
LIMIT number_of_rows


Example:

SELECT Name
FROM Account
WHERE Industry = 'Media' LIMIT 100

This query returns the first 100 Account records whose Industry is Media.