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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
1
down vote

favorite












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
    6 hours ago










  • @Carlos Original post edited with component.
    – Sumchans
    6 hours ago










  • 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
    5 hours ago

















up vote
1
down vote

favorite












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
    6 hours ago










  • @Carlos Original post edited with component.
    – Sumchans
    6 hours ago










  • 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
    5 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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 5 hours ago









Carlos Naranjo

2,14021123




2,14021123










asked 6 hours ago









Sumchans

133




133












  • can you add the component as well, please?
    – Carlos Naranjo
    6 hours ago










  • @Carlos Original post edited with component.
    – Sumchans
    6 hours ago










  • 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
    5 hours ago


















  • can you add the component as well, please?
    – Carlos Naranjo
    6 hours ago










  • @Carlos Original post edited with component.
    – Sumchans
    6 hours ago










  • 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
    5 hours ago
















can you add the component as well, please?
– Carlos Naranjo
6 hours ago




can you add the component as well, please?
– Carlos Naranjo
6 hours ago












@Carlos Original post edited with component.
– Sumchans
6 hours ago




@Carlos Original post edited with component.
– Sumchans
6 hours ago












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
5 hours ago




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
5 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













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
    4 hours ago








  • 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
    4 hours ago












  • 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
    4 hours ago


















up vote
0
down vote













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
    5 hours ago










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    5 hours ago











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',
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








up vote
2
down vote













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
    4 hours ago








  • 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
    4 hours ago












  • 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
    4 hours ago















up vote
2
down vote













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
    4 hours ago








  • 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
    4 hours ago












  • 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
    4 hours ago













up vote
2
down vote










up vote
2
down vote









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 4 hours ago









sfdcfox

240k10182403




240k10182403












  • 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
    4 hours ago








  • 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
    4 hours ago












  • 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
    4 hours ago


















  • 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
    4 hours ago








  • 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
    4 hours ago












  • 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
    4 hours ago
















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
4 hours ago






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
4 hours ago






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
4 hours ago






@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
4 hours ago














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
4 hours ago




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
4 hours ago












up vote
0
down vote













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
    5 hours ago










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    5 hours ago















up vote
0
down vote













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
    5 hours ago










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    5 hours ago













up vote
0
down vote










up vote
0
down vote









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 5 hours ago

























answered 6 hours ago









Carlos Naranjo

2,14021123




2,14021123












  • 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
    5 hours ago










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    5 hours ago


















  • 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
    5 hours ago










  • In your setCallback, there is no logic to set back to the component the results coming from that callback.
    – Carlos Naranjo
    5 hours ago
















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
5 hours ago




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
5 hours ago












In your setCallback, there is no logic to set back to the component the results coming from that callback.
– Carlos Naranjo
5 hours ago




In your setCallback, there is no logic to set back to the component the results coming from that callback.
– Carlos Naranjo
5 hours ago


















 

draft saved


draft discarded



















































 


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

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)