0

Apex controller:

public class plController {
@AuraEnabled
public static integer IsDataAvailable() {
    integer count=[select count()   FROM Bank__c where IsActiveFlag__c=: true and BankCompleteFlag__c=: true and  BankStatus__c!='Incomplete'];
    return count;
}
@AuraEnabled
public static List<PipelineResponse> getBankOrigination() {
    List<PipelineResponse> objRes=new List<PipelineResponse> ();
    List<Bank__c> obj=new List<Bank__c>();
    List<Client__c> objallclient=new List<Client__c>();
    List<Bank__c> objBankid=new List<Bank__c>();  
    try{        
        objBankid=[SELECT Id FROM Bank__c where IsActiveFlag__c=: true and BankCompleteFlag__c=: true and BankStatus__c in('Proposal','Waiting for Full Package') ];            
        obj=  [SELECT Id,Name,BankNumber__c,BankStatus__c ,LastModifiedDate FROM Bank__c where IsActiveFlag__c=: true and BankCompleteFlag__c=: true and BankStatus__c in('Proposal','Waiting for Full Package') ORDER BY BankStatus__c];
        objallclient=[SELECT Name,First_Name__c, Last_Name__c,BankId__c FROM Client__c where Primary_Client_for_the_Bank__c =: true and BankId__c IN:objBankid  ];

        for(Bank__c lc:obj)            
        {                
            PipelineResponse obj1=new PipelineResponse();
            obj1.Bankid=lc.ID;
            if(lc.BankNumber__c ==null || lc.BankNumber__c =='')
            {
                obj1.BankNumber=lc.Name;
            }
            else
            {
                obj1.BankNumber=lc.BankNumber__c;
            }

            for(Client__c c:objallclient)  
            {
                if(c.BankId__c==lc.ID)
                {
                    obj1.FullName= c.Name;
                }
            }
       /****/obj1.BankStatus=lc.BankStatus__c; //How can I get a value            
                                     instead of API Name for this Picklist
            obj1.BankDate=lc.LastModifiedDate.date().format();
            objRes.add(obj1);
        }
    }
    catch(exception e){}
    return objRes;  
}
}

Lightning Component:

<aura:iteration items="{!v.Bank}" var="Bank">                                            
<tr >    
<td data-label="Bank Number"  >
    <div class="slds-truncate table-body">            
        <b><a id = "{!Bank.Bankid}" onclick="{!c.PipeLineMenu}">{!Bank.BankNumber}</a>
        </b></div>
</td>
<td data-label="Name" >
    <div class="slds-truncate table-body"><b>
        {!Bank.FullName}</b></div>    </td>
<td data-label="Status"  >
    <div class="slds-truncate table-body"><b>{!Bank.BankStatus} /***/
        </b></div>
</td>
<td data-label="Bank Status DateTime"  >
    <div class="slds-truncate table-body"><b>{!Bank.BankDate}
        </b></div>
</td>    
</tr>
</aura:iteration>

BankStatus__c is a Picklist field, I get the API value as output, how can I get field label as output. Thanks!

4

There's a way to get picklist label via Schema.

For example from official blog:

Schema.DescribeFieldResult fieldResult = Account.PicklistField__c.getDescribe();
List<Schema.PicklistEntry> values = fieldResult.getPicklistValues();
for( Schema.PicklistEntry v : values) {
    System.debug('Picklist Value Label:' + v.getLabel());
    System.debug('Picklist API Name:' + v.getValue());
}

In your case.

  1. Get DescribeFieldResult from Bank__c.BankStatus__c.
  2. Make a Map to store Api <-> Label relationship.
  3. Get Label from the map.

https://developer.salesforce.com/blogs/developer-relations/2017/01/keeping-picklist-integrations-safe-using-api-names.html

Hope it helps.



Code Edit Example:

Put this before loop

    ................................
    // Made a Map to store ApiName <-> Label relationship
    Schema.DescribeFieldResult fieldResult = Bank__c.BankStatus__c.getDescribe();
    List<Schema.PicklistEntry> values = fieldResult.getPicklistValues();
    Map<String, String> valueLabelMap = new Map<String,String>();
    for( Schema.PicklistEntry v : values) {
        valueLabelMap.put(v.getValue(), v.getLabel());
    }

    for(Bank__c lc:obj)            
    { 
       ...........................

Then use the Map to get Label like this:

    obj1.BankStatus = valueLabelMap.get(lc.BankStatus__c);
  • Thank you Kealsalas it is working, but how can I use it in my code?, sorry I am new to coding, can you help me with this, thanks! – Sfdc learner Apr 8 '18 at 16:45
  • The Example was added. Please try it. – Kealsalas Apr 9 '18 at 0:30
  • Awesome!!!!!!! Thank you so much @Kealsalas . Just a small change, we need to add valueLabelMap.put(v.getValue(), v.getLabel()); – Sfdc learner Apr 9 '18 at 3:59
  • Oops, my mistake. Sorry for that. Fixed.@Sfdc learner – Kealsalas Apr 9 '18 at 5:30
1

Another option would be to use toLabel() function in your SOQL statement as described in this answer How to query 'Value' of a picklist rather than the 'API NAME', using SOQL?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.