Values from helper.js controller not passed to apex controller!












1














I am trying to pass values from helper.js file to apex controller class. The apex controller dont seem to be getting the values. Here in this code I am passing the bStreet & bCity values.



Component:



<aura:component controller="AccountsActiveListApexController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<!--<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}" /> -->
<aura:attribute name="accounts" type="List"/>

<lightning:card>
<div class="slds-grid slds-gutters slds-p-around_medium">

<div class="slds-col slds-size_5-of-6">
<div>
<table class="slds-p-around_large bgSettings">
<tbody>
<tr >
<td>
<div class="slds-p-around_small">
<lightning:input aura:id="bStreet" placeholder="Street Name"/>
</div>
</td>
<td >
<div class="slds-p-around_small slds-p-left_xx-small">
<lightning:input aura:id="bCity" placeholder="City"/>
</div>
</td>
<td>
<div>
<button class="slds-button slds-button_brand" onclick="{!c.searchAddress}">Search</button>
</div>
</td>
<td>
<div class="slds-float_right slds-p-right_medium">
<lightning:buttonGroup>
<lightning:button label="Never" class="slds-button_neutral" value="never"/>
<lightning:button label="Cold" class="slds-button_neutral" value="cold"/>
<lightning:button label="Active" class="slds-button_neutral" value="active"/>
<lightning:button label="X" class="slds-button_neutral" value="clear"/>
</lightning:buttonGroup>
</div>
</td>
</tr>
</tbody>
</table>
<table id="oppsTable" class="slds-table slds-table_bordered slds-table_col-bordered slds-p-around_x-small">
<thead>
<tr>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Account Number">Account Number</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Name">Name</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Billing Address">Billing Address</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Status">Status</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="acc">
<tr class="slds-hint-parent">
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.AccountNumber }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.Name }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Address__c}</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Status__c }</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</div>
<div class="slds-col slds-size_1-of-6">
</div>
</div>
</lightning:card>




Helper .js:



    searchAddresses : function(component, bStreet, bCity) {  
var address = component.get("c.accountsOnAddress");
address.setParams(
{
bStreet : bStreet,
bCity : bCity
}
);
//console.log(bStreet, bCity);
address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}
});
$A.enqueueAction(address);
}


Apex Controller Code:



    @AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
System.debug('Test');
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity='bCity'];
}









share|improve this question
























  • can you add the component as well, please?
    – Carlos Naranjo
    Nov 24 at 21:01










  • @Carlos Original post edited with component.
    – Sumchans
    Nov 24 at 21:07










  • fyi: naming your variables the same as your attributes is never a good idea, in such a case, you might want to consider converting your attribute names to strings, ex: "bStreet" : bStreet and "bCity": bCity
    – glls
    Nov 24 at 21:31
















1














I am trying to pass values from helper.js file to apex controller class. The apex controller dont seem to be getting the values. Here in this code I am passing the bStreet & bCity values.



Component:



<aura:component controller="AccountsActiveListApexController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<!--<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}" /> -->
<aura:attribute name="accounts" type="List"/>

<lightning:card>
<div class="slds-grid slds-gutters slds-p-around_medium">

