You need to sign in to do that
Don't have an account?
Problems with apex script
Hi, I got this error message while trying to change Cases Status even though tha case doesn't have a Setup. --> : CaseResponseTimeTrigger: execution of BeforeUpdate caused by: System.QueryException: List has more than 1 row for assignment to SObject: Class.ServiceAvailability.GetHoursToUse: line 128, column 1
When I check that line 128 :
public Id GetHoursToUse(Case updatedCase, Setup__c relatedSetup) {
// Get the default business hours
BusinessHours defaultHours = [select Id from BusinessHours where IsDefault=true];
Account costCenter = [select Id, Name, Account_Top_Parent__c from Account where Id =: relatedSetup.Cost_Center__c];
System.Debug('CC Id: ' + costCenter.Id);
System.Debug('CC Name: ' + costCenter.Name);
Account mainAccount = [select Id, Name, V_Account_Number__c from Account where Id =: costCenter.Account_Top_Parent__c];
System.Debug('MA Id: ' + mainAccount.Id);
System.Debug('MA Name: ' + mainAccount.Name);
Contract contract = [select Id, AccountNumber__c, Business_Hours__c, Status from Contract where AccountNumber__c =: mainAccount.Videra_Account_Number__c];
System.Debug('Contract Id: ' + contract.Id);
System.Debug('Contract Business Hrs: ' + contract.Business_Hours__c);
System.Debug('Contract Acc Number: ' + contract.AccountNumber__c);
Id hoursToUse = contract.Business_Hours__c != null ? contract.Business_Hours__c : defaultHours.Id;
return hoursToUse;
}
I can't understand why this error occurs?
Try to filter out the additional records by adding more conditions to the where clause.
All Answers
Try to filter out the additional records by adding more conditions to the where clause.
As 'Avidev9' said, your SOQL query returns more than 1 record .To fix this error, use any of the following.
Regards,
HK.
Thanks, this helped a lot! ! :)