# Get RecordTypeID by Name for Lightning Component

I am beginning to look at using a Lightning Component to quick create records, I have been able to get quite far but have got a little stuck when trying to set the record type id of the destination record (it's a case and we have 15+ record types and I want to be able to set it alongside a lot of other predefined field values).

This is what I have got so far:

Apex Controller

public class QuickActionsController {
@AuraEnabled
//Get Record Type ID
public static Id getCaseRecordTypeID() {
Id CaseRTID = Schema.SObjectType.Case.getRecordTypeInfosByName().get('RTYPENAME').getRecordTypeId();
return CaseRTID;
}
}


Javascript Controller

    createCase1: function (component) {
//Get Record Type Id
var CaseRecordTypeID = component.get("c.CaseRecordTypeID ");
var createRecordEvent = $A.get('e.force:createRecord'); if ( createRecordEvent ) { createRecordEvent.setParams({ 'entityApiName': 'Case', 'recordTypeId': CaseRecordTypeID , }); createRecordEvent.fire(); } else { /* Create Record Event is not supported */ alert("Case creation not supported"); } },...  This is my first lightning component, trying to make a quick actions menu to let users create records with fewer clicks/fields etc. Sorry edit, the error states: Error on parameter recordTypeId: java://java.lang.String • How is your CaseRecordTypeID declared on the component and when are you populating it? I don't see a call made to the aura method, so if that's done somewhere else? You may like to provide some more code from your component to be able to get some details here. – Jayant Das Aug 14 '18 at 15:06 • Firstly you need to get the value from apex is that returning ? by seeing your code its not return as well. Learn about how server side action works in lightning developer.salesforce.com/docs/atlas.en-us.lightning.meta/… – vignesh Aug 14 '18 at 15:09 • Have you tried hardcoding the recordTypeId? – Lightning Evangelist Aug 14 '18 at 15:10 • Maybe instead of a server method that pulls in just 1 id, you create a method that can return all of the ids and store them in the view state so that you only need 1 server call. – gNerb Aug 14 '18 at 15:20 • Thanks, the link and the answer gave me what I want. I'll keep going as planned just now, hoping to extend the component quite a lot and this is what I was after. – n34_panda Aug 14 '18 at 15:30 ## 1 Answer  var CaseRecordTypeID = component.get("c.CaseRecordTypeID");  This doesn't invoke the server-side controller action getCaseRecordTypeID(). You need to specify the full method name getCaseRecordTypeID - unlike in Visualforce. But then, once you have the right parameter to component.get(), CaseRecordTypeID isn't the return value of your Apex. It's a reference to the server controller action. You need to invoke the action asynchronously and use its return value in your callback method, along these lines (freely stolen/adapted from Trailhead):  var action = component.get("c.getCaseRecordTypeID"); action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { // do something with response.getReturnValue(), such as firing your create event here. } else { console.log("Failed with state: " + state); } });$A.enqueueAction(action);

• make sure you note the correct action name "getCaseRecordTypeID" in your bottom code snippet. – Jason Benkert Aug 14 '18 at 15:14
• Thanks for everyones help, the link in the comments above and your example was exactly what I was after. I've been able to fix my code and now I am a happy ...! – n34_panda Aug 14 '18 at 15:29