You need to sign in to do that
Don't have an account?

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 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 just showing for 1 sec UsCanSampleProductRecordType and then it is taking me to record creation page with default record type.
Please help.
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 just showing for 1 sec UsCanSampleProductRecordType and then it is taking me to record creation page with default record type.
Please help.
Greetings to you!
You need to use recordTypeId instead of RecordTypeId as lightning is based on aura framework which is a type of JavaScript and JavaScript is case sensitive so lightning is case sensitive.
Please refer to the below links which might help you further.
http://sfdcmonkey.com/2017/05/09/custom-record-type-selection-lightning-component/
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
You need to use recordTypeId instead of RecordTypeId as lightning is based on aura framework which is a type of JavaScript and JavaScript is case sensitive so lightning is case sensitive.
Please refer to the below links which might help you further.
http://sfdcmonkey.com/2017/05/09/custom-record-type-selection-lightning-component/
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
If you use 'recordTypeId' then it will be Hardcoding ID so it's not salesforce standard so can you please help me to use the developer name?
I tried 'recordTypeName' also tried Developer name but not working. Can you please help me for this