You need to sign in to do that
Don't have an account?
AMRITA P Panda
How to use the list from apex class in the helper?
Apex class:-
@AuraEnabled
public static List < sObject > fetchLookUpValues(String searchKeyWord, String ObjectName, List<sObject> ExcludeitemsList, String UserId)
{
try{
List <Group > Careagentgroup;
List <Group > noncareagentgroup;
String searchKey = '' + searchKeyWord + '%';
List <String> lstOfGroupIds = new List <String> ();
List <Group> lstOfQueue;
List <GroupMember> lstOfSubGroupId;
Set<id> idGroup = new Set<id>();
lstOfSubGroupId = [SELECT GroupId from GroupMember WHERE UserOrGroupId=: UserId LIMIT 500];
if(lstOfSubGroupId.size()>0){
for(GroupMember gm : lstOfSubGroupId){
idGroup.add(gm.GroupId);
}
}
lstOfQueue = [SELECT Id from Group WHERE Id IN (Select Groupid from GroupMember where userOrGroupId in : idGroup) LIMIT 500];
if(lstOfQueue.size()>0){
for(Group q : lstOfQueue){
lstOfGroupIds.add(q.Id);
}
}
List<string> lstExcludeitems = new List<string>();
for(sObject item : ExcludeitemsList ){
lstExcludeitems.add(item.id);
}
Careagentgroup=[select name from group where name like'care%' AND Name LIKE: searchKey AND Id NOT IN : lstExcludeitems AND Id NOT IN : lstOfGroupIds];
noncareagentgroup=[select name from group where Name LIKE: searchKey AND (NOT name LIKE 'care%') AND Id NOT IN : lstExcludeitems AND Id NOT IN : lstOfGroupIds];
list<user> u=[select id,name,profile.name from user where id=:UserId];
List <sObject> returnList = new List <sObject> ();
if(u[0].profile.name=='Service Care Agent'){
for (sObject obj: Careagentgroup) {
returnList.add(obj);
}
}
else{
for (sObject obj: noncareagentgroup) {
returnList.add(obj);
}
}
return returnList;
}
catch(Exception e){
System.debug('The following exception has occurred: ' + e.getMessage());
return null;
}
}
helper :-
({
searchHelper : function(component,event,getInputkeyWord,UserId) {
var action = component.get("c.fetchLookUpValues");
action.setParams({
'searchKeyWord': getInputkeyWord,
'ObjectName' : component.get("v.objectAPIName"),
'ExcludeitemsList' : component.get("v.lstSelectedRecords"),
'UserId' : UserId
});
//String searchKeyWord, String ObjectName, List<sObject> ExcludeitemsList, List<Group> lstofgrp
action.setCallback(this, function(response) {
$A.util.removeClass(component.find("mySpinner"), "slds-show");
var state = response.getState();
console.log("state" + state);
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
//console.log("storeResponse-----" +storeResponse[0].Name );
if (storeResponse.length == 0) {
component.set("v.Message", 'No records found');
}
else {
component.set("v.Message", '');
}
component.set("v.listOfSearchRecords", storeResponse);
}
});
$A.enqueueAction(action);
},
})
Question is :- I want to take the values present in the "returnlist" from apex class and compare it in the helper and based on the comparision will print the message as " not authorized".
@AuraEnabled
public static List < sObject > fetchLookUpValues(String searchKeyWord, String ObjectName, List<sObject> ExcludeitemsList, String UserId)
{
try{
List <Group > Careagentgroup;
List <Group > noncareagentgroup;
String searchKey = '' + searchKeyWord + '%';
List <String> lstOfGroupIds = new List <String> ();
List <Group> lstOfQueue;
List <GroupMember> lstOfSubGroupId;
Set<id> idGroup = new Set<id>();
lstOfSubGroupId = [SELECT GroupId from GroupMember WHERE UserOrGroupId=: UserId LIMIT 500];
if(lstOfSubGroupId.size()>0){
for(GroupMember gm : lstOfSubGroupId){
idGroup.add(gm.GroupId);
}
}
lstOfQueue = [SELECT Id from Group WHERE Id IN (Select Groupid from GroupMember where userOrGroupId in : idGroup) LIMIT 500];
if(lstOfQueue.size()>0){
for(Group q : lstOfQueue){
lstOfGroupIds.add(q.Id);
}
}
List<string> lstExcludeitems = new List<string>();
for(sObject item : ExcludeitemsList ){
lstExcludeitems.add(item.id);
}
Careagentgroup=[select name from group where name like'care%' AND Name LIKE: searchKey AND Id NOT IN : lstExcludeitems AND Id NOT IN : lstOfGroupIds];
noncareagentgroup=[select name from group where Name LIKE: searchKey AND (NOT name LIKE 'care%') AND Id NOT IN : lstExcludeitems AND Id NOT IN : lstOfGroupIds];
list<user> u=[select id,name,profile.name from user where id=:UserId];
List <sObject> returnList = new List <sObject> ();
if(u[0].profile.name=='Service Care Agent'){
for (sObject obj: Careagentgroup) {
returnList.add(obj);
}
}
else{
for (sObject obj: noncareagentgroup) {
returnList.add(obj);
}
}
return returnList;
}
catch(Exception e){
System.debug('The following exception has occurred: ' + e.getMessage());
return null;
}
}
helper :-
({
searchHelper : function(component,event,getInputkeyWord,UserId) {
var action = component.get("c.fetchLookUpValues");
action.setParams({
'searchKeyWord': getInputkeyWord,
'ObjectName' : component.get("v.objectAPIName"),
'ExcludeitemsList' : component.get("v.lstSelectedRecords"),
'UserId' : UserId
});
//String searchKeyWord, String ObjectName, List<sObject> ExcludeitemsList, List<Group> lstofgrp
action.setCallback(this, function(response) {
$A.util.removeClass(component.find("mySpinner"), "slds-show");
var state = response.getState();
console.log("state" + state);
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
//console.log("storeResponse-----" +storeResponse[0].Name );
if (storeResponse.length == 0) {
component.set("v.Message", 'No records found');
}
else {
component.set("v.Message", '');
}
component.set("v.listOfSearchRecords", storeResponse);
}
});
$A.enqueueAction(action);
},
})
Question is :- I want to take the values present in the "returnlist" from apex class and compare it in the helper and based on the comparision will print the message as " not authorized".
You can refer below code:
I have gone through your problem.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora