3

Can I use attribute type of aura component apex class? For example:

<aura:attribute name="approvals" type="ApprovalData[]" />

Where ApprovalData class:

public class ApprovalData {

    public String targetObjectId {get;set;}
    public String name {get;set;}
    public String reuqestId {get;set;}

}

In helper.js I receive array with objects, but these objects are empty.

My helper.js:

({
    getApprovals : function(cmp) {
        var action = cmp.get("c.approvals");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(cmp.isValid() && state === 'SUCCESS') {
                var approvals = response.getReturnValue();
                console.debug('approvals = ', approvals, ', size = ', approvals.length);
                cmp.set('v.approvals', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }
})

And apex controller:

@AuraEnabled
    public static List<ApprovalData> approvals() {
        List<ProcessInstanceWorkItem> processInstanceWorkItems = [SELECT CreatedById, ProcessInstance.TargetObjectId, ProcessInstance.ProcessDefinitionId 
            FROM ProcessInstanceWorkItem];
        Set<String> userIds = new Set<String>();
        for(ProcessInstanceWorkItem item:processInstanceWorkItems) {
            userIds.add(item.CreatedById);
        }
        Map<Id, User> users = new Map<Id,User>([SELECT id, Name FROM User WHERE id IN :userIds]);
        System.debug('users = ' + users);
        List<ApprovalData> approvals = new List<ApprovalData>();
        for(ProcessInstanceWorkItem item:processInstanceWorkItems) {
            ApprovalData approve = new ApprovalData();
            approve.targetObjectId = item.ProcessInstance.TargetObjectId;
            approve.name = users.get(item.CreatedById).Name;
            approve.reuqestId = item.ProcessInstance.ProcessDefinitionId;
            approvals.add(approve);
        }
        System.debug('approvals = ' + approvals);
        return approvals;
    }
2
  • can you post you helper.js code ? Commented Dec 7, 2016 at 9:50
  • Added helper.js and apex controller
    – JKasyan
    Commented Dec 7, 2016 at 9:57

1 Answer 1

8

Add @AuraEnabled annotation to class properties eg:

public class ApprovalData {
    @auraEnabled
    public String targetObjectId {get;set;}
    @auraEnabled
    public String name {get;set;}
    @auraEnabled
    public String reuqestId {get;set;}
}
1
  • If this worked for you please mark it as an answer
    – Amjad khan
    Commented Dec 7, 2016 at 11:15

You must log in to answer this question.

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