<div class="slds-col slds-size_5-of-6">
<div>
<table class="slds-p-around_large bgSettings">
<tbody>
<tr >
<td>
<div class="slds-p-around_small">
<lightning:input aura:id="bStreet" placeholder="Street Name"/>
</div>
</td>
<td >
<div class="slds-p-around_small slds-p-left_xx-small">
<lightning:input aura:id="bCity" placeholder="City"/>
</div>
</td>
<td>
<div>
<button class="slds-button slds-button_brand" onclick="{!c.searchAddress}">Search</button>
</div>
</td>
<td>
<div class="slds-float_right slds-p-right_medium">
<lightning:buttonGroup>
<lightning:button label="Never" class="slds-button_neutral" value="never"/>
<lightning:button label="Cold" class="slds-button_neutral" value="cold"/>
<lightning:button label="Active" class="slds-button_neutral" value="active"/>
<lightning:button label="X" class="slds-button_neutral" value="clear"/>
</lightning:buttonGroup>
</div>
</td>
</tr>
</tbody>
</table>
<table id="oppsTable" class="slds-table slds-table_bordered slds-table_col-bordered slds-p-around_x-small">
<thead>
<tr>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Account Number">Account Number</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Name">Name</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Billing Address">Billing Address</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Status">Status</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="acc">
<tr class="slds-hint-parent">
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.AccountNumber }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.Name }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Address__c}</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Status__c }</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</div>
<div class="slds-col slds-size_1-of-6">
</div>
</div>
</lightning:card>




Helper .js:



    searchAddresses : function(component, bStreet, bCity) {  
var address = component.get("c.accountsOnAddress");
address.setParams(
{
bStreet : bStreet,
bCity : bCity
}
);
//console.log(bStreet, bCity);
address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}
});
$A.enqueueAction(address);
}


Apex Controller Code:



    @AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
System.debug('Test');
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity='bCity'];
}









share|improve this question
























  • can you add the component as well, please?
    – Carlos Naranjo
    Nov 24 at 21:01










  • @Carlos Original post edited with component.
    – Sumchans
    Nov 24 at 21:07










  • fyi: naming your variables the same as your attributes is never a good idea, in such a case, you might want to consider converting your attribute names to strings, ex: "bStreet" : bStreet and "bCity": bCity
    – glls
    Nov 24 at 21:31














1












1








1







I am trying to pass values from helper.js file to apex controller class. The apex controller dont seem to be getting the values. Here in this code I am passing the bStreet & bCity values.



Component:



<aura:component controller="AccountsActiveListApexController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<!--<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}" /> -->
<aura:attribute name="accounts" type="List"/>

<lightning:card>
<div class="slds-grid slds-gutters slds-p-around_medium">

<div class="slds-col slds-size_5-of-6">
<div>
<table class="slds-p-around_large bgSettings">
<tbody>
<tr >
<td>
<div class="slds-p-around_small">
<lightning:input aura:id="bStreet" placeholder="Street Name"/>
</div>
</td>
<td >
<div class="slds-p-around_small slds-p-left_xx-small">
<lightning:input aura:id="bCity" placeholder="City"/>
</div>
</td>
<td>
<div>
<button class="slds-button slds-button_brand" onclick="{!c.searchAddress}">Search</button>
</div>
</td>
<td>
<div class="slds-float_right slds-p-right_medium">
<lightning:buttonGroup>
<lightning:button label="Never" class="slds-button_neutral" value="never"/>
<lightning:button label="Cold" class="slds-button_neutral" value="cold"/>
<lightning:button label="Active" class="slds-button_neutral" value="active"/>
<lightning:button label="X" class="slds-button_neutral" value="clear"/>
</lightning:buttonGroup>
</div>
</td>
</tr>
</tbody>
</table>
<table id="oppsTable" class="slds-table slds-table_bordered slds-table_col-bordered slds-p-around_x-small">
<thead>
<tr>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Account Number">Account Number</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Name">Name</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Billing Address">Billing Address</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Status">Status</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="acc">
<tr class="slds-hint-parent">
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.AccountNumber }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.Name }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Address__c}</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Status__c }</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</div>
<div class="slds-col slds-size_1-of-6">
</div>
</div>
</lightning:card>




Helper .js:



    searchAddresses : function(component, bStreet, bCity) {  
var address = component.get("c.accountsOnAddress");
address.setParams(
{
bStreet : bStreet,
bCity : bCity
}
);
//console.log(bStreet, bCity);
address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}
});
$A.enqueueAction(address);
}


Apex Controller Code:



    @AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
System.debug('Test');
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity='bCity'];
}









share|improve this question















I am trying to pass values from helper.js file to apex controller class. The apex controller dont seem to be getting the values. Here in this code I am passing the bStreet & bCity values.



Component:



<aura:component controller="AccountsActiveListApexController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<!--<aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}" /> -->
<aura:attribute name="accounts" type="List"/>

<lightning:card>
<div class="slds-grid slds-gutters slds-p-around_medium">

<div class="slds-col slds-size_5-of-6">
<div>
<table class="slds-p-around_large bgSettings">
<tbody>
<tr >
<td>
<div class="slds-p-around_small">
<lightning:input aura:id="bStreet" placeholder="Street Name"/>
</div>
</td>
<td >
<div class="slds-p-around_small slds-p-left_xx-small">
<lightning:input aura:id="bCity" placeholder="City"/>
</div>
</td>
<td>
<div>
<button class="slds-button slds-button_brand" onclick="{!c.searchAddress}">Search</button>
</div>
</td>
<td>
<div class="slds-float_right slds-p-right_medium">
<lightning:buttonGroup>
<lightning:button label="Never" class="slds-button_neutral" value="never"/>
<lightning:button label="Cold" class="slds-button_neutral" value="cold"/>
<lightning:button label="Active" class="slds-button_neutral" value="active"/>
<lightning:button label="X" class="slds-button_neutral" value="clear"/>
</lightning:buttonGroup>
</div>
</td>
</tr>
</tbody>
</table>
<table id="oppsTable" class="slds-table slds-table_bordered slds-table_col-bordered slds-p-around_x-small">
<thead>
<tr>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Account Number">Account Number</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Name">Name</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Billing Address">Billing Address</div>
</th>
<th class="slds-text-title_caps tableColumnHeader">
<div class="slds-align_absolute-center slds-truncate" title="Status">Status</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.accounts}" var="acc">
<tr class="slds-hint-parent">
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.AccountNumber }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.Name }</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Address__c}</div>
</td>
<td>
<div class="slds-text-heading_x-small slds-align_absolute-center">{! acc.sumchans__Status__c }</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</div>
<div class="slds-col slds-size_1-of-6">
</div>
</div>
</lightning:card>




Helper .js:



    searchAddresses : function(component, bStreet, bCity) {  
var address = component.get("c.accountsOnAddress");
address.setParams(
{
bStreet : bStreet,
bCity : bCity
}
);
//console.log(bStreet, bCity);
address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}
});
$A.enqueueAction(address);
}


Apex Controller Code:



    @AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
System.debug('Test');
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity='bCity'];
}






apex lightning






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 at 22:07









Carlos Naranjo

2,61221223




2,61221223










asked Nov 24 at 20:55









Sumchans

415




415












  • can you add the component as well, please?
    – Carlos Naranjo
    Nov 24 at 21:01










  • @Carlos Original post edited with component.
    – Sumchans
    Nov 24 at 21:07










  • fyi: naming your variables the same as your attributes is never a good idea, in such a case, you might want to consider converting your attribute names to strings, ex: "bStreet" : bStreet and "bCity": bCity
    – glls
    Nov 24 at 21:31


















  • can you add the component as well, please?
    – Carlos Naranjo
    Nov 24 at 21:01










  • @Carlos Original post edited with component.
    – Sumchans
    Nov 24 at 21:07










  • fyi: naming your variables the same as your attributes is never a good idea, in such a case, you might want to consider converting your attribute names to strings, ex: "bStreet" : bStreet and "bCity": bCity
    – glls
    Nov 24 at 21:31
















can you add the component as well, please?
– Carlos Naranjo
Nov 24 at 21:01




can you add the component as well, please?
– Carlos Naranjo
Nov 24 at 21:01












@Carlos Original post edited with component.
– Sumchans
Nov 24 at 21:07




@Carlos Original post edited with component.
– Sumchans
Nov 24 at 21:07












