function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fred13Fred13 

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"}}

Thanks!!!

Fred
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"} }); 
createRecordEvent.fire();


OR


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 
Fred13Fred13
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!!

Fred
Naveen IlaNaveen Ila
Hi, 


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). 


Regards,
Naveen Ila
 
Fred13Fred13
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.  
 
Fred13Fred13
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!

Fred
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?