- In apex anonymous block - the code runs in the user mode, i.e. With Sharing context. - Limitation of With Security_Enforced - it does not filter the results in where clause and it throws only the 1st error. Hence, apex always recommends With User_Mode.
The WITH SECURITY_ENFORCED clause in Apex has some limitations, including: Polymorphic lookup fields: This clause doesn't support traversing a polymorphic field's relationship in queries. Insufficient permissions: If a field is hidden, the query will throw an exception. DML operations: This clause can't be used in DML operations.
1.Anonymous block code by default executes in user Mode 2. Limitations of With Security Enforced - -Applied security check only to fields and objects referenced in SELECT or FROM clauses(No WHERE clause) -Finds only First Error (Not all) 3. Yes we can assign the permission set using apex .
1.anonymous Block will be running as USER_MODE 2.WITH SECURITY_ENFORCED clause Enable If there are any fields or objects referenced in the SELECT clause that are inaccessible to the user, an exception is thrown and no data is returned. 3.Yes , PermissionSetAssignment prset = new PermissionSetAssignment (PermissionSetId = myPermissionSetId, AssigneeId = myAssigneeId); insert prset;
If an inherited sharing class is the entry point and no explicit sharing context is defined, it will not default to with sharing. Instead, it will behave similarly to without sharing because there is no calling class to inherit the context from. Scenario 1: If MyEntryClass is called from another class, it will inherit the sharing context of the caller (either with sharing or without sharing). Scenario 2: If MyEntryClass is invoked directly, e.g., from a button click or a Visualforce page, there’s no sharing context to inherit, so it behaves as without sharing. If you want the class to enforce sharing rules by default when it is the entry point, you should explicitly declare it as with sharing instead of relying on inherited sharing. inherited sharing does not default to with sharing when the class is the entry point of the transaction. If you need sharing rules to be enforced by default, you should explicitly use with sharing.
Nice video with interview related stuff👌👍. Pls continue this series 😊 Also explain these apex concepts and batch apex, security , triggers in detail through boot camps 😊
Yes, using PermissionSetAssignment object, we can assign the permission set to user via apex
code written in anonymous block will be running in user mode as you explained at the start, which is respecting sharing context
- In apex anonymous block - the code runs in the user mode, i.e. With Sharing context.
- Limitation of With Security_Enforced - it does not filter the results in where clause and it throws only the 1st error. Hence, apex always recommends With User_Mode.
The WITH SECURITY_ENFORCED clause in Apex has some limitations, including:
Polymorphic lookup fields: This clause doesn't support traversing a polymorphic field's relationship in queries.
Insufficient permissions: If a field is hidden, the query will throw an exception.
DML operations: This clause can't be used in DML operations.
Yes, anonymous blocks in Salesforce can be executed in User Mode.
Yes permissionset can be assigned as shown below:
PermissionSetAssignment psa = new PermissionSetAssignment
(PermissionSetId = myPermissionSetId, AssigneeId = myAssigneeId);
insert psa;
1.Anonymous block code by default executes in user Mode
2. Limitations of With Security Enforced -
-Applied security check only to fields and objects referenced in SELECT or FROM clauses(No WHERE clause)
-Finds only First Error (Not all)
3. Yes we can assign the permission set using apex .
All are correct Diksha
1.anonymous Block will be running as USER_MODE
2.WITH SECURITY_ENFORCED clause Enable If there are any fields or objects referenced in the SELECT clause that are inaccessible to the user, an exception is thrown and no data is returned.
3.Yes , PermissionSetAssignment prset = new PermissionSetAssignment
(PermissionSetId = myPermissionSetId, AssigneeId = myAssigneeId);
insert prset;
If an inherited sharing class is the entry point and no explicit sharing context is defined, it will not default to with sharing. Instead, it will behave similarly to without sharing because there is no calling class to inherit the context from.
Scenario 1: If MyEntryClass is called from another class, it will inherit the sharing context of the caller (either with sharing or without sharing).
Scenario 2: If MyEntryClass is invoked directly, e.g., from a button click or a Visualforce page, there’s no sharing context to inherit, so it behaves as without sharing.
If you want the class to enforce sharing rules by default when it is the entry point, you should explicitly declare it as with sharing instead of relying on inherited sharing.
inherited sharing does not default to with sharing when the class is the entry point of the transaction.
If you need sharing rules to be enforced by default, you should explicitly use with sharing.
Correct my friend
Nice video with interview related stuff👌👍. Pls continue this series 😊
Also explain these apex concepts and batch apex, security , triggers in detail through boot camps 😊
Sure keep following !!
With System_Mode - For running apex in system mode
Ankit You are good, please make a list on the apex trigger and Aura also
Sure will plan for it
sir what is difference between a inhertied sharing calss and class with no sharing declaration(i.e a normal class)
I cover that question in playlist
Sir can you please make one Play list of apex like LWC please sir we request you
already have you can check on channel
@@harmeetsandhu8238 no for Apex there is no any playlist. Please check
Yes will plan for it
@@TechJourneyWithAnkit sir please do it as soon as possible. I Request you
Part 3 ?
Will be on this Sunday !!
in herited sharing little got confused
Checkout this link - developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm