1

Got an Apex function that takes in a String as a parameter (which is the current page's recordId - Opportunity Id) and I want to query the Opportunity for any Product__c objects its linked to via a lookup field. However I've noticed that the String Parameter of the Apex function is never populated and thus I always get the error 'Argument cannot be null'. Any ideas what I could be doing wrong?

Component

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" 
            controller="ProductSelectionCtrl" access="global">


<aura:attribute name="products" type="Product__c[]"/>
<aura:attribute name="selectedProductId" type="String"/>
<aura:attribute name="asset_classes" type="Product__c[]"/>
<aura:attribute name="sub_asset_classes" type="Product__c[]"/>
<aura:attribute name="macro_strategies" type="Product__c[]"/>
<aura:attribute name="strategies" type="Product__c[]"/> 
<aura:attribute name="filterObject" type="Object" />
<aura:attribute name="pageSize" type="integer" default="18"/>
<aura:attribute name="page" type="integer"/>
<aura:attribute name="pages" type="integer"/>
<aura:attribute name="total" type="integer"/>
<aura:attribute name="openModalTrue" type="Boolean"/>




<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<aura:handler event="c:ProductFilterChange" action="{!c.productFilterChangeHandler}"/>

<!-- event that recieves the product Id from an onlcik action on the ProductTile cmp -->
<aura:handler event="c:ProductGetProdIdEvent" action="{!c.saveProductToOpportunity}"/>

<aura:handler name="change" value="{!v.asset_classes}" action="{!c.onAssetClassFilterChange}"/>
<aura:handler name="change" value="{!v.sub_asset_classes}" action="{!c.onSubAssetClassFilterChange}"/>
<aura:handler name="change" value="{!v.macro_strategies}" action="{!c.onMacroStrategyFilterChange}"/>
<aura:handler name="change" value="{!v.strategies}" action="{!c.onStrategyFilterChange}"/>
<aura:handler name="change" value="{!v.openModalTrue}" action="{!c.onModalInitialization}"/>




<aura:registerEvent name="ProductModalOpen" type="c:ProductSelectorInitialModal" />


<div class="slds-m-right_xx-large">
               <div>        
                   <ul aura:id="list" class="slds-grid slds-grid--pull-padded slds-wrap">          
                       <aura:iteration items="{!v.products}" var="product" indexVar="index">                    
                           <c:ProductTile product="{#product}" index="{#index}"/>                   
                       </aura:iteration>
                   </ul>                    
                   <c:Paginator page="{!v.page}" pages="{!v.pages}" total="{!v.total}" label="products"
                                previousPage="{!c.onPreviousPage}" nextPage="{!c.onNextPage}"/>

               </div>
             </div>

Controller

 ({
doInit: function(component, event, helper) {


    var filterObject = {
        searchKey: '',
        assetClass: '',
        subAssetClass: '',
        strategy: '',
        macroStrategy : ''
    }

    component.set("v.filterObject", filterObject);
    //sets the openModal attribute to true which in turn will trigger an event to open the Initial Modal screen
    component.set("v.openModalTrue", "True");

    helper.loadProducts(component);





},

           onPreviousPage: function(component, event, helper) {
                          var page = component.get("v.page") || 1;
    var direction = event.getParam("direction");
    page = page - 1;
    helper.loadProducts(component, page);
           },

           onNextPage: function(component, event, helper) {
                          var page = component.get("v.page") || 1;
    var direction = event.getParam("direction");
    page = page + 1;
    helper.loadProducts(component, page);
    debugger;
           },


onModalInitialization: function(component, event, helper) {
    /*need to figure out a way to check if the opp (current record id) has a Product__c connected to it)*/
    var modalEventFire = $A.get("e.c:ProductSelectorInitialModal");        

    helper.getLinkedProduct(component);
    debugger;


                          /*
    if(modalCount == 0){
           modalEventFire.setParams({"openModal" : "True"});
           modalEventFire.fire();

    }else{
        component.set("openModalTrueCount", 1);
    }*/
},



productFilterChangeHandler: function(component, event, helper) {

    var filterObject = component.get("v.filterObject");
    if (event.getParam("searchKey") !== undefined) {
                   filterObject.searchKey = event.getParam("searchKey");

    }
    if (event.getParam("assetClass") !== undefined) {
        filterObject.assetClass = event.getParam("assetClass");
    }
    if (event.getParam("subAssetClass") !== undefined) {
        var subAssetClass = event.getParam("subAssetClass");
                   filterObject.subAssetClass = event.getParam("subAssetClass");
    }
    if (event.getParam("strategy") !== undefined) {
        var strategy = event.getParam("strategy");

                   filterObject.strategy = event.getParam("strategy");
    }
    if (event.getParam("macroStrategy") !== undefined) {
        var macroStrategy = event.getParam("macroStrategy");
                   filterObject.macroStrategy = event.getParam("macroStrategy");
    }
    if (event.getParam("focusFunds") !== undefined) {

                   filterObject.focusFund = event.getParam("focusFunds");
    }
    if (event.getParam("defendFunds") !== undefined) {

                   filterObject.defendFund = event.getParam("defendFunds");
    }

    if (event.getParam("introductionFunds") !== undefined) {

                   filterObject.introductionFund = event.getParam("introductionFunds");
    }

    console.log(filterObject);
    helper.loadProducts(component);
},

           onAssetClassFilterChange: function(component, event, helper){             

                   var acOptionChange = $A.get("e.c:ProductSelectorAssetClassFilterEvent");     
                   var resultingACs = component.get("v.asset_classes");     
                   var acOptionChangesValues = acOptionChange.getParam("assetClassTypes");
                   acOptionChange.setParams({"assetClassTypes" : resultingACs});
                   acOptionChange.fire(); 

           },

           onSubAssetClassFilterChange: function(component, event, helper){               

        var sacOptionChange = $A.get("e.c:ProductSelectorSubAssetClassFilterEvent");     
        var resultingSACs = component.get("v.sub_asset_classes");
        var sacOptionChangesValues = sacOptionChange.getParam("subAssetClassTypes");
        sacOptionChange.setParams({"subAssetClassTypes" : resultingSACs});            
        sacOptionChange.fire(); 
           },


           onMacroStrategyFilterChange: function(component, event, helper){                 
        var macStratOptionChange = $A.get("e.c:ProductSelectorMacroStrategyFilterEvent");
        var resultingMacStrats = component.get("v.macro_strategies");
        var macStratOptionChangesValues = macStratOptionChange.getParam("macroStrategyTypes");
        macStratOptionChange.setParams({"macroStrategyTypes" : resultingMacStrats});
        macStratOptionChange.fire(); 

           },


           onStrategyFilterChange: function(component, event, helper){  
        var stratOptionChange = $A.get("e.c:ProductSelectorStrategyFilterEvent");
        var resultingStrats = component.get("v.strategies");
        var stratOptionChangesValues = stratOptionChange.getParam("strategyTypes");
        stratOptionChange.setParams({"strategyTypes" : resultingStrats});
        stratOptionChange.fire(); 

           },


           saveProductToOpportunity: function(component, event, helper){
        var selectProdId = event.getParam("prodId");
        var oppId = component.get("v.recordId");
        helper.saveProductToOpportunity(component, selectProdId, oppId);

           }

})

Helper

getLinkedProduct: function(component){

    var action = component.get("c.getProducts");        
    var oppId = component.get("v.recordId");        
    action.setParam({
        "currentOppId": oppId            
    });        
    action.setCallback(this, function(response){
        if (state === 'SUCCESS') {
            var result = response.getReturnValue();                
        }    
    });        

    $A.enqueueAction(action);

},

Apex Controller (part of it)

@AuraEnabled
public static List<Opportunity> getProducts(String currentOppId) {

    Id oppId = Id.valueOf(currentOppId);
    System.debug('oppId: ' + oppId);
    Opportunity[] linkedProduct = [Select Id, Product__c from Opportunity 
    where Id =: oppId];
    System.debug('linkedProduct: ' + linkedProduct);
    return linkedProduct;
}
5
  • 1
    can you add lightning component code and also, where you have placed this component? Commented Jul 4, 2018 at 10:50
  • are you getting "currentOppId" null in sever side???
    – Annappa PH
    Commented Jul 4, 2018 at 10:54
  • @SFDC_learner yes
    – DimzeeD
    Commented Jul 4, 2018 at 11:01
  • no need to do type coversion just pass string value to your query .Opportunity[] linkedProduct = [Select Id, Product__c from Opportunity where Id =: currentOppId];....comment oppId
    – Annappa PH
    Commented Jul 4, 2018 at 11:04
  • I'am not seeing > aura:attribute "recordId" in your lightning component. Then how you are accessing component.get("v.recordId") in your Javascript side.if you access like that you will get null value in your server side
    – Annappa PH
    Commented Jul 4, 2018 at 12:09

1 Answer 1

4

You have a simple typo in your JavaScript controller. action.setParam(), with that object parameter, should be action.setParams(), plural.

3
  • Thankyou @David but I've tried that with no results
    – DimzeeD
    Commented Jul 4, 2018 at 10:54
  • add force:hasRecordId interface ::<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName"> and also correct it your action.setParams() [david already mentioned it]
    – Annappa PH
    Commented Jul 4, 2018 at 10:57
  • Very nice @David.Very nice catch :)
    – Annappa PH
    Commented Jul 4, 2018 at 10:59

You must log in to answer this question.

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