0

I have created lightning component for record type selection. I have two record types. They are 1. standard opportunity 2. Custom opportunity. My requirement is if I select record type as standard opportunity then it should redirect to Salesforce standard opportunity page and If I select record type as "Custom Opportunity" then it should redirect to custom lightning component name - CreateOpportunityComp.

I am able to redirect to Standard Opportunity but unable to redirect custom opportunity component - CreateOpportunityComp.

Component:

Below is the Lightning COntroller.

    ({
        createRecordFun : function (component, event, helper) {
            var rtDet = document.querySelector('input[name="recordTypeRadio"]:checked');
            alert('rtDet==>' +rtDet)
            if(rtDet != null) {
                document.getElementById("newClientSectionId").style.display = "none" ;
                var createRecordEvent = $A.get("e.force:createRecord");
                createRecordEvent.setParams({
                    "entityApiName": "Opportunity",
                    "recordTypeId":rtDet.id
                });
                createRecordEvent.fire();
            }  
        },
        doInit : function(component, event, helper) {  
            helper.RecordTypeSelectorController(component);  
        }

    })

    Helper:

    ({
       RecordTypeSelectorController: function(component) {
        var action = component.get("c.getListOfRecordType");
        action.setCallback(this, function(actionResult) {
            var infos = actionResult.getReturnValue();
            component.set("v.recordTypes", infos);
        });
        $A.enqueueAction(action);
      }

    })
1
  • Welcome to SFSE. Please take a moment to scroll through the tour and read How to Ask. What is your question? Please edit your post to clarify what you are trying to ask and where specifically you are stuck.
    – Adrian Larson
    Commented Feb 1, 2019 at 14:00

1 Answer 1

1

Summarizing your question:

  1. You have 2 record types (say A and B) on Opportunity
  2. On a Lightning Component, if a User selects A, they should be navigated to standard Opportunity creation screen
  3. If a User selects B, they should be navigated to your custom lightning component

As in your current implementation, it is not working as expected because you are using force:createRecord event to redirect to the Opportunity create page. When you use this event, you will always get redirected to the Standard create screen.

You will need to address the redirection based on the record type selected in your controller in createRecordFun JS funtion. You will need to use force:navigateToComponent (refer to documentation for implementation details) to be able to redirect to your custom component.

Below is a pusedo-code, which you should extend to get it working:

createRecordFun : function (component, event, helper) {
    var recordTypeSelected = <fetch the record type selected on the component>;

    if(recordTypeSelected === "A") {

        // use the force:createRecord event here
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Opportunity",
            "recordTypeId":rtDet.id
        });
        createRecordEvent.fire();
    } else {

          // use force:navigateToComponent here
          var evt = $A.get("e.force:navigateToComponent");
          evt.setParams({
                         componentDef : "c:myComponent",
                         componentAttributes: {}
           });
           evt.fire();
    }
},
2
  • Jayant, I have provided complete code. can u plz share answer in detail.
    – SFDC Guest
    Commented Feb 1, 2019 at 14:15
  • 1
    The answer here is in detail, you will need to adjust/modify it based on your implementation. The way SFSE works is that we don't write code for anyone, but help to provide you solution to specific issues or provide directions. Because I don't know the record type names and how you are fetching the values in your JS, you just need to substitute those in the template here. Also please go through the documentation links provided in the answer so that you can get further details as how it works.
    – Jayant Das
    Commented Feb 1, 2019 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .