I am new to the lightning component. I want to get two lists in the js controller how it's possible?

 public class ContactListController {

public  static List<Contact> getContactlist(){
        List<integer> listTwo=new list<integer>();
        List<Contact> listOne= new  List<Contact>([select id, FirstName,LastName,email,Phone from Contact]);
       return listOne;


Js controller

    doInit : function(component, event, helper) {
        var action= component.get('c.getContactlist');
            var responseValue = response.getReturnValue();

Now Question is how can we get two lists in js controller. the getContactlist return only one list. I want to return many things from the same method like integer , string, boolean etc

1 Answer 1


This example is not especially realistic, but the general solution remains the same: define a custom type that wraps all of the data you're interested in transferring, and return an instance of that class:

public class MyDTO {
    public List<Contact> contacts { get; set; }
    public List<Integer> ints { get; set; }
    // ...

See the Aura Developer Guide for more information and details on shipping data back and forth between Aura and Apex.

  • so how can I get these two lists in the js controller?
    – user91246
    Jun 15, 2021 at 18:14
  • David has linked the resources to get you started, if you are expecting someone to provide you a complete code sample, note that this is not the purpose of this site.
    – glls
    Jun 15, 2021 at 18:19
  • 1
    Your getReturnValue() result has a shape as a JavaScript object that matches your Apex class shape.
    – David Reed
    Jun 15, 2021 at 18:24
  • like that `` component.set('v.contactlist',responseValue.contactlsit);`` and `` component.set('v.intlist',responseValue.ints);`` ?
    – user91246
    Jun 15, 2021 at 18:26
  • 1
    @fawad, if you are new to lwc and/or aura, I would strongly suggest you follow the corresponding trailhead modules.
    – glls
    Jun 15, 2021 at 18:44

You must log in to answer this question.