[SalesForce] Creating a record to a specific Record Type via Lightning component

In my Apex controller class, I was able to query RecordType using:

SELECT Id, Name FROM RecordType WHERE SObjectType = 'Department__c'

I am trying to create a record to a specific record type in the Departments custom object and I am not sure how can I specify that record type(with combination of aura:Iteration and aura:if.

In my Lightning Component(cmp), I am trying this:

<aura:iteration items="{!v.recType}" var="recordType" >
                <aura:if isTrue="{!v.recordType.Name == 'Finance'}">
                    Success!
                    <aura:set attribute="else">
                        False
                    </aura:set>
                </aura:if>

I know this will only go to else statement, but how can I get to the specific recordtype? Is there any contains formula function which I can use in the if statement?

Best Answer

Assuming that in your code you have the following attribute:

<aura:attribute name="recType" type="RecordType "/>

And you are filling that attribute in the client controller when the server side action returns the RecordType list,

you should use the iteration like this:

<aura:iteration items="{!v.recType}" var="recordType" >
    <aura:if isTrue="{!recordType.Name == 'Finance'}">

You do not need the v. because this variable is declared in the iteration

Hope it helps

Itai

Related Topic