+ Start a Discussion
Shruti Ranjana 13Shruti Ranjana 13 

Can someone help me with the below apex code ? I am new to this and would appreciate your help.

We have a custom object "Sample Request", when creating a record for the object "Sample Request", the option to select record type is displayed if the user has "Sample_Request_Select_Record_Type" permission set assigned to their profile : 
User-added image
This is working fine in SF classic as the following apex code is written :

  public Boolean getSelectRecordType(){
        list<PermissionSetAssignment> permissionSetAssignments = [SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'Sample_Request_Select_Record_Type'];

        return (permissionSetAssignments.size() != 0);
    }

This code is called in the VF page :

<apex:outputPanel rendered="{!selectRecordType}"> Select a record type to use: &nbsp; <apex:selectList id="recordTypeId" value="{!recordTypeId}" size="1"> <apex:selectOptions value="{!rectypes}" /> </apex:selectList>

But when the same scenario is run in SF lightning, the users are not getting an option to select the record type :
User-added imageThe display record type section is missing because the lightning coding does not have the logic on the basis of "permission set" assignment. Can someone please help me with writing the lightning(@AuraEnabled) code for just this section of apex code :

public Boolean getSelectRecordType(){
        list<PermissionSetAssignment> permissionSetAssignments = [SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'Sample_Request_Select_Record_Type'];

        return (permissionSetAssignments.size() != 0);
    }

Really appreciate the help!! Thanks in advance.
Ankit Khiwansara 10Ankit Khiwansara 10
@AuraEnabled
public Static Boolean getSelectRecordType(){
        list<PermissionSetAssignment> permissionSetAssignments = [SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'Sample_Request_Select_Record_Type'];

        return (permissionSetAssignments.size() != 0);
    }
In the above code, I have added @AuraEnabled annotation and make the method static.
Create a server-side controller as above and call it from a client-side controller.