fyi: naming your variables the same as your attributes is never a good idea, in such a case, you might want to consider converting your attribute names to strings, ex: "bStreet" : bStreet and "bCity": bCity
– glls
Nov 24 at 21:31




fyi: naming your variables the same as your attributes is never a good idea, in such a case, you might want to consider converting your attribute names to strings, ex: "bStreet" : bStreet and "bCity": bCity
– glls
Nov 24 at 21:31










2 Answers
2






active

oldest

votes


















2














Typically, you can just bind your inputs to an attribute. This makes your code easier to read. Here's one way I might do this:



<aura:attribute name="filters" type="Map" default="{ 'bCity': '', 'bStreet': '' }" />


...



<lightning:input label="Street" value="{!v.filters.bStreet}" />    


...



<lightning:input label="City" value="{!v.filters.bCity}" />


...



Which makes your search function look like this:



searchAddresses: function(component) {
var action = component.get("c.accountsOnAddress");
action.setParams(component.get("v.filters"));
action.setCallback(this, function(result) {
var state = result.getState();
if(state === "SUCCESS") {
component.set("v.accounts", component.getReturnValue());
} else {
// deal with errors here
}
});
$A.enqueueAction(action);
}




As an aside, your Apex Code is also wrong; you're searching for the literal term 'bCity', not the variable. You'll need to use variable binding:



@AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity=:bCity];
}





share|improve this answer





















  • Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
    – tsalb
    Nov 24 at 23:03








  • 1




    @tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
    – sfdcfox
    Nov 24 at 23:06












  • The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
    – tsalb
    Nov 24 at 23:09










  • Thanks sfdcfox, this really helped.
    – Sumchans
    Nov 25 at 16:48



















1














There is any particular reason why you are doing searchAddress: function(component, bStreet, bCity) ?
Change that for searchAddress: function(component, event, helper).



You probably need to get bStreet and bCity from the component before passing it to your Apex class. There are no values for those fields? You may want to set the "value" attribute. After that, you can get that value and pass it to the Apex method.



I think if you change those lines to these:



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


and



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


You will be capturing the values entered by the user.



var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("value");


Please, try this:



searchAddresses : function(component, event, helper) {  
var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("v.value");

var address = component.get("c.accountsOnAddress");
address.setParams({
bStreet : bStreet,
bCity : bCity
});


I think that the problem is that you are passing nothing to your Apex method. Try this approach and let us know if it works.



UPDATE -- setCallback



As I mentioned, you need to set the results coming from your setCallback.



 address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}


You need set the results doing something like this:



address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
component.set("v.accounts",result);
//$A.get('e.force:refreshView').fire();
}


You are getting the reponse.getReturnValue and you are assigning that to the result variable. Then I assume that you want to pass those values to your:



<aura:attribute name="accounts" type="List"/>


So that is what you should try....



In Apex you use:




system.debug();




for




console.log()







share|improve this answer























  • That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
    – Sumchans
    Nov 24 at 21:50










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    Nov 24 at 21:59











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240409%2fvalues-from-helper-js-controller-not-passed-to-apex-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Typically, you can just bind your inputs to an attribute. This makes your code easier to read. Here's one way I might do this:



<aura:attribute name="filters" type="Map" default="{ 'bCity': '', 'bStreet': '' }" />


...



<lightning:input label="Street" value="{!v.filters.bStreet}" />    


...



<lightning:input label="City" value="{!v.filters.bCity}" />


...



Which makes your search function look like this:



searchAddresses: function(component) {
var action = component.get("c.accountsOnAddress");
action.setParams(component.get("v.filters"));
action.setCallback(this, function(result) {
var state = result.getState();
if(state === "SUCCESS") {
component.set("v.accounts", component.getReturnValue());
} else {
// deal with errors here
}
});
$A.enqueueAction(action);
}




