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
Sohan Rawat 5Sohan Rawat 5 

Need help in below queries

List<Merchandise__c> ml= [select id, Name from Merchandise__c]; As long as I understand with this query that it retrieves all the merchandise and then stores them in a list ml. I'm confused with below for query for query also does the same thing then how it is different. I was just reading this under best practice or recommended one as this retrieves the record in chunks of 200. Can anyone explain me here how this for loop retrieves record in 200 chunk.

and 
for(List<Merchandise__c> ml : [select id, Name from Merchandise__c])
{
}'

Thanks
Sohan Rawat 5Sohan Rawat 5
Also can someone give me some more information on system.assertequals statement for exception handling

Thanks
Chandra Sekhar CH N VChandra Sekhar CH N V
The standard queries discussed in SOQL and SOSL Queries can retrieve either the count of a query or a number of object records, SOQL forloops retrieve all sObjects, using efficient chunking with calls to the query and queryMore methods of the SOAP API. Developers should always use a SOQL for loop to process query results that return many records, to avoid the limit on heap size.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_SOQL.htm
Sohan Rawat 5Sohan Rawat 5
Thanks Chandra,
That link was helpful and answered most of my questions
Do you have any idea on my other query or a helpsite link for system.assert exception details
Chandra Sekhar CH N VChandra Sekhar CH N V
System.assertEquals() is used to validate two values are equal. Basically it is used in test method. This method asserts that the first two arguments, x and y are the same, if they are not a runtime exception is thrown.

 Example:
Account ac=new Account(name=’<someAccount>’);
Insert ac;
Account acc=[select id,name from account where id=:ac.id];
System.assertEquals(acc.name, ‘<someAccount>’);

You can view all assert methods in the below link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_system.htm
Sohan Rawat 5Sohan Rawat 5
Thanks Chandra.