1

i have the following object:

public class myType {
   public String name {get; set;}
   public String fields {get; set;}
   public Integer page {get; set;}
   public Integer pageSize { get; set; }
}

I am trying to receive this as a parameter from an aura enabled function:

@AuraEnabled
public static object getCount(myType listParams){
    String query = 'SELECT count(ID) FROM ' + listParams.objectName;
    System.debug(listParams);
    System.debug(query);
    return Database.query(query);
}

running like this from the lwc component:

connectedCallback(){
    var params = {
        objectName: this.sObject,
        fields: this.fields,
        page: this.page,
        pageSize: this.pageSize
    }
    console.log(params)
    getCount({ listParams: params }).then(countResult => {
       console.log(countResult)
    })
}

But all the apex get on developer console are null values. error

If i change the type to object on the controller i get Map<Any,Any>. What i am doing wrong here? This does work with SObject types as i have tried it before.

1 Answer 1

2

To get the value, you must use @AuraEnabled as well as using the default getter/setter ({ get; set; }):

public class myType {
   @AuraEnabled public String name {get; set;}
   @AuraEnabled public String fields {get; set;}
   @AuraEnabled public Integer page {get; set;}
   @AuraEnabled public Integer pageSize { get; set; }
}

An example is provided in the documentation.

public class SimpleAccount {
    
    @AuraEnabled public String Id { get; set; }
    @AuraEnabled public String Name { get; set; }
    public String Phone { get; set; }
    
    // Trivial constructor, for server-side Apex -> client-side JavaScript
    public SimpleAccount(String id, String name, String phone) {
        this.Id = id;
        this.Name = name;
        this.Phone = phone;
    }
    
    // Default, no-arg constructor, for client-side -> server-side
    public SimpleAccount() {}
    
}

When returned from a remote Apex controller action, the Id and Name properties are defined on the client-side. However, because it doesn’t have the @AuraEnabled annotation, the Phone property isn’t serialized on the server side, and isn’t returned as part of the result data.

You must log in to answer this question.

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