0

I have 2 objects Case & Level agreement ( Don't have any relationship between both objects) I want to compare Task Category value for both objects ...When I write below query on Apex class getting the error:

An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject

Queries in Apex class:

Case c = [select id,Task_Category__c,CaseNumber from Case where id IN:CaseId]; 
Level_Agreement__c sla = [select id,Task_Category__c,Process_Approver_email__c from Level_Agreement__c where Task_Category__c =:c.Task_Category__c];

pls, let me know is there anything missing from my side... Thanks Ram

4

Change Case and Level_Agreement__c with List <Case> and List<Level_Agreement__c>. You're trying to assign a List of sObjects to a single sObject

1

To add to Christian's answer; if you do only expect or require one result from the query, add 'LIMIT 1' to the end and you don't need to update the variable to a List.

Also, if your 'CaseId' is really just one Case's Id, consider amending your query to 'WHERE Id = :CaseId' rather than using 'IN', which is normally used when you have a list or set of values.

  • Thank you Dan for your help...i already identified my mistake.Your other point 'WHERE Id = :CaseId' rather than using 'IN', i miss this small point ...Thanks Dan your help – Sekhar Nov 12 '19 at 18:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.