0

I want to set record type while creating record in lightning component through e.force:createRecord. But I am not able to do so. I tried using custom label and even I tried hardcoding still It is not showing correct record type and it is showing default record type for record creation. Please find below code for javascript controller:

({
    doInit: function (component, event, helper) {
        var recId = component.get("v.recordId");
        console.log(recId);

        var action = component.get("c.getdetails");
        action.setParams({
            "sId": recId
        });
        action.setCallback(this, function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                $A.get("e.force:closeQuickAction").fire();
                console.log("Success" + JSON.stringify(response.getReturnValue()));
                component.set("v.sampleRequest", response.getReturnValue());
                var sampProd = component.get("v.sampleRequest");

                 if(sampProd.Lead__c === sampProd.Contact__c){
                    var Name = sampProd.Contact__r.Name;
                }
                else
                {
                   var Name = sampProd.Lead__r.Name; 
                }



                var createSampleProduct = $A.get("e.force:createRecord");
                var staticRecordLabel = $A.get("$Label.c.UsCanSampleProductRecordType");
                createSampleProduct.setParams({
                    "entityApiName": "Sample_Product__c",
                    "RecordTypeId": '0121b0000004aeSAAQ',
                    "defaultFieldValues": {
                        'Sample_Request__c' : component.get("v.recordId"),
                        'Name__c': Name,                    
                    }
                });
                createSampleProduct.fire();
            } else {
                console.log("Fail");
            }
        });
        $A.enqueueAction(action);
    }
})

I tried hardcoding:

var staticRecordLabel = $A.get("$Label.c.UsCanSampleProductRecordType");
            createSampleProduct.setParams({
                "entityApiName": "Sample_Product__c",
                "RecordTypeId": '0121b0000004aeSAAQ',

I have tried using:

**var staticRecordLabel = $A.get("$Label.c.UsCanSampleProductRecordType");**
            createSampleProduct.setParams({
                "entityApiName": "Sample_Product__c",
                "RecordTypeId": staticRecordLabel ,

It is taking me to record creation page with default record type and not with record type that I want to set.

Please help.

  • Possible duplicate of : salesforce.stackexchange.com/questions/159029/… – sfdc_sk Feb 18 '19 at 9:47
  • Can you remove the comma after 'Name__c': Name and run the code? Do the record type has been added to your profile? While fetching the values from label, are you considering the api name of label? – sanket kumar Feb 18 '19 at 10:06
  • Issue was due to case sensitive nature of lightning only.It got resolved when I used recordTypeId instead of RecordTypeId – Sharmila Feb 18 '19 at 12:39
  • @Sharmila please add that as an answer so that the question can be considered resolved. – Jayant Das Feb 18 '19 at 13:46
1

Issue was due to case sensitive nature of lightning only.It got resolved when I used recordTypeId instead of RecordTypeId

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.