You need to sign in to do that
Don't have an account?
Kathryn Bullock
Trigger to Disallow two Opportunities of Similar Type
Is it possible to create a trigger that will allow no one, except system administrators, to create two opportunities of the same type on the Account object? So, if someone has already created an equipment opportunity, another person could not create another equipment opportunity on the account. I had originally thought this would be a validation rule and now I have no idea what to do. Please advise.
Basically, you can have a Before inserting trigger to check any Identical Opportunity in the Database If You Find any Block that Opportunity being Created Using Trigger.Add Error Method. Create a Unique String (Combination of Any Field of Opportunity) Check against the database If-Match Find then block. Sample Trigger Below. Here Field 1, 2,3 are Example. You change the Filed accordingly to your need. Here in the Below Code and am getting the Values from Trigger.New and String in Variable and Querying the Database and Checking the same Combination. The Furst Can be Eliminated if you Create a Custom Field Which would Update the same using a Formula or Workflow.
Trigger: Handler Class.
Please Mark this as the best answer if this resolves your query.
All Answers
Kindly follow below steps to acheive this requirement.
1. Create Roll up summary field on account object and choose Summarized Object as Opportunity also roll up type as COUNT so that It will keep count of no of opp associated with that account.
2. Write the trigger on Opportunity object as below.
3. This will prevent the user whose profile is other than System admin to create more than one Opp record on the Account.
Kindly mark this answer as best answer if it helps you.
Regards,
Sagar
Basically, you can have a Before inserting trigger to check any Identical Opportunity in the Database If You Find any Block that Opportunity being Created Using Trigger.Add Error Method. Create a Unique String (Combination of Any Field of Opportunity) Check against the database If-Match Find then block. Sample Trigger Below. Here Field 1, 2,3 are Example. You change the Filed accordingly to your need. Here in the Below Code and am getting the Values from Trigger.New and String in Variable and Querying the Database and Checking the same Combination. The Furst Can be Eliminated if you Create a Custom Field Which would Update the same using a Formula or Workflow.
Trigger: Handler Class.
Please Mark this as the best answer if this resolves your query.
So that trigger would be able to prevent a situation like this? Also, is it possible to write in a portion of the trigger that could allow that opportunity type to be created after 90 days?
@ Kathryn Bullock,
IN Trigger.New You can add IF Condition to check System Admin
AND To Check 90 Days. You Can add the AND condition while querying the Data Base The Query output would come null if Opp Created us more than 90 Days so the System will Create a new one.