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
randombardrandombard 

Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject"

Hi All getting this error:

 

tom_test_error_conditions.test_package_error_conditions()Class111

 

Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject", Failure Stack Trace: "Class.tom_test_error_conditions.test_package_error_conditions: line 11, column 1"

 

Now there is only one queue that matches these criteria, but it does relate to multiple objects.

 

the line of code is.

 

  Group payroll_queue = [select Id, Name from Group where (Name = 'Time_Off_Manager_Payroll') and (Type = 'Queue')];

 

Any help greatly apreciated.

 

R

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Use limit keyword in the query as followed

 

Group payroll_queue = [select Id, Name from Group where (Name = 'Time_Off_Manager_Payroll') and (Type = 'Queue') limit 1];

All Answers

SurekaSureka
Hi,

There might be two records for the scenario. Otherwise use "Limit 1"

Thanks
Bhuvana
harsha__charsha__c

Use limit keyword in the query as followed

 

Group payroll_queue = [select Id, Name from Group where (Name = 'Time_Off_Manager_Payroll') and (Type = 'Queue') limit 1];
This was selected as the best answer
deepak1.3956330618074822E12deepak1.3956330618074822E12
it worked. I added "limit 1" first in Sandbox and deployed it in production. Once that was successful, i deployed my apex trigger and this time it completed succssfully without any issues.

Thanks Harsha for the trick

Regards
Deepak