As an aside, your Apex Code is also wrong; you're searching for the literal term 'bCity', not the variable. You'll need to use variable binding:



@AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity=:bCity];
}





share|improve this answer





















  • Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
    – tsalb
    Nov 24 at 23:03








  • 1




    @tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
    – sfdcfox
    Nov 24 at 23:06












  • The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
    – tsalb
    Nov 24 at 23:09










  • Thanks sfdcfox, this really helped.
    – Sumchans
    Nov 25 at 16:48
















2














Typically, you can just bind your inputs to an attribute. This makes your code easier to read. Here's one way I might do this:



<aura:attribute name="filters" type="Map" default="{ 'bCity': '', 'bStreet': '' }" />


...



<lightning:input label="Street" value="{!v.filters.bStreet}" />    


...



<lightning:input label="City" value="{!v.filters.bCity}" />


...



Which makes your search function look like this:



searchAddresses: function(component) {
var action = component.get("c.accountsOnAddress");
action.setParams(component.get("v.filters"));
action.setCallback(this, function(result) {
var state = result.getState();
if(state === "SUCCESS") {
component.set("v.accounts", component.getReturnValue());
} else {
// deal with errors here
}
});
$A.enqueueAction(action);
}




As an aside, your Apex Code is also wrong; you're searching for the literal term 'bCity', not the variable. You'll need to use variable binding:



@AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity=:bCity];
}





share|improve this answer





















  • Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
    – tsalb
    Nov 24 at 23:03








  • 1




    @tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
    – sfdcfox
    Nov 24 at 23:06












  • The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
    – tsalb
    Nov 24 at 23:09










  • Thanks sfdcfox, this really helped.
    – Sumchans
    Nov 25 at 16:48














2












2








2






Typically, you can just bind your inputs to an attribute. This makes your code easier to read. Here's one way I might do this:



<aura:attribute name="filters" type="Map" default="{ 'bCity': '', 'bStreet': '' }" />


...



<lightning:input label="Street" value="{!v.filters.bStreet}" />    


...



<lightning:input label="City" value="{!v.filters.bCity}" />


...



Which makes your search function look like this:



searchAddresses: function(component) {
var action = component.get("c.accountsOnAddress");
action.setParams(component.get("v.filters"));
action.setCallback(this, function(result) {
var state = result.getState();
if(state === "SUCCESS") {
component.set("v.accounts", component.getReturnValue());
} else {
// deal with errors here
}
});
$A.enqueueAction(action);
}




As an aside, your Apex Code is also wrong; you're searching for the literal term 'bCity', not the variable. You'll need to use variable binding:



@AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity=:bCity];
}





share|improve this answer












Typically, you can just bind your inputs to an attribute. This makes your code easier to read. Here's one way I might do this:



<aura:attribute name="filters" type="Map" default="{ 'bCity': '', 'bStreet': '' }" />


...



<lightning:input label="Street" value="{!v.filters.bStreet}" />    


...



<lightning:input label="City" value="{!v.filters.bCity}" />


...



Which makes your search function look like this:



searchAddresses: function(component) {
var action = component.get("c.accountsOnAddress");
action.setParams(component.get("v.filters"));
action.setCallback(this, function(result) {
var state = result.getState();
if(state === "SUCCESS") {
component.set("v.accounts", component.getReturnValue());
} else {
// deal with errors here
}
});
$A.enqueueAction(action);
}




As an aside, your Apex Code is also wrong; you're searching for the literal term 'bCity', not the variable. You'll need to use variable binding:



