You need to sign in to do that
Don't have an account?

No rows assigned to SObject
Case 1 --- ABC__c a = [select a.Id, a.name from A where a.label = 'apex'];
Case 2 --- List <ABC__c> a = [select a.Id, a.name from A where a.label = 'apex'];
In case of Case 1 , if there is no matching record then it throws an exception when run (no row assigned to Sobject) whereas Case 2 does not throw an exception.
For now I am using syntax of Case 2 in my coding but how can I make the code (Case 1) more efficient without having to use a list as defined in Case 2.
I need to use this in many places, any help would be appreciated.
thanks,
kathyani
Case 2 --- List <ABC__c> a = [select a.Id, a.name from A where a.label = 'apex'];
In case of Case 1 , if there is no matching record then it throws an exception when run (no row assigned to Sobject) whereas Case 2 does not throw an exception.
For now I am using syntax of Case 2 in my coding but how can I make the code (Case 1) more efficient without having to use a list as defined in Case 2.
I need to use this in many places, any help would be appreciated.
thanks,
kathyani
Apex , as you noticed, will throw an exception if 0 or more than 1 record is returned and your return type is a single object (and not a List).
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/langCon_apex_SOQL_single_row.htm