You need to sign in to do that
Don't have an account?
On mass udpate error getting error: List has more than 1 row for assignment to SObject
Hey everybody,
I am getting the following error when I try and update multiple records (Feature Request custom object) through an enhanced list view. I know it has to do with I am querying multiple records but I don't know the best method to get this fixed. Does it have to do with maps? See apex code below. Thanks!
I am getting the following error when I try and update multiple records (Feature Request custom object) through an enhanced list view. I know it has to do with I am querying multiple records but I don't know the best method to get this fixed. Does it have to do with maps? See apex code below. Thanks!
trigger UpdateOFR on Feature_Request__c (after update, after insert) { Feature_Request__c fr = [Select Feature_Request_Status__c, Target_Release__c, Owner.Name from Feature_Request__c where ID IN :trigger.new]; List<Opportunity_Feature_Request__c> lstToUpdate = new List<Opportunity_Feature_Request__c>(); for(Opportunity_Feature_Request__c obj :[select Feature_Request_Status__c, Feature_Request_Target_Release__c, Feature_Request_Owner__c from Opportunity_Feature_Request__c where Feature_Request__c in : trigger.new]){ obj.Feature_Request_Target_Release__c = fr.Target_Release__c; obj.Feature_Request_Owner__c = fr.Owner.Name; obj.Feature_Request_Status__c = fr.Feature_Request_Status__c; lstToUpdate.add(obj); } if(!lstToUpdate.isEmpty()) update lstToUpdate; }
ie: Another approach (I think the better one) would be to iterate over Trigger.new, like:
Again, I'm pretty new at Apex so take this with a grain of salt.