You need to sign in to do that
Don't have an account?
ab d
query is not returning userorgroup.name data
Public Class DynamicController {
@AuraEnabled
Public static List<Sobject> getDynamicValues (String recId , string SobjctNme){
// String recorId = recId ;
String SobjectShrNme = SobjctNme ;
wraperShreLst wrperShrLst = new wraperShreLst ();
String theQuery ;
// Public List<String> accessibleFields = getFieldsList(SobjctNme) ;
if(!SobjectShrNme.endsWith('__c')){
SobjectShrNme += 'Share' ; // adding Share to standard object
String sObjId = SobjctNme + 'Id' ; // creating string for sobject id for retrive thier associated share records.
System.debug('@@@@@@@@@'+sObjId);
theQuery = 'SELECT ' + joinList(getFieldsList(SobjectShrNme) , ', ') +
' FROM ' +SobjectShrNme+
' WHERE ' + sObjId + '=\''+recId+'\'';
System.debug('the query is :'+theQuery);
wrperShrLst.shrlst = Database.query(theQuery) ;
String UsrNme = 'UserorGroup.Name' ; // adding userorgroupName field for feteching name of userorgroup shared list.
String thequery1 = 'SELECT '+UsrNme+ ' FROM ' +SobjectShrNme+' WHERE ' + sObjId + '=\''+recId+'\'' ;
system.debug('//////////'+thequery1);
wrperShrLst.usrGrpLst = Database.query(thequery1);
system.debug('++++++++++'+wrperShrLst);
system.debug('@@@@@@@@@@@'+Database.query(theQuery)); // lines added to check
}
else { // code for getting custom object share records.
SobjectShrNme = SobjectShrNme.removeEnd('__c') +'__Share' ; // adding Share to Custom object
String sObjId = 'Parent' + 'Id' ; // creating string for sobject id as parent id for retrive thier associated share records.
System.debug('@@@@@@@@@'+sObjId);
theQuery = 'SELECT ' + joinList(getFieldsList(SobjectShrNme) , ', ') +
' FROM ' +SobjectShrNme+
' WHERE ' + sObjId + '=\''+recId+'\'';
List < Sobject > sObjList = Database.query(theQuery) ;
system.debug('@@@@@@@@@@@'+sObjList); // lines added to check
}
return(Database.query(theQuery));
}
Private static List<String> getFieldsList(String SobjectName){ // Feteching the Fields From Associated Objects.
sObject obj = Schema.getGlobalDescribe().get(SobjectName).newSObject(); // converting String to Sobject.
Map<String, Schema.SobjectField> fields = obj.getSObjectType().getDescribe().fields.getMap();
List<String > accessibleFields = new List<String>() ; // List of accessibleFields.
for (String s : fields.keySet()) {
if ( (fields.get(s).getDescribe().isAccessible())) {
if(s.containsIgnoreCase('Id')|| s.containsIgnoreCase('user') || s.containsIgnoreCase('Level') ){ // fields are filter here.
accessibleFields.add(s);
}
}
}
System.debug('+++++++++++++'+accessibleFields);
String UsrNme = 'UserorGroup.Name' ; // adding userorgroupName field for feteching name of userorgroup shared list.
accessibleFields.add(UsrNme);
return accessibleFields ;
}
// Join an Apex List of fields into a SELECT fields list string
private static String joinList(List<String> theList, String separator) {
if (theList == null) { return null; }
if (separator == null) { separator = ''; }
String joined = '';
Boolean firstItem = true;
for (String item : theList) {
if(null != item) {
if(firstItem){ firstItem = false; }
else { joined += separator; }
joined += item;
}
}
return joined;
}
Public class wraperShreLst {
@AuraEnabled Public List<Sobject> shrlst {get ;set ;}
@AuraEnabled Public List<sobject> usrGrpLst {get ;set;}
}
}
in the above highlighted area query is not returning userorGroupName from associates shared object ,
Please Help me to resolve ...
@AuraEnabled
Public static List<Sobject> getDynamicValues (String recId , string SobjctNme){
// String recorId = recId ;
String SobjectShrNme = SobjctNme ;
wraperShreLst wrperShrLst = new wraperShreLst ();
String theQuery ;
// Public List<String> accessibleFields = getFieldsList(SobjctNme) ;
if(!SobjectShrNme.endsWith('__c')){
SobjectShrNme += 'Share' ; // adding Share to standard object
String sObjId = SobjctNme + 'Id' ; // creating string for sobject id for retrive thier associated share records.
System.debug('@@@@@@@@@'+sObjId);
theQuery = 'SELECT ' + joinList(getFieldsList(SobjectShrNme) , ', ') +
' FROM ' +SobjectShrNme+
' WHERE ' + sObjId + '=\''+recId+'\'';
System.debug('the query is :'+theQuery);
wrperShrLst.shrlst = Database.query(theQuery) ;
String UsrNme = 'UserorGroup.Name' ; // adding userorgroupName field for feteching name of userorgroup shared list.
String thequery1 = 'SELECT '+UsrNme+ ' FROM ' +SobjectShrNme+' WHERE ' + sObjId + '=\''+recId+'\'' ;
system.debug('//////////'+thequery1);
wrperShrLst.usrGrpLst = Database.query(thequery1);
system.debug('++++++++++'+wrperShrLst);
system.debug('@@@@@@@@@@@'+Database.query(theQuery)); // lines added to check
}
else { // code for getting custom object share records.
SobjectShrNme = SobjectShrNme.removeEnd('__c') +'__Share' ; // adding Share to Custom object
String sObjId = 'Parent' + 'Id' ; // creating string for sobject id as parent id for retrive thier associated share records.
System.debug('@@@@@@@@@'+sObjId);
theQuery = 'SELECT ' + joinList(getFieldsList(SobjectShrNme) , ', ') +
' FROM ' +SobjectShrNme+
' WHERE ' + sObjId + '=\''+recId+'\'';
List < Sobject > sObjList = Database.query(theQuery) ;
system.debug('@@@@@@@@@@@'+sObjList); // lines added to check
}
return(Database.query(theQuery));
}
Private static List<String> getFieldsList(String SobjectName){ // Feteching the Fields From Associated Objects.
sObject obj = Schema.getGlobalDescribe().get(SobjectName).newSObject(); // converting String to Sobject.
Map<String, Schema.SobjectField> fields = obj.getSObjectType().getDescribe().fields.getMap();
List<String > accessibleFields = new List<String>() ; // List of accessibleFields.
for (String s : fields.keySet()) {
if ( (fields.get(s).getDescribe().isAccessible())) {
if(s.containsIgnoreCase('Id')|| s.containsIgnoreCase('user') || s.containsIgnoreCase('Level') ){ // fields are filter here.
accessibleFields.add(s);
}
}
}
System.debug('+++++++++++++'+accessibleFields);
String UsrNme = 'UserorGroup.Name' ; // adding userorgroupName field for feteching name of userorgroup shared list.
accessibleFields.add(UsrNme);
return accessibleFields ;
}
// Join an Apex List of fields into a SELECT fields list string
private static String joinList(List<String> theList, String separator) {
if (theList == null) { return null; }
if (separator == null) { separator = ''; }
String joined = '';
Boolean firstItem = true;
for (String item : theList) {
if(null != item) {
if(firstItem){ firstItem = false; }
else { joined += separator; }
joined += item;
}
}
return joined;
}
Public class wraperShreLst {
@AuraEnabled Public List<Sobject> shrlst {get ;set ;}
@AuraEnabled Public List<sobject> usrGrpLst {get ;set;}
}
}
in the above highlighted area query is not returning userorGroupName from associates shared object ,
Please Help me to resolve ...