function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SARTHAK GARG 4SARTHAK GARG 4 

Not able to visit current case Edit record page through dynamic record picklist selector(ligtning conponent)

On click of next button the edit record page of current record with the selected recortype should be Displayed

Please find below code & let me know where i am going wrong :-

 

MyQuickAction.cmp

<aura:component Controller="RecordTypeSelector" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="lstOfRecordType" type="List" />
    <!-- Fetch all available record types after component construction but before rendering -->
    <aura:attribute name="recordId" type="id" />
    <aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>
    
    
    
    <lightning:layout multipleRows="true" horizontalAlign="center">
        
        <lightning:layoutItem flexibility="auto" padding="around-small"
                              
                              size="12"
                              
                              largeDeviceSize="12"
                              
                              mediumDeviceSize="12"
                              
                              smallDeviceSize="12">
            
            <lightning:formattedText value="Select Case Record Type" />
            
        </lightning:layoutItem>
        
        <lightning:layoutItem flexibility="auto" padding="around-small"
                              
                              size="12"
                              
                              largeDeviceSize="12"
                              
                              mediumDeviceSize="12"
                              
                              smallDeviceSize="12">
            
            
            
            <!-- select to hold all available record type names list -->            
            <lightning:select aura:id="recordTypePickList" name="selectRecordType" label="Select a Record Type">
                
                <option value="" text="Select Record Type"/>
                
                <aura:iteration items="{!v.lstOfRecordType}" var="item">
                    
                    <option value="{!item.recordTypeId}" text="{!item.recordTypeName}"/>
                    
                </aura:iteration>
                
            </lightning:select>
            
            
            
        </lightning:layoutItem>
        
        <lightning:layoutItem flexibility="auto" padding="around-small"
                              
                              size="3"
                              
                              largeDeviceSize="3"
                              
                              mediumDeviceSize="3"
                              
                              smallDeviceSize="6">
            
            <lightning:button variant="brand" label="Next" onclick="{!c.createRecord}"/>
            
        </lightning:layoutItem>
        
        <lightning:layoutItem flexibility="auto" padding="around-small"
                              
                              size="3"
                              
                              largeDeviceSize="3"
                              
                              mediumDeviceSize="3"
                              
                              smallDeviceSize="6">
            
            <lightning:button variant="neutral" label="Cancel" onclick="{!c.closeModal}" />
            
        </lightning:layoutItem>
        
    </lightning:layout>
    
</aura:component>

 

 

MyQuickActionController.js
 

({
    
    /*

     * This method is being called from init event

     * to fetch all available recordTypes

     * */
    
    fetchListOfRecordTypes: function(component, event, helper) {
        var action = component.get("c.fetchRecordTypeValues");
        //pass the object name here for which you want
        
        //to fetch record types
        
        action.setParams({
            
            "objectName" : "Case"
            
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            //console.log('response.getReturnValue() == ' + response.getReturnValue());
            component.set("v.lstOfRecordType", response.getReturnValue());
        });
        $A.enqueueAction(action);
    },    
    
    /*

     * This method will be called when "Next" button is clicked

     * It finds the recordTypeId from selected recordTypeName

     * and passes same value to helper to create a record

     * */
    
    createRecord: function(component, event, helper, sObjectRecord) {
       console.log('Inside Create Record');
        var recordId = component.get("v.recordId");
        
        var selectedRecordTypeName = component.find("recordTypePickList").get("v.value");
        
        if(selectedRecordTypeName != ""){
            
            var selectedRecordTypeMap = component.get("v.mapOfRecordType");
            
            var selectedRecordTypeId;
            
            
            
            //finding selected recordTypeId from recordTypeName
            
            for(var key in selectedRecordTypeMap){
                
                if(selectedRecordTypeName == selectedRecordTypeMap[key]){
                    
                    selectedRecordTypeId = key;//match found, set value in selectedRecordTypeId variable
                    
                    break;
                    
                }
                
            }
            
            //Close Quick Action Modal here
            
            helper.closeModal();
            
            
            
            //Calling CreateRecord modal here without providing recordTypeId
            helper.showEditRecordModal(component,recordId ,selectedRecordTypeId, "Case");
            
        } else{
            
            alert('You did not select any record type');
            
        }
        
        
        
    },
    
    
    
    /*

     * closing quickAction modal window

     * */
    
    closeModal : function(component, event, helper){
        
        helper.closeModal();
        
    }
    
})



MyQuickActionHelper.js
({

    /*

     * This methid takes recordTypeId and entityTypeName parameters

     * and invoke standard force:createRecord event to create record

     * if recordTypeIs is blank, this will create record under master recordType

     * */

    showEditRecordModal : function(component,recordId, selectedRecordTypeId, entityApiName) {

       

        var editRecordEvent = $A.get("e.force:editRecord");

        if(editRecordEvent){ //checking if the event is supported
          
            if(selectedRecordTypeId){//if recordTypeId is supplied, then set recordTypeId parameter

                editRecordEvent.setParams({
                    
                            
                    "entityApiName": entityApiName,

                    "recordTypeId": recordTypeId,

                   

                "recordId": component.get("v.recordId")

                   

                    

                });

            } 
            
            

        } else{

            alert('This event is not supported');

        }

    },

    

    /*

     * closing quickAction modal window

     * */

    closeModal : function(){

        var closeEvent = $A.get("e.force:closeQuickAction");

        if(closeEvent){

        closeEvent.fire();

        } else{

            alert('force:closeQuickAction event is not supported in this Ligthning Context');

        }

    },

})



Apex Controller

public class RecordTypeSelector{

    /*

     * This function will fetch the RecordTypes of

     * provided object and will return a map of

     * recordTypeId and recordTypeNames

     * it excludes 'master' record type

     * */

    public static List<recordTypeWrapper> recordtypemap;

@AuraEnabled        

    public static List<recordTypeWrapper> fetchRecordTypeValues(String objectName){

        List<Schema.RecordTypeInfo> recordtypes = Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfos();    

        recordtypemap = new List<recordTypeWrapper>();

        for(RecordTypeInfo rt : recordtypes){
            if(String.isNotBlank(rt.getName().trim())){
                recordtypemap.add(new recordTypeWrapper(rt.getRecordTypeId(), rt.getName()));
            }
        } 
        system.debug('recordtypemap == ' + recordtypemap);
        return recordtypemap;

    }
    
    public class recordTypeWrapper {
        @AuraEnabled      
        public String recordTypeId;
        @AuraEnabled      
        public String recordTypeName;
        public recordTypeWrapper (String recordTypeId, String recordTypeName) {
            this.recordTypeId = recordTypeId;
            this.recordTypeName = recordTypeName;
        }
    }

}