@AuraEnabled
public static List<Account> accountsOnAddress(String bStreet, String bCity) {
return [Select AccountNumber, Name, sumchans__Address__c, sumchans__Status__c From Account Where BillingCity=:bCity];
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 at 22:55









sfdcfox

247k11188424




247k11188424












  • Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
    – tsalb
    Nov 24 at 23:03








  • 1




    @tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
    – sfdcfox
    Nov 24 at 23:06












  • The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
    – tsalb
    Nov 24 at 23:09










  • Thanks sfdcfox, this really helped.
    – Sumchans
    Nov 25 at 16:48


















  • Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
    – tsalb
    Nov 24 at 23:03








  • 1




    @tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
    – sfdcfox
    Nov 24 at 23:06












  • The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
    – tsalb
    Nov 24 at 23:09










  • Thanks sfdcfox, this really helped.
    – Sumchans
    Nov 25 at 16:48
















Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
– tsalb
Nov 24 at 23:03






Whoa! I did not know lightning automatically converts a clientside map attribute into it's appropriate serverside parameter mapping without explicitly setting them... But this makes perfect sense once I saw it. I would venture this works if you pass an object in (directly) and let the properties be the apex params?
– tsalb
Nov 24 at 23:03






1




1




@tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
– sfdcfox
Nov 24 at 23:06






@tsalb Yes, that also works as well. The framework just expects an object that has key-value pairs, it doesn't really matter how you get there. I just think this format happens to be a bit easier to read.
– sfdcfox
Nov 24 at 23:06














The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
– tsalb
Nov 24 at 23:09




The other day I had trouble finding a good place to "declare" what keys are possible on my objects so I will be borrowing this....thank you very much ;)
– tsalb
Nov 24 at 23:09












Thanks sfdcfox, this really helped.
– Sumchans
Nov 25 at 16:48




Thanks sfdcfox, this really helped.
– Sumchans
Nov 25 at 16:48













1














There is any particular reason why you are doing searchAddress: function(component, bStreet, bCity) ?
Change that for searchAddress: function(component, event, helper).



You probably need to get bStreet and bCity from the component before passing it to your Apex class. There are no values for those fields? You may want to set the "value" attribute. After that, you can get that value and pass it to the Apex method.



I think if you change those lines to these:



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


and



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


You will be capturing the values entered by the user.



var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("value");


Please, try this:



searchAddresses : function(component, event, helper) {  
var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("v.value");

var address = component.get("c.accountsOnAddress");
address.setParams({
bStreet : bStreet,
bCity : bCity
});


I think that the problem is that you are passing nothing to your Apex method. Try this approach and let us know if it works.



UPDATE -- setCallback



As I mentioned, you need to set the results coming from your setCallback.



 address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}


You need set the results doing something like this:



address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
component.set("v.accounts",result);
//$A.get('e.force:refreshView').fire();
}


You are getting the reponse.getReturnValue and you are assigning that to the result variable. Then I assume that you want to pass those values to your:



<aura:attribute name="accounts" type="List"/>


So that is what you should try....



In Apex you use:




system.debug();




for




console.log()







share|improve this answer























  • That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
    – Sumchans
    Nov 24 at 21:50










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    Nov 24 at 21:59
















1














There is any particular reason why you are doing searchAddress: function(component, bStreet, bCity) ?
Change that for searchAddress: function(component, event, helper).



You probably need to get bStreet and bCity from the component before passing it to your Apex class. There are no values for those fields? You may want to set the "value" attribute. After that, you can get that value and pass it to the Apex method.



I think if you change those lines to these:



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


and



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


You will be capturing the values entered by the user.



var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("value");


Please, try this:



searchAddresses : function(component, event, helper) {  
var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("v.value");

var address = component.get("c.accountsOnAddress");
address.setParams({
bStreet : bStreet,
bCity : bCity
});


I think that the problem is that you are passing nothing to your Apex method. Try this approach and let us know if it works.



UPDATE -- setCallback



As I mentioned, you need to set the results coming from your setCallback.



 address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}


You need set the results doing something like this:



address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
component.set("v.accounts",result);
//$A.get('e.force:refreshView').fire();
}


You are getting the reponse.getReturnValue and you are assigning that to the result variable. Then I assume that you want to pass those values to your:



