+ Start a Discussion

Lighting Pass Record Type

I am using the e.force:createRecord and want to know if I can use the name (rather than ID) to pass the record type.
I know its not good practive to hardcode the ID's but unsure about how else to pass them.  Currently, I'm using:

{"entityApiName":"Opportunity","defaultFieldValues" :{ "AccountId": "#parentrecordid#", "RecordTypeId":"01239000000HrXEAA0", "Name":"Temp Name", "Region__c":"Inernational"}}


Raj VakatiRaj Vakati
Try like this 
<aura:attribute name="recordTypeId" value="" type="string"/>
var createRecordEvent = $A.get("e.force:createRecord"); 
createRecordEvent.setParams({ "entityApiName": "Contact", 
"recordTypeId": "{!v.recordTypeId"} }); 


Insted of pass the recordId .. pass the record type name to the apex controller ​whihc will retunn ID and set to the attribute and pass it to the event 
<aura:attribute name="recordTypeName" value="" type="string"/>

Call the apex class to get the record type Id on doInit

Set the value to attribute and call it from the event as shown above 
Thanks Raj.  The issue I have is that I am using the sortable grids appexchange product to configure the button.  Its not like building a component.  The section is called, "payload"  Its been a challenge figuring out what I have so far.  I tried this but no luck:

{"entityApiName":"Opportunity","defaultFieldValues" :{ "AccountId": "#parentrecordid#", "recordTypeName":"New Business Int Student", "Name":"Temp Name", "Region__c":"Inernational"}}

Any thoughts?  Thanks again!!

Naveen IlaNaveen Ila

You can use custom label ({!$Label.c.labelName}) and store the record type Id in the same. So that you can update the value muanully (Post deployment steps). 

Naveen Ila
Thanks Naveen.. But I would still be storing the record type id and not a name.  The real issue is that the record type id could (and is) different in my testing environmnet vs my production org.  I want to prevent using ID's if possible.  thanks!!!!
Naveen IlaNaveen Ila
I do agree to your point. However I hope here in this case, we don't options for coding. I don't want to make application dependent on Record Id directly. That is why I mentioned add it to the post deployment steps which is one time job.  
Thanks Naveen!  I appreciate your help on this!!!  Its not the end of the world but I'm surprised they aren't accounting for this

Thanks again!

Pramitha Ayyappan NairPramitha Ayyappan Nair
Hi Fred!! I have the same issue- Did you find a way to pass the RecordtypeId in the Event payload?