You need to sign in to do that
Don't have an account?
inbox outbox 7
This is a controller LWC code and I have trouble with the return type when the query has a sub query. Please help
What I am trying to achieve is to ensure CRUD and FLS using Security class method stripInaccessible()/ DescribeFieldResult. Also after doing that I am updating the fields which are inaccessbile to user with NULL.
I have trouble when it is a relationship query.
Basically what I am trying to understand is how can we return in this scenario when you have query on a MAP
SECURITY.STRIPINACCESSIBLE
I have trouble when it is a relationship query.
Basically what I am trying to understand is how can we return in this scenario when you have query on a MAP
SECURITY.STRIPINACCESSIBLE
public with sharing class practController { @AuraEnabled(cacheable = true) public static List<Temple__c> getRecordsMethod(){ try { SObjectAccessDecision securityDecision = Security.stripInaccessible(AccessType.Readable, [SELECT Name, (SELECT Name, OwnerId, Type__c FROM ChildObjects__r ) FROM Temple__c ]); Map<String, Boolean> childMap = New Map<String, Boolean>(); List<ChildObject__c> childObjectList = securityDecision.getRecords(); Set<String> removedFilds = securityDecision.getRemovedFields().get('ChildObject__c'); for(ChildObject__c child: childObjectList ){ for(String fieldName: removedFilds){ childMap.put(fieldName, NULL); } } return $$$$$$$$$$$ return securityDecision.getRecords(); ?????? }catch (Exception e) { throw new AuraHandledException('The error code is' + e.getMessage() + ', the line is' + e.getLineNumber() + ', error type is ' + e.getTypeName() + '& the stackTraceString is' + e.getStackTraceString() + '.'); } } }DESCRIBEFIELDRESULT CLASS METHODS:
public with sharing class practController { @AuraEnabled(cacheable = true) public static List<Temple__c> getRecordsMethod(){ try { Map<String, ChildObject__c> childMap = New Map<String, ChildObject__c>([SELECT Name, (SELECT Name, OwnerId, Type__c FROM ChildObjects__r ) FROM Temple__c ]); Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.ChildObject__c.fields.getMap(); Map<String, Boolean> fieldToAccessibility = New Map<String, Boolean>(); For(ChildObject__c child: childMap.values()){ Set<String> populatedFields = child.getPopulatedFieldsAsMap().keySet(); for(String fieldName: populatedFields){ Boolean isAccessible = fieldToAccessibility.get(fieldName); if(isAccessible == NULL){ isAccessible = fieldMap.get(fieldName).getDescribe().isAccessible(); fieldToAccessibility.put(fieldName, isAccessible); } if(!isAccessible){ fieldToAccessibility.put(fieldName, NULL); } } } } return ???????? }catch (Exception e) { throw new AuraHandledException('The error code is' + e.getMessage() + ', the line is' + e.getLineNumber() + ', error type is ' + e.getTypeName() + '& the stackTraceString is' + e.getStackTraceString() + '.'); } } }