Skip to main content

Posts

Showing posts with the label benchmark

Field Level Security in Apex: WITH SECURITY_ENFORCED vs. Security.stripInaccessible

Every time your users access Lightning (web) component or Visualforce page the background Apex code is being run in user context. What does it mean? If there's with sharing keyword on your class definition or you are inheriting with sharing from another class, sharing rules are enforced. In other words SOQL query will return only records, that are visible for current user. And that's great, this is one security concern less. However object level security and field level security permissions are not respected , therefore results of database queries will contain fields, that current user doesn't have access to. There are 3 different ways, how to ensure your user will not see, what he's not supposed to see. WITH SECURITY_ENFORCED clause on SOQL queries Security class and its method stripInaccessible DescribeFieldResult class and its method isAccessible Let's inspect them one by one. Let's get our playground ready First, we need to get our laboratory rea

Apex switch statement under the microscope

It is almost 18 months since Salesforce finally introduced one of the most eagerly anticipated features for Apex - switch statement . Does it even make sense to comment it today? I can only guess it was because of general familiarity with the switch statement , good documentation or simply happiness over surprising birth of a son you stopped dreaming about years ago, but no one has ever questioned it ! Why do we love switch statements ? We've had switch statements in other programming languages since the dawn of time and if not, it was definitely long before I was born. Therefore reasons to use switch statements over if and if else statements are also clear and kind of indisputable. It is preferable to use switch , if you can agree with following statements in your programming language and of course specific situation you are in: Code is easier to read and therefore it is easier to understand and maintain Code is easier to debug Code is faster to execute

About author

My photo
Jan Binder
Experienced Salesforce Technical Architect and Team Lead with a proven track record of delivering successful enterprise projects for major global companies across diverse industries, including automotive, oil & gas, and construction.