2

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?

2
  • Can you expand on this a little - why do you need to do this? May 17, 2017 at 2:06
  • Hey Caspar, thanks for checking in. I have three different Record types under Departments object. The lightning component which I am working is publicly accessible. So based on the User login status, the form should submit a record to a specific record type, i.e, logged-in user's recordtype should be diff. from a not-logged-in user's recordtype.
    – SatyaV
    May 17, 2017 at 2:34

2 Answers 2

1

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

3
  • Yes, I do have have <aura:attribute name="recType" type="RecordType[]"/>. I am using an array of RecordType object, because, I am trying to access a set of record types. My apologies for using v. again in the <aura:if>, even after removal of this, I have no luck. I am not sure exactly how I can be able to get a specific record type from the list.
    – SatyaV
    May 17, 2017 at 12:40
  • print your RecordType[] to the console to see if all data has arrived, also check for case-sensitive issues (is the recordType Finance or finance?) May 17, 2017 at 12:59
  • Sounds good. I was able to get the solution after a lot of debug. I have used <aura:if isTrue="{recordType.Name == 'Finance'}"> instead of <aura:if isTrue="{!recordType.Name == 'Finance'}">, thus unable to get into the if statement. I only realized once I couldn't go further. Thanks for your time.
    – SatyaV
    May 17, 2017 at 13:51
1

I believe you are trying to select a record type in Record creation. If so, check this link It may help you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .