Skip to main content
Full Circle Insights

Overriding Initial Field Values for the Opportunity Lightning Components


The Opportunity Lightning components (API names FCRM.FCROppCreateAction and FCRM.FCROppNew) support gating of opportunity creation off contacts in Lightning. By default, it sets the value based on the opportunity gating query string in configuration. However, that query string is designed for use with the classic new opportunity page (using predefined field values such as opp5, opp6, etc.) and does not support setting values dynamically.

The Opportunity Lightning components allow developers to create a custom Apex class that overrides the initial opportunity field values when creating opportunities.

Defining the Override Class

Begin by creating a global class named FCROppCreateActionOverride that implements the system.Callable interface.

Implement the standard system.Callable call method.

The action parameter to process is 'oppcreatefieldsoverride'.

The args parameter has two entries:

  • 'contactid' is the ID of the contact from which the action was called
  • 'fieldvalues' is a Map<String,String> where the key is the opportunity field API name, and the value is the desired initial value.

The function should always return null

The fieldvalues map will already contain entries such as the primary campaign and originating contact that are required by response management or defined through the query string configuration. You may override those values in this function.

The following examples shows an implementation of an override function that clears any default values, then sets the initial opportunity account ID to the contact's account ID, and sets the initial opportunity close date to 30 days from today.

global inherited sharing class FCROppCreateActionOverride implements system.Callable{
        global Object call(String action, Map<String, Object> args){
                Map<String,String> fieldValues = (Map<String,String>)args.get('fieldvalues');
                ID contactId = (ID)args.get('contactid');
                List<Contact> cts = [Select ID, AccountID, Account.Name from Contact where ID = :contactId];
                if(cts.size()==0) return null; // This should be impossible
                fieldValues.put('AccountId', cts[0].AccountID);
                fieldValues.put('CloseDate', String.ValueOf(;
            return null;

Testing the Override Class

The following examples shows a typical unit test for the override class.

public without sharing class FCROppCreateActionOverrideTest {
    private static void TestOverrides(){
        Account act = new Account(Name='testact');
        insert act;
        Contact ct = new Contact(FirstName = 'ctest1', LastName = 'ctest1', Email ='',
                                 AccountID =;
        insert ct;
        Map<String,String> oppFieldNamesAndValuesMap = new Map<String, String>();
        string typeclassname = 'FCROppCreateActionOverride';
        System.Type thetype = Type.forName('',typeclassname);   // Try resolving local class first
        if(thetype==null) thetype = Type.forName(typeclassname);    // Try the default
        Object theobject = thetype.newInstance();
        System.Assert(theobject instanceof System.Callable);
        System.Callable overrideInstance = (System.Callable)theobject;
        Map<String, Object> params = new Map<String,Object>{'contactid'=>, 'fieldvalues'=> oppFieldNamesAndValuesMap };'oppcreatefieldsoverride', params);
        system.assertEquals(, oppFieldNamesAndValuesMap.get('AccountId'));

Version Information

Requires version 1.32.2 of Response Management

  • Was this article helpful?