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;
}