How can I get the function getNewRecord() to take a variable as the record Type ID? I'm in a different scratch org and I don't want to have to keep going through and finding the specific recordTypeID.
doInit : function(component, event, helper) {
//Get Record Type Id of Anticipated
String devRecordTypeId = Schema.SObjectType.Invention__c.getRecordTypeInfosByName().get('Anticipated').getRecordTypeId();
//Prepare new record from template
component.find("inventionRecordCreator").getNewRecord(
"Invention__c", // sObject Type (entityAPIName)
devRecordTypeId, //recordTypeID
false, //skip cache?
$A.getCallback(function() {
var rec = component.get("v.newInvention");
var error = component.get("v.newInventionError");
if(error || (rec === null)) {
console.log("Error initializing record template: " + error);
}else{
console.log("Record template initialized: " + rec.sobjectType);
}
})
);
}
I have tried saving devRecordTypeId as an Id and as a String. I get the error
Parsing error: Unexpected token devRecordTypeId
Worth noting this code worked perfectly fine until I changed scratch orgs. (The code above was edited given the problem, and originally did not have devRecordTypeId as the value was explicitly given).
Solution verified. Thank you @Keith C
//Get Record Type Id of Anticipated
var devRecordTypeId = component.get("c.getRecordTypeId");
Controller:
//Get Record Type ID
public static String getRecordTypeId() {
Id devRecordTypeId = Schema.SObjectType.Invention__c.getRecordTypeInfosByName().get('Anticipated').getRecordTypeId();
return devRecordTypeId;
}
Best Answer
This:
looks like Apex code and so will not execute as JavaScript. You can execute that in a server side method and return its value; not sure if there is an easier way to get the value in Lightning Component JavaScript.