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;
    }
  • can you post you helper.js code ? – Sagar Thoriya Dec 7 '16 at 9:50
  • Added helper.js and apex controller – JKasyan Dec 7 '16 at 9:57
7

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;}
}
  • If this worked for you please mark it as an answer – Amjad khan Dec 7 '16 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.