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
Shobha JamesShobha James 

for (Database.SaveResult sr : srList)..can somebody expalin the syntax?

for (Database.SaveResult sr : srList)..can somebody expalin the syntax?
what does the 'semi colon' in the bracket mean?
in
Database.SaveResult[] srList = Database.insert(conList, false); // Iterate through each returned result for (Database.SaveResult sr : srList) { if (sr.isSuccess()) { // Operation was successful, so get the ID of the record that was processed System.debug('Successfully inserted contact. Contact ID: ' + sr.getId()); } else { // Operation failed, so get all errors for(Database.Error err : sr.getErrors()) { System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); System.debug('Contact fields that affected this error: ' + err.getFields()); } }
Best Answer chosen by Shobha James
David @ ConfigeroDavid @ Configero
This is the syntax of a loop to iterate over every element in srList.

for (each variable named 'sr' in array 'srList) { execute loop block }

Database.SaveResult is the class and data type of variable 'sr', and 'srList' is a list of Database.SaveResult objects (ie. List<Database.SaveResult>).

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

Please mark this answer as correct if it helped you.

All Answers

David @ ConfigeroDavid @ Configero
This is the syntax of a loop to iterate over every element in srList.

for (each variable named 'sr' in array 'srList) { execute loop block }

Database.SaveResult is the class and data type of variable 'sr', and 'srList' is a list of Database.SaveResult objects (ie. List<Database.SaveResult>).

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

Please mark this answer as correct if it helped you.
This was selected as the best answer
Shobha JamesShobha James
Thank you so much David ...quick responds!!!!