You need to sign in to do that
Don't have an account?
Karthik Mohan 6
An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject
I wrote a apex code which is triggerd when a particular filed in updated above a certain value. When i manually edit that field the code works fine. But the code had to be excute whenever the value is updated, it shouldnt wait until manual edit. The apex helps in assigning a account to particular queue.
the apex code is as follows :
public class AssignLeadsUsingAssignmentRules
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
Lead Leads=[select id from lead where lead.id in :LeadIds];
Leads.setOptions(dmo);
update Leads;
}
}
Error message : Error element myWaitEvent_myWait_myRule_1_event_0_SA1 (FlowActionCall).
An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject
Can someone help me with this?. Thanks in advance.
the apex code is as follows :
public class AssignLeadsUsingAssignmentRules
{
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
Lead Leads=[select id from lead where lead.id in :LeadIds];
Leads.setOptions(dmo);
update Leads;
}
}
Error message : Error element myWaitEvent_myWait_myRule_1_event_0_SA1 (FlowActionCall).
An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject
Can someone help me with this?. Thanks in advance.
I think the query you have written is returning more than one leads. Make it List<Lead>
Hope this helps.
can you explain bit more clearly, I'm a newbie in this coding
Hi Gauravendra,
I tried using List<Lead>. but i tdint work since the next line Leads.setOptions(dmo); thorws an error. Because the retun type on setOptions() method is void by default.
Hi Karthik,
Since you are getting a list of lead record. You may call setOptions() for each lead record individually.
Please try this, and let me know if its work.
It worked. Thnaks for the help