You need to sign in to do that
Don't have an account?
brozinickr
List has more than 1 row for assignment sobject error
Hello, I have this trigger that stops people from deleting an opportunity of a certain type. Originally only system admins were allowed to delete these opportunities, but now we need another profile to be able to do this as well.
I am getting a list has 1 or more rows for assignments error on the line that is underlined in red. I am not sure how to make this trigger accommodate for both profiles though.
trigger CannotDeleteAcctMgmtRenewal on Opportunity (before insert, before delete) { Profile p = [SELECT Id from Profile where Name IN ('System Administrator', 'Sales Op Admin')]; if(System.Trigger.IsDelete) { for (Opportunity opps : trigger.old) if (UserInfo.getProfileId() != p.Id && (Opps.Type == 'Acct. Mgmt. Renewal'||Opps.Type == 'Acct. Mgmt. Supersede'||Opps.Type == 'Acct. Mgmt. Late Renewal'||Opps.Type == 'Acct. Mgmt. TER'||Opps.Type == 'New Ad Sales')) { opps.addError('You do not have the permissions delete opportunities. Please contact a System Administrator or your designated Ad Operations Specialist.'); } } if(System.Trigger.IsInsert) { for (Opportunity Opps : trigger.new) if (UserInfo.getProfileId() != p.Id && (Opps.Type == 'Acct. Mgmt. Renewal'||Opps.Type == 'Acct. Mgmt. Supersede'||Opps.Type == 'Acct. Mgmt. Late Renewal'||Opps.Type == 'Acct. Mgmt. TER')) { Opps.addError('Error: You do not have the permissions create Acct. Mgmt. Renewal opportunities. Please contact a System Administrator or your designated Ad Operations Specialist.'); } } }
You're trying to find two records (and succeeding), but you didn't store it in a list. Instead, you probably want this:
All Answers
You're trying to find two records (and succeeding), but you didn't store it in a list. Instead, you probably want this:
Thank you for your help, sfdcfox. :)