Professional Documents
Culture Documents
Salesforce Question
Salesforce Question
Salesforce Question
Batch Apex in Salesforce is designed to efficiently handle large data sets while respecting the
platform's governor limits. Key limits include: Total number of records retrieved by SOQL
queries: 50 million records. Maximum batch size: Default is 200 records per batch, but can be
set up to 2,000
When working with SOQL, you'll most likely be using it within Apex, which has a few more
restrictions around how you can use SOQL: Maximum 100 queries in a synchronous
transaction. Maximum 200 queries in an asynchronous transaction. Maximum 50000 rows
returned per transaction.
Batch Apex jobs are limited to five tasks running simultaneously, whereas queueable jobs can
run up to 100!
The maximum number of asynchronous Apex method executions (batch Apex, future methods,
Queueable Apex, and scheduled Apex) per a 24-hour period is 250,000 or the number of user
licenses in your organization multiplied by 200, whichever is greater.
A maximum of five batch jobs can be submitted in case of a running test. There can be up to
250,000 Batch Apex method executions per day or the number of user licenses in an
organization multiplied by 200 — whichever is greater.
: Yes, we can call another batch class from the Finish method.
How do I query more than 50000 records in Salesforce?
You can get more than 50,000 using a Query Locator. Use Salesforce workbench to query such
records. Workbench uses the salesforce rest/tooling API that doesn't have 50K record limitation.
It might happen that it will fail for 4-5 times due to huge amount of data but it would work.
Salesforce enforces an Apex Heap Size Limit of 6MB for synchronous transactions and 12MB
for asynchronous transactions. The "Apex heap size too large" error occurs when too much data
is being stored in memory during processing.
Batch Apex Limits
Batch Apex in Salesforce is designed to efficiently handle large data sets
while respecting the platform’s governor limits. Key limits include:
It’s crucial to design Batch Apex classes considering these limits to ensure
efficient and error-free execution.
Use Cases
Below are a few use cases of Batch Apex:
1. Scheduled Processing: Batch Apex can be used to schedule periodic
tasks, such as sending out emails or cleaning up records that are no longer
needed.
2. Parallel Processing: Batch Apex can be used to execute multiple
operations in parallel and make better use of system resources.
3. Automation: Batch Apex can be used to automate processes in
Salesforce, such as creating new records or deleting old ones.
4. Complex Operations: Batch Apex can be used to perform complex
operations that cannot be done through the standard Salesforce interface,
such as generating complex reports or integrating data from multiple
sources.
1. start(): Gathers the initial record set for processing, returning a query
locator or iterable defining the record scope.
2. execute(): Processes records in batches (up to 200 at a time), where data
processing logic is implemented.
3. finish(): Executes after all batches are processed, used for cleanup or
post-processing tasks.
1. Manual Abortion: Go to Setup > Jobs > Apex Jobs, select the job, and
click the “Abort” button.
2. Programmatic Stop: Use Apex to invoke
the Database.BatchableContext method stop() within the execute() method.
3. Automatic Timeout: Salesforce will automatically abort the job if it runs for
an extended period without completion.
SOQL SOSL
Syntax of Trigger
Before update: Executes the trigger before a record is updated
Before insert: Executes the trigger before a record is inserted
Before delete: Executes the trigger before a record is deleted
After delete: Executes the trigger after a record is deleted
After insert: Executes the trigger after a record is inserted
After update: Executes the trigger after a record is updated
After undelete: Executes the trigger to recover a deleted record from
recycle bin
https://salesforcegeek.in/salesforce-apex-trigger-examples-part-1/
Synchronous Process
In simple words we can say executing a class based on single thread that is nothing but
execute one method at a time either using top down or bottom to top approach.
Example: Imagine you have a requirement like when you insert a contact or delete a
contact update the account with number of contacts and then you need to perform web
service callout for that account. Using the synchronous apex is no-no situation because
we always need to deal with the governor limits and apex CPU time. So how can we
solve this situation.
Asynchronous process
The answer is yes, asynchronous process will execute in its own thread it is
independent. So how many asynchronous flavors we have in salesforce?
Do not worry we have that in Salesforce. It is nothing but @future annotation how cool
it is right. Now we are ready to deep dive into learn about the future asynchronous
process.
FUTURE APEX QUEUEABLE APEX
It is a class which implements’ queueable
It is annotation based so we can use the same apex class to
interface. Syntax: public class CLASS_NAME
write the future method. Syntax: @future
implements Queueable{}
We cannot monitor the jobs We can monitor the jobs based on the job Id.
Batch apex allows you to define a job that can be divided into manageable chunks,
where each chunk can be proceed separately. In batch apex, it will fetch all records
which you want perform the field update and divide them into list of 200 records and
every 200 records operation is performed separately.
What is the difference between data loader and apex data loader?
Basically Apex data loader is a desktop tool and it is meant for data migration between
two systems. In other words, when you want to move data between SFDC and some
other environment, you go with data loader.
Step 2: Override the old record values with the new values.
Step 5: Save the record but do not commit the record to the database.
Step 10: If there are workflow field updates then execute the field update.
Step 11: If the record was updated with a workflow field update then execute before and after
triggers created on the object in the context again but only once.
Step 14: Update the roll-up summary fields & cross-object formula fields.
Step 15: Repeat the same process with the affected parent or grand-parent records.
Use validation rules to maintain user input data or system modified records.
User input data: Where users may be prone to making mistakes or cutting corners, or when you need data to be in a certain format.
System modified records: Changes to data triggered by imports, automated processes, integrated systems, etc. will need to abide by validation
rules*.
Master-Detail Lookup
Child and Parent exist
independently (field is
Child cannot exist without Parent (field is required not required and can be
and can’t be null or blank) null or blank)
Child and Parent
security settings are set
Child inherits security settings from Parent independently
Cascade delete (deleting Parent deletes all Child Deletion of Parent does
records) not delete Child records
No rollup summary
(appexchange tools
Rollup summary (i.e. count, sum, min, max) available)
Standard objects can be
Standard objects cannot be the child of custom the child of custom
objects objects
Up to 40 lookups on a
custom object (child can
have up to 40 parents)
Can have up to two master-details on an object (child and 25 lookups on a
can have up to two parents) standard object
Salesforce Junction Objects give you a way to create a many-to-many relationship between
Salesforce objects. They are created using a custom object to relate two other objects via two
master-detail relationships. This is necessary when modeling certain data schemas. Let’s dive
into a couple of examples:
https://dev.to/shivamkapasia0/decorators-in-
lightning-web-componentlwc-3379
There are three type of Decorators in Lightning web components.
1. Api
2. Track
3. Wire
4. @api: It is used to expose a variable or functions publically and
make properties reactive.
5. @track: It is used to make variable private but reactive. Tracked
properties are also called private reactive properties.
6. @wire: To read Salesforce data, Lightning web components use
a reactive wire service. When the wire service provisions data, the
component rerenders. Components use @wire in their JavaScript
class to specify a wire adaptor or an Apex method.
@api
To expose a public property or a public method, decorate with @api. Public properties
are reactive, also known as public reactive properties since if a value of property
changes then component is re-rendered
Public properties define API of a component whereas public methods are part of a
component’s API
A Component is re-rendered when the value of a referenced public property is modified
or changed
To pass data from parent component to child component, @api decorator in the child
component exposes a property by making it public so that parent component can
update it
@api properties can be exposed in an App builder
@track
To expose a private property or a private method, declare with @track. Also known as
Private reactive properties
To track a private property and to re-render component when that property changes,
use @track decorator (Available only for the component where it is declared)
Fields which are using @track decorator that contains an object or an array, tells the
framework to observe changes to the properties of an object or elements of an array
After Salesforce Spring ’20, all the fields in a Lightning Web Component are reactive. If a
field is used in a template & value changes, the component re-renders and displays a
new value by default
. @wire
Reactive wire service is utilized in Lightning Web Components to read the Salesforce
data from apex class into Lightning web components
Component is re-rendered when wire service provisions the data from apex class. The
output from apex method is set to a property.