You need to sign in to do that
Don't have an account?
TechEd_Programmer
Help with 'List has more than 1 row for assignment to SObject'
Ok, spoke too soon. I am getting this error and need some assistance in restructuring my code.
Below is the code that I have:
List<Trial_Session__c> objTrialSession = new List<Trial_Session__c>(); objTrialSession = [SELECT External_ID__c FROM Trial_Session__c WHERE External_ID__c = :TSInfo.strOrderID]; if(objTrialSession.size() > 0) { // Existing Session Check Trial_Session__c updateTrialSession = [SELECT Patient_Data__c, External_ID__c, Test_Date__c, Type_of_Test__c, Reviewer_Name__c, Reviewer_Comments__c, Date_of_Birth__c, Height__c, Weight__c, Gender__c, Ethnicity__c, Asthma__c, COPD__c, Smoker__c, Date_Reviewed__c, Lung_Age__c, Quality_Grade__c, Quality_Grade_Original__c, Software_Version__c FROM Trial_Session__c WHERE External_ID__c = :TSInfo.strOrderID]; updateTrialSession.External_ID__c = TSInfo.strOrderID; updateTrialSession.Test_Date__c = TSInfo.dtmTestDate; updateTrialSession.Type_of_Test__c = TSInfo.strTypeofTest; updateTrialSession.Reviewer_Name__c = TSInfo.strReviewerName; updateTrialSession.Reviewer_Comments__c = TSInfo.strReviewerComments; updateTrialSession.Date_of_Birth__c = TSInfo.dtmDateofBirth; updateTrialSession.Height__c = TSInfo.numHeight; updateTrialSession.Weight__c = TSInfo.numWeight; updateTrialSession.Gender__c = TSInfo.strGender; updateTrialSession.Ethnicity__c = TSInfo.strEthnicity; updateTrialSession.Asthma__c = TSInfo.strAsthma; updateTrialSession.COPD__c = TSInfo.strCOPD; updateTrialSession.Smoker__c = TSInfo.strSmoker; updateTrialSession.Date_Reviewed__c = TSInfo.dtmDateReviewed; updateTrialSession.Lung_Age__c = TSInfo.numLungAge; updateTrialSession.Quality_Grade__c = TSInfo.strQualityGrade; updateTrialSession.Quality_Grade_Original__c = TSInfo.strQualityGradeOriginal; updateTrialSession.Software_Version__c = TSInfo.strSoftwareVersion; update updateTrialSession; return updateTrialSession; }
It is erroring out on the Update updateTrialSession line.
The error is:
'List has more than 1 row for assignment to SObject'
Thank you for any assistacne you can prodive. FYI the external ID is set to unique
I am not sure of the reason as of now.. but to debug. Can you try to remove the update fields (e.g. updateTrialSession.Test_Date__c = TSInfo.dtmTestDate;) and try to perform update; then add fields one by one to see where the update fails.
Hello TechEd!
Try adding a 'LIMIT 1' to your soqls, so that they always return a max of 1 record.
Regards,
Adrian
Hello TechEd
'List has more than 1 row for assignment to SObject' occurs when your query returns more than 1 record and you try to assign it to a object rather than collection of objects(e.g List).
At first glace you code looks, a possible error is in following query if it return more than 1 row:
Try to change your query to following, and comment rest of the code related to field assignment and update statement.
Check you debug logs if you see size of list is 2 you need to either assign your query result either to list or have Limit clause if that work with business logic you are implementing.
Amit -
I will always have multiple records. How will this code account for that, or how will I structure it if I use Limit 1. I am quite new to integration.