Posts

Apex - Enforcing Sharing Rules

Image
First thing first- How can we enforce sharing rules in Apex class? Apex generally runs in system context; that is, the current user's permissions and field-level security aren’t taken into account during code execution. Sharing rules, however, are not always bypassed: the class must be declared with the without sharing keyword in order to ensure that sharing rules are not enforced. Use with sharing keyword to enforce sharing rules of the current user(Doesn't includes the user's permissions and field-level security). Some important notes✍- 1) Enforcing sharing rules by using the with sharing keyword doesn’t enforce the user's permissions and field-level security. This again, pertains to only respecting OWDs and Sharing Rules. 2) If a class is declared as "with sharing" then, the sharing settings apply to all code contained in the class, including initialization code, constructors and methods. However, Inner Classes DO NOT inherit sharing settings from the co...

Salesforce - Performance analysis of Apex

Image
   It was Diwali festival last weekend and a long weekend for me. During this break, I thought to write a blog on how we can analyse the performance of various Apex properties(Apex Methods, Queries, Workflow, Callouts, DML, validations, Triggers and Pages).  In your personal or work projects, you may come across the situation where apex code (mostly APIs callout) take time to execute which results in a delay, and eventually a bad user experience👎. Performance analysis is helpful in determining which Apex property is taking much time to load or execute, and accordingly you can make the application more efficient, and eventually improve the customer's interaction with application. There are many ways of analysing the Apex logs. Some people use VS Code extensions like 'Apex Log Analyzer'. But, I prefer to analyse directly in Developer Console. To keep the blog short and comprehensible, I'll create an  LWC application  and call the server side  Apex methods...