/
DYNAMIC APEX COMPONENTS DYNAMIC APEX DYNAMIC APEX COMPONENTS DYNAMIC APEX

DYNAMIC APEX COMPONENTS DYNAMIC APEX - PowerPoint Presentation

della
della . @della
Follow
67 views
Uploaded On 2023-07-07

DYNAMIC APEX COMPONENTS DYNAMIC APEX - PPT Presentation

Dynamic Apex Enables you to create more flexible applications by providing you the ability to access sObject and field metadata descriptions Allows you to write dynamic SOQL and SOSL queries and dynamic DML ID: 1006600

method dynamic sosl soql dynamic method soql sosl batch apex schema objects execute database records string data passed describe

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "DYNAMIC APEX COMPONENTS DYNAMIC APEX" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. DYNAMIC APEX COMPONENTS

2. DYNAMIC APEX

3. Dynamic ApexEnables you to create more flexible applications by providing you the ability to access sObject and field metadata descriptions.Allows you to write dynamic SOQL and SOSL queries and dynamic DML.Consists of several components such as schema describe, dynamic SOQL, dynamic SOSL, and dynamic DML.

4. Schema DescribeSchema describe is a way to programmatically learn about the metadata of your data model within Apex.Schema describe provide the ability to programmatically discover information about the current org schema, such as a list of top-level objects, including custom objects, and their fields.You can also use schema describe to create a tree structure of all the objects and fields in your schema browser. To do this, you use the code: Map<String, Schema.SObjectType> sobj = Schema.getGlobalDescribe(); This returns a map of all sObject names or keys to sObject tokens or values for the standard and custom objects defined in an organization.

5. Dynamic SOQLDynamic SOQL refers to the creation of a SOQL string at runtime within Apex. You use dynamic SOQL to query data without hardcoding names for fields and objects in the SOQL statement.Dynamic SOQL makes an application more flexible by allowing SOQL creation at runtime. The example that query a single record and a list of records are shown here. There are times when a user is required to enter some values into SOQL. In this case, the users may enter values that may lead to SOQL injection. SOQL injection is a technique by which a user causes the application to execute database methods that you , as a developer, did not intend to execute, by passing SOQL statements into the scrip you have written. This can occur in an Apex scrip whenever the application relied on end-user inputs to construct a dynamic SOQL statement and, as a developer, you do not handle the input properly.To preven SOQL injection, use the “escapeSingleQuotes” method. This method adds the escape character (\) to all single quotation marks in a string that is passed by a user. The method ensures that all single quotation marks are treated as enclosing strings instead of database commands.

6. Dynamic SOSLDynamic SOSL refers to the creation of a SOSL statement at runtime. You use dynamic SOSL to search for data without hard coding the names of fields and objects in the SOSL statement.Dynamic SOSL makes an application more flexible by allowing SOSL creation at runtime. An example of using SOSL query is shown hereList<List, <sObject>> myquery = search.query(SOSL_Search_Str);In dynamic SOSL, you use “String.escapeSingleQuote” s(string) to prevent SOSL injection.

7. Dynamic DMLDynamic DML provides the ability to perform DML operations on sObjects dynamically.

8. Schema Describe Result Objects

9. Generate a list of map of tokens for the sObjects

10. Batch ApexBatch Apex is the feature of Salesforce that you can use for asynchronous batch processing. This feature allows you to create batch items that can be processed asynchronously due to large data volumes or complex processes. This feature enables customers, developers, and Independent Software Vendors (ISVs) to build and deploy complex business processes, operate over entire data sets, and leverage the power and flexibility of Salesforce.com’s asynchronous platform.

11. Batch Apex cont..

12. Methods available in the database.batchable interfaceThe database.batchable interface contains three methods that must be implemented for all batch jobs: start, execute, and finish. All of these methods require a reference to a database.batchableconext object to keep track of the context of the batch job.  The database.batchablecontext method getJobId returns the Id of the asynchronous Apex job object associated with this batch job as a string.

13. Start()The start method is called at the beginning of a batch Apex job. You use the start method to collect records or objects to be passed to the execute method. This method returns either a Database.getQueryLocator object or an iterable that contains the records or objects being passed into the job.

14. execute()The execute method is called for each batch item of records passed to the method. You use this method to perform all required processing for each chunk of data. Each execution of a batch item is considered a discrete transaction, and the Apex governor limits are reset.The execute method takes an optional scope parameter, which can be used to limit the number of records to be passed in each batch item to lower than the 200 records default

15. finish()The finish method is called after all batches are processed. You use this method to send confirmation emails or execute post-processing operations.