If you have your own custom "New" opportunity button that is a Visualforce page with Apex and you need to implement opportunity gating, you will need to write some Apex code to do so. Use the following code snippets as a guide for implementing opportunity gating in Apex. Note that while the code snippets shown here demonstrate the solution for a Visualforce controller, the logic is identical for Lightning components.
<!-- Visualforce Page --> <apex:page standardController="Opportunity" extensions="MyOppController"> <!-- your VFPage page content here --> </apex:page>
// Apex controller
public with sharing class MyOppController
{
public MyOppController(ApexPages.StandardController stdController)
{
// Required: If in Active Mode then opp must be created from a contact with an active response
if(!FCRM.FCR_SupportAPI.IsPassiveMode())
{
// Optional: only use IsNonResponseByRecordType if you have record types implemented for your contacts. If no record types then remove only this one conditional statement.
if(!FCRM.FCR_SupportAPI.IsNonResponseByRecordType(conid))
{
// Required: Opp must be created from a Contact
String conid = ApexPages.currentPage().getParameters().get('conid');
if(conid == null)
{
// Add custom code here to prevent user from creating the opportunity.
// You could display a message like "Opportunities must be created from a Contact"
// You could develop your page to show a JavaScript alert with a similar message
}
// Required: Contact must be part of an active campaign
List<CampaignMember> activeResponses = FCRM.FCR_SupportAPI.GetActiveResponses(new List<Id>{conid});
if(activeResponses.size() == 0)
{
// Add custom code here to prevent user from creating the opportunity.
// You could display a message like "To create an opportunity the contact must have an active repsonse"
// You could develop your page to show a JavaScript alert with a similar message
// You could redirect user back to the Contact after showing the message
}
}
// Add code here to create opportunities based on the documentation at:
// https://support.fullcircleinsights.com/Full_Circle_Response_Management/Response_Management_Admin_Zone/Response_Management_SDK/10_Extensibility_Functions/11_FCR_SupportAPI_Class
}
}
}
Comments
0 comments
Please sign in to leave a comment.