Posts

Showing posts from May, 2020

Batch Apex

                  What is Batch Apex?      Batch Apex is asynchronous execution of Apex code, specially designed for processing the     large number of records and has greater flexibility in governor limits than the synchronous code.    It allows you to define a job that can be divided into manageable chunks, where each chunk can be processed separately. For example, if you want to make a field update of all records in any object which is having more number of records, then governor limits restricts us to process that operation. Because in a single transaction we can only process 10,000 records. In batch apex, it will fetch all records which you want to perform the field update and divide them into a list of 200 records & every 200 records operation is performed separately.     when to use Batch Apex? When you want to process large number of records on daily basis or even on specific time of interval then you can go for Batch Apex. Also, when you want an operation to be asynchronou

With Sharing Keyword and Without Sharing Keyword

    System mode - System mode is nothing but running apex code by ignoring user's permissions. For example, logged in user does not have create permission but he/she is able to create a record.  Means eventhough user does not have necessary profile level permission, record level permission or field level permission, but still they can perform any operation on it. In system mode, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren't applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user. In Salesforce, all apex code run in system mode. It ignores user's permissions. Only exception is anonymous blocks like developer console and standard controllers. Even runAs() method doesn't enforce user permissions or field-level permissions, it only enforces record sharing. User mode -  User mode is nothing but running apex code by respecting user's permissi