You need to sign in to do that
Don't have an account?
List has no rows for assignment to SObject
Hello,
I found a controller that will clone all fields for an object. I am using this controller to help me clone and opp if specific requirements are met. (StageName = '09-Win' and type = 'Reseller / Partner Registration'). The works fine if there is an opp that meets the requirements but if I try to change that op (or update any op that does not meet the requirements) I get the error:
Error:Apex trigger partnerOppClone caused an unexpected exception, contact your administrator: partnerOppClone: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.partnerOppClone: line 2, column 1
I understand that it is telling me that since it does not meet the requirements it had no rows - I am just stumped at how to go about fixing it.
Thanks in advance.
trigger partnerOppClone on Opportunity (after update) { Opportunity originalOpp = [select Id from Opportunity where StageName = '09-Win' and type = 'Reseller / Partner Registration']; sObject originalSObject = (sObject) originalOpp; List<sObject> originalSObjects = new List<sObject>{originalSObject}; List<sObject> clonedSObjects = SObjectAllFieldCloner.cloneObjects( originalSobjects, originalSobject.getsObjectType()); Opportunity clonedOpp = (Opportunity)clonedSObjects.get(0); clonedOpp.StageName='training'; if (clonedOpp != null) insert clonedOpp; }
Something like this should do:
I'm also not sure why you have to cast the opportunity to an original SObject list, passing in the list of opportunities should work regardless since SObject is the parent type of opportunity.
All Answers
Something like this should do:
I'm also not sure why you have to cast the opportunity to an original SObject list, passing in the list of opportunities should work regardless since SObject is the parent type of opportunity.
Thanks!