1- I am using fflib for my managed package.
2- By default CRUD/FLS are enabled for all domain/selector flows (Using Base class)
3- In a specific method which is used by site guest users, I want to bypass CRUD/FLS check.
4- "Configuration.disableTriggerCRUDSecurity();" is not working in a domain specific method.
5- I know same is possible in Selector layer (See Accepted Answer) . I want same thing in domain layer.
How to By pass CRUD/FLS from Domain layer in any specific Flow?
Sample Code which should work but it is not working
public inherited sharing abstract class BaseDomain extends fflib_SObjectDomain {
public BaseDomain(List<SObject> records) {
super(records);
Configuration.enforceTriggerCRUDSecurity();
}
}
public inherited sharing class ABCs extends BaseDomain implements IABCs{
public ABCs(List<ABC__c> abcs) {
super(abcs);
}
..........................
public list<Boolean> incrementViewCount(fflib_ISObjectUnitOfWork uow){
Configuration.disableTriggerCRUDSecurity();
//Business Logic
for(SObject urlObj:Records){
ABC__c abc = (ABC__c)urlObj;
Double viewCount = 0;
if(abc.TotalView__c != null){
dataDumpViewCount = abc.TotalView__c;
}
abc.TotalView__c = dataDumpViewCount +1;
uow.registerDirty(abc);
}
}
}
public with sharing class ABCServiceImpl implements IABCServiceService{
public void createViewCountByGuestUser(list<ID> abcIds){
new ElevatedViewStatus().saveViewStatus(abcIds);
}
private without sharing class ElevatedViewStatus{
public ViewStatusBO saveViewStatus(list<ID> abcIds){
fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
.........................
IABCs abcsDomain = (IABCs) Application.Domain.newInstance(abcIds);
abcsDomain.incrementViewCount(uow);
........................
}
}
}
fflib_SObjectDomain
, you'll see thatConfiguration.EnforcingTriggerCRUDSecurity
applies only tohandleAfterInsert/Update/Delete/Undelete
. Your domain methodincrementViewCount
is not associated with trigger events.fflib
is a red herring here - you need to think about why a Flow executed by a guest user can't update the custom objectABC__c
and when committed, will execute the domain onAfterUpdate and bypass the isUpdateable check. Is your flow defined to run in System Context rather than the default User Context?