I have established a custom field called "Products Used" on the account object with a variety of banking products to choose from. I am trying to program an Apex controller to query the selected products for the account page the user is on and then return a true or false to my Aura component.

The idea is if a product is being used / true, it will highlight the products name in green in the component on the account page.

I am having trouble building the apex controller. I've had no luck using the SOQL statement as it queries all pick list options. Any advice or guidance on what approach I should be taking to build this controller?


<aura:component controller="gridController"
implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes" access="global">
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <!-- PAGE HEADER -->
    <lightning:layout class="slds-page-header slds-page-header--object-home">
            <lightning:icon iconName="standard:product_item" alternativeText="Products Used"/>
     <lightning:layoutItem padding="horizontal-small">
            <div class="page-section page-header">
                <h1 class="slds-text-heading--label">Products</h1>
                <h2 class="slds-text-heading--medium">Products Used</h2>
    <lightning:layoutItem >

Apex Controller

public with sharing class gridController {  

public static testMethod List<String> getProducts(){
    List<String> productsUsedList = new List<String>();
    Schema.DescribeFieldResult fieldResult = 
    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    for (Schema.PicklistEntry pickListVal : ple) {
    return productsUsedList;

JS controller

doInit : function(component, event, helper) {

    var action = component.get("c.getProducts");

    action.setCallBack(this, function(response) {
        var state = response.getResponse();
        if (response == "Checking Account") {
            component.set(document.getElementById("p1").style.color = "magenta");
        else {
            console.log("Failed with state: " + state);    

Product Grid

<aura:component >
<div aria-labelledby="newproductgrid">
    <!-- BOXED AREA -->
    <fieldset class="slds-box slds-theme--default slds-container--medium">
    <div class="main-box main-box--sizing slds-grid slds-wrap">
        <div id="p1" class="slds-size_1-of-2">
             <div id="p1" class="slds-box slds-box_medium slds-text-align_center slds-text-heading_small slds-m-around_medium">Checking Account</div>
         <div id="p2" class="slds-size_1-of-2">
             <div class="slds-box slds-box_medium slds-text-align_center slds-text-heading_small slds-m-around_medium">Savings Account</div>
         <div class="slds-size_1-of-2">
             <div class="slds-box slds-box_medium slds-text-align_center slds-text-heading_small slds-m-around_medium">Mortgage</div>
        <div class="slds-size_1-of-2">
             <div class="slds-box slds-box_medium slds-text-align_center slds-text-heading_small slds-m-around_medium">Home Equity</div>
        <div class="slds-size_1-of-2">
             <div class="slds-box slds-box_medium slds-text-align_center slds-text-heading_small slds-m-around_medium">Credit Card</div>
        <div class="slds-size_1-of-2">
             <div class="slds-box slds-box_medium slds-text-align_center slds-text-heading_small slds-m-around_medium">Online Banking</div>

1 Answer 1


There's a couple of things not quite clear here, perhaps you forgot to add some of your code?

In Apex controller, why "testMethod", that's probably there by mistake.

Your method "getProducts" is good enough to get the product options, but the JS controller is not processing the results right. You're checking a string, but returning a list.

See the docs on how to check the response state and get the result or error here (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

What's in c:productGrid component? Where are you getting the current record's selected value in the picklist?

Also careful of appPageTypes, you need to be on recordHome to get the recordId

I think you could combine the Apex method you have now with Lightning Data Service (force:recordData). User aura:iteration to iterate over the picklist options and condition the rendering based on the value in the picklist of your current record.



  • The 'testMethod' was there by mistake for something I had tried previously. I have also changed the appPage Types to recordHome on the aura component. I looked into the force:recordData option - and admittedly I am not too familiar with this yet. My goal was to use the apex controller to query the selected pick list values on the account object the user is on, pass these to the JS controller and if successful, update the color on the c:productGrid component. Is this even possible? If so, I am having trouble querying the select values of the current account object in the apex controller. Commented Aug 22, 2019 at 22:17
  • Modifying contents of a component directly like that will be a "no-no" in Lightning. Each component is a closed box. You need to expose public/global attributes or methods to affect it from outside. You aren't querying your current record anywhere. You'd have to pass the recordId from your component to an Apex method, where you query the data. Or use force:recordData. but: I don't mean this in a bad way, but I think you need to take a step back and start from the beginning with development for the Lightning Platform. There are some fundamental specific concepts you seem to be missing.
    – alesremta
    Commented Aug 23, 2019 at 7:44
  • You could go through some modules on trailhead.com to cover the basics of Lightning Components. How to get data and how to structure components. Also, if you are starting, skip Aura components and go straight to LWC. trailhead.salesforce.com/en/content/learn/modules/… trailhead.salesforce.com/en/content/learn/modules/…
    – alesremta
    Commented Aug 23, 2019 at 7:50

You must log in to answer this question.

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