Pass list attribute from lightning component to apex controller
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I have an attribute
in lightning component:
<aura:attribute name="pricingRecommendationListDetailsData" access="PUBLIC" type="list" default="object" />
Data stored in it visible as:
accRecmId: "a07e000", category: "test", Price: 56, PriceRange: â¦, cost: 0.3, â¦
Now I need to pass this attribute as parameter to apex controller on button click.And I need to iterate over values such as accRecmId
in apex class
lightning-components
add a comment |Â
up vote
1
down vote
favorite
I have an attribute
in lightning component:
<aura:attribute name="pricingRecommendationListDetailsData" access="PUBLIC" type="list" default="object" />
Data stored in it visible as:
accRecmId: "a07e000", category: "test", Price: 56, PriceRange: â¦, cost: 0.3, â¦
Now I need to pass this attribute as parameter to apex controller on button click.And I need to iterate over values such as accRecmId
in apex class
lightning-components
You would simply pass it using the method param name and the component.get of the attribute
â Eric
Aug 8 at 7:12
But how will I iterate over the list<string> and grabaccRecmId
from each instance?
â devforce
Aug 8 at 7:13
More of a map isnâÂÂt it?
â Eric
Aug 8 at 7:15
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have an attribute
in lightning component:
<aura:attribute name="pricingRecommendationListDetailsData" access="PUBLIC" type="list" default="object" />
Data stored in it visible as:
accRecmId: "a07e000", category: "test", Price: 56, PriceRange: â¦, cost: 0.3, â¦
Now I need to pass this attribute as parameter to apex controller on button click.And I need to iterate over values such as accRecmId
in apex class
lightning-components
I have an attribute
in lightning component:
<aura:attribute name="pricingRecommendationListDetailsData" access="PUBLIC" type="list" default="object" />
Data stored in it visible as:
accRecmId: "a07e000", category: "test", Price: 56, PriceRange: â¦, cost: 0.3, â¦
Now I need to pass this attribute as parameter to apex controller on button click.And I need to iterate over values such as accRecmId
in apex class
lightning-components
lightning-components
asked Aug 8 at 6:55
devforce
10710
10710
You would simply pass it using the method param name and the component.get of the attribute
â Eric
Aug 8 at 7:12
But how will I iterate over the list<string> and grabaccRecmId
from each instance?
â devforce
Aug 8 at 7:13
More of a map isnâÂÂt it?
â Eric
Aug 8 at 7:15
add a comment |Â
You would simply pass it using the method param name and the component.get of the attribute
â Eric
Aug 8 at 7:12
But how will I iterate over the list<string> and grabaccRecmId
from each instance?
â devforce
Aug 8 at 7:13
More of a map isnâÂÂt it?
â Eric
Aug 8 at 7:15
You would simply pass it using the method param name and the component.get of the attribute
â Eric
Aug 8 at 7:12
You would simply pass it using the method param name and the component.get of the attribute
â Eric
Aug 8 at 7:12
But how will I iterate over the list<string> and grab
accRecmId
from each instance?â devforce
Aug 8 at 7:13
But how will I iterate over the list<string> and grab
accRecmId
from each instance?â devforce
Aug 8 at 7:13
More of a map isnâÂÂt it?
â Eric
Aug 8 at 7:15
More of a map isnâÂÂt it?
â Eric
Aug 8 at 7:15
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
you have two option:
- Send only the accRecmId to your Server method like this:
JS Controller:
var selectedList = component.get('v.pricingRecommendationListDetailsData');
var ids=new Array();
for (var i= 0 ; i < selectedList.length ; i++)
ids.push(selectedList[i].accRecmId);
var idListJSON=JSON.stringify(ids);
var action = component.get("c.callServier");
action.setParams(
"accRecmId":idListJSON
);
Apex Controller:
public static void callServier(String accRecmId)
Type idArrType = Type.forName('List<string>');
List<string> wrapperList = (List<string>) JSON.deserialize(accRecmId, idArrType);
- Pass all attribute to your apex controller and inside your apex controller get the accRecmId.
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than afor(...)
loop in modern JS.
â sfdcfox
Aug 8 at 10:10
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
add a comment |Â
up vote
1
down vote
My recommendation is to prepare the required data on the client and send only the list of ids you have to work within the server:
MyComponentController.js
// get the list of pricing details
var pricingDetails = component.get('v.pricingRecommendationListDetailsData');
// map through the list to create a list of acc rec ids
var accRecmIds = pricingDetails.map(function (detail)
return detail.accRecmId;
);
// get the server call action
var action = component.get("c.iterateOverAccRecmIds");
// set the list of acc rec ids as a parameter
action.setParams(
"accRecmIds":accRecmIds
);
MyComponentController.cls
public with sharing class MyComponentController
@AuraEnabled
public static void iterateOverAccRecmIds(List<String> accRecmIds)
// do what you want with the list of ids...
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
you have two option:
- Send only the accRecmId to your Server method like this:
JS Controller:
var selectedList = component.get('v.pricingRecommendationListDetailsData');
var ids=new Array();
for (var i= 0 ; i < selectedList.length ; i++)
ids.push(selectedList[i].accRecmId);
var idListJSON=JSON.stringify(ids);
var action = component.get("c.callServier");
action.setParams(
"accRecmId":idListJSON
);
Apex Controller:
public static void callServier(String accRecmId)
Type idArrType = Type.forName('List<string>');
List<string> wrapperList = (List<string>) JSON.deserialize(accRecmId, idArrType);
- Pass all attribute to your apex controller and inside your apex controller get the accRecmId.
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than afor(...)
loop in modern JS.
â sfdcfox
Aug 8 at 10:10
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
add a comment |Â
up vote
4
down vote
accepted
you have two option:
- Send only the accRecmId to your Server method like this:
JS Controller:
var selectedList = component.get('v.pricingRecommendationListDetailsData');
var ids=new Array();
for (var i= 0 ; i < selectedList.length ; i++)
ids.push(selectedList[i].accRecmId);
var idListJSON=JSON.stringify(ids);
var action = component.get("c.callServier");
action.setParams(
"accRecmId":idListJSON
);
Apex Controller:
public static void callServier(String accRecmId)
Type idArrType = Type.forName('List<string>');
List<string> wrapperList = (List<string>) JSON.deserialize(accRecmId, idArrType);
- Pass all attribute to your apex controller and inside your apex controller get the accRecmId.
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than afor(...)
loop in modern JS.
â sfdcfox
Aug 8 at 10:10
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
you have two option:
- Send only the accRecmId to your Server method like this:
JS Controller:
var selectedList = component.get('v.pricingRecommendationListDetailsData');
var ids=new Array();
for (var i= 0 ; i < selectedList.length ; i++)
ids.push(selectedList[i].accRecmId);
var idListJSON=JSON.stringify(ids);
var action = component.get("c.callServier");
action.setParams(
"accRecmId":idListJSON
);
Apex Controller:
public static void callServier(String accRecmId)
Type idArrType = Type.forName('List<string>');
List<string> wrapperList = (List<string>) JSON.deserialize(accRecmId, idArrType);
- Pass all attribute to your apex controller and inside your apex controller get the accRecmId.
you have two option:
- Send only the accRecmId to your Server method like this:
JS Controller:
var selectedList = component.get('v.pricingRecommendationListDetailsData');
var ids=new Array();
for (var i= 0 ; i < selectedList.length ; i++)
ids.push(selectedList[i].accRecmId);
var idListJSON=JSON.stringify(ids);
var action = component.get("c.callServier");
action.setParams(
"accRecmId":idListJSON
);
Apex Controller:
public static void callServier(String accRecmId)
Type idArrType = Type.forName('List<string>');
List<string> wrapperList = (List<string>) JSON.deserialize(accRecmId, idArrType);
- Pass all attribute to your apex controller and inside your apex controller get the accRecmId.
answered Aug 8 at 7:17
salesforce Developer
1,20621329
1,20621329
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than afor(...)
loop in modern JS.
â sfdcfox
Aug 8 at 10:10
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
add a comment |Â
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than afor(...)
loop in modern JS.
â sfdcfox
Aug 8 at 10:10
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than a for(...)
loop in modern JS.â sfdcfox
Aug 8 at 10:10
var ids = selectedList.map(value => value.accRecmId);
There's usually a shorter way than a for(...)
loop in modern JS.â sfdcfox
Aug 8 at 10:10
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
Why not just pass the map to the apex method and do the work needed there? Provide much more flexibility to extend the functionality later on....Maybe I am missing something.
â Eric
Aug 8 at 16:14
add a comment |Â
up vote
1
down vote
My recommendation is to prepare the required data on the client and send only the list of ids you have to work within the server:
MyComponentController.js
// get the list of pricing details
var pricingDetails = component.get('v.pricingRecommendationListDetailsData');
// map through the list to create a list of acc rec ids
var accRecmIds = pricingDetails.map(function (detail)
return detail.accRecmId;
);
// get the server call action
var action = component.get("c.iterateOverAccRecmIds");
// set the list of acc rec ids as a parameter
action.setParams(
"accRecmIds":accRecmIds
);
MyComponentController.cls
public with sharing class MyComponentController
@AuraEnabled
public static void iterateOverAccRecmIds(List<String> accRecmIds)
// do what you want with the list of ids...
add a comment |Â
up vote
1
down vote
My recommendation is to prepare the required data on the client and send only the list of ids you have to work within the server:
MyComponentController.js
// get the list of pricing details
var pricingDetails = component.get('v.pricingRecommendationListDetailsData');
// map through the list to create a list of acc rec ids
var accRecmIds = pricingDetails.map(function (detail)
return detail.accRecmId;
);
// get the server call action
var action = component.get("c.iterateOverAccRecmIds");
// set the list of acc rec ids as a parameter
action.setParams(
"accRecmIds":accRecmIds
);
MyComponentController.cls
public with sharing class MyComponentController
@AuraEnabled
public static void iterateOverAccRecmIds(List<String> accRecmIds)
// do what you want with the list of ids...
add a comment |Â
up vote
1
down vote
up vote
1
down vote
My recommendation is to prepare the required data on the client and send only the list of ids you have to work within the server:
MyComponentController.js
// get the list of pricing details
var pricingDetails = component.get('v.pricingRecommendationListDetailsData');
// map through the list to create a list of acc rec ids
var accRecmIds = pricingDetails.map(function (detail)
return detail.accRecmId;
);
// get the server call action
var action = component.get("c.iterateOverAccRecmIds");
// set the list of acc rec ids as a parameter
action.setParams(
"accRecmIds":accRecmIds
);
MyComponentController.cls
public with sharing class MyComponentController
@AuraEnabled
public static void iterateOverAccRecmIds(List<String> accRecmIds)
// do what you want with the list of ids...
My recommendation is to prepare the required data on the client and send only the list of ids you have to work within the server:
MyComponentController.js
// get the list of pricing details
var pricingDetails = component.get('v.pricingRecommendationListDetailsData');
// map through the list to create a list of acc rec ids
var accRecmIds = pricingDetails.map(function (detail)
return detail.accRecmId;
);
// get the server call action
var action = component.get("c.iterateOverAccRecmIds");
// set the list of acc rec ids as a parameter
action.setParams(
"accRecmIds":accRecmIds
);
MyComponentController.cls
public with sharing class MyComponentController
@AuraEnabled
public static void iterateOverAccRecmIds(List<String> accRecmIds)
// do what you want with the list of ids...
edited Aug 8 at 10:10
![](https://i.stack.imgur.com/Qvgta.png?s=32&g=1)
![](https://i.stack.imgur.com/Qvgta.png?s=32&g=1)
sfdcfox
229k10177391
229k10177391
answered Aug 8 at 9:02
![](https://lh4.googleusercontent.com/-sqSosQbtmtY/AAAAAAAAAAI/AAAAAAAAABA/4wWgN9WLJMM/photo.jpg?sz=32)
![](https://lh4.googleusercontent.com/-sqSosQbtmtY/AAAAAAAAAAI/AAAAAAAAABA/4wWgN9WLJMM/photo.jpg?sz=32)
Ruslan Kurchenko
16018
16018
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f228109%2fpass-list-attribute-from-lightning-component-to-apex-controller%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You would simply pass it using the method param name and the component.get of the attribute
â Eric
Aug 8 at 7:12
But how will I iterate over the list<string> and grab
accRecmId
from each instance?â devforce
Aug 8 at 7:13
More of a map isnâÂÂt it?
â Eric
Aug 8 at 7:15