<aura:attribute name="accounts" type="List"/>


So that is what you should try....



In Apex you use:




system.debug();




for




console.log()







share|improve this answer























  • That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
    – Sumchans
    Nov 24 at 21:50










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    Nov 24 at 21:59














1












1








1






There is any particular reason why you are doing searchAddress: function(component, bStreet, bCity) ?
Change that for searchAddress: function(component, event, helper).



You probably need to get bStreet and bCity from the component before passing it to your Apex class. There are no values for those fields? You may want to set the "value" attribute. After that, you can get that value and pass it to the Apex method.



I think if you change those lines to these:



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


and



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


You will be capturing the values entered by the user.



var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("value");


Please, try this:



searchAddresses : function(component, event, helper) {  
var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("v.value");

var address = component.get("c.accountsOnAddress");
address.setParams({
bStreet : bStreet,
bCity : bCity
});


I think that the problem is that you are passing nothing to your Apex method. Try this approach and let us know if it works.



UPDATE -- setCallback



As I mentioned, you need to set the results coming from your setCallback.



 address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}


You need set the results doing something like this:



address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
component.set("v.accounts",result);
//$A.get('e.force:refreshView').fire();
}


You are getting the reponse.getReturnValue and you are assigning that to the result variable. Then I assume that you want to pass those values to your:



<aura:attribute name="accounts" type="List"/>


So that is what you should try....



In Apex you use:




system.debug();




for




console.log()







share|improve this answer














There is any particular reason why you are doing searchAddress: function(component, bStreet, bCity) ?
Change that for searchAddress: function(component, event, helper).



You probably need to get bStreet and bCity from the component before passing it to your Apex class. There are no values for those fields? You may want to set the "value" attribute. After that, you can get that value and pass it to the Apex method.



I think if you change those lines to these:



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


and



<lightning:input aura:id="bStreet" placeholder="Street Name" value=""/>


You will be capturing the values entered by the user.



var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("value");


Please, try this:



searchAddresses : function(component, event, helper) {  
var bStreet = component.find("v.bStreet").get("v.value");
var bCity = component.find("v.bCity").get("v.value");

var address = component.get("c.accountsOnAddress");
address.setParams({
bStreet : bStreet,
bCity : bCity
});


I think that the problem is that you are passing nothing to your Apex method. Try this approach and let us know if it works.



UPDATE -- setCallback



As I mentioned, you need to set the results coming from your setCallback.



 address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
//$A.get('e.force:refreshView').fire();
}


You need set the results doing something like this:



address.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var result = response.getReturnValue();
console.log(result);
component.set("v.accounts",result);
//$A.get('e.force:refreshView').fire();
}


You are getting the reponse.getReturnValue and you are assigning that to the result variable. Then I assume that you want to pass those values to your:



<aura:attribute name="accounts" type="List"/>


So that is what you should try....



In Apex you use:




system.debug();




for




console.log()








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 at 22:09

























answered Nov 24 at 21:12









Carlos Naranjo

2,61221223




2,61221223












  • That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
    – Sumchans
    Nov 24 at 21:50










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    Nov 24 at 21:59


















  • That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
    – Sumchans
    Nov 24 at 21:50










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    Nov 24 at 21:59
















That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
– Sumchans
Nov 24 at 21:50




That is the exactly the way I have it now, the only thing is I added the value attribute to the lightning:input component. It still doesn't work. How do I do the console.log in the apex controller class?
– Sumchans
Nov 24 at 21:50












In your setCallback, there is no logic to set back to the component the results coming from that callback.
– Carlos Naranjo
Nov 24 at 21:59




In your setCallback, there is no logic to set back to the component the results coming from that callback.
– Carlos Naranjo
Nov 24 at 21:59


















draft saved

draft discarded




















































Thanks for contributing an answer to Salesforce Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240409%2fvalues-from-helper-js-controller-not-passed-to-apex-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...