Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with Apex exception in Salesforce

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will show you how to deal with Apex exceptions in Salesforce. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

One. Apex language

Apex is a proprietary language developed by Salesforce.com. By official definition, Apex is a strongly typed, object-oriented programming language that allows developers to execute traffic and transaction control statements on Force.com platform servers while calling Force.com API. It has a syntax similar to Java and like a database stored procedure. It enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. You can start the proxy code through triggers on Web service requests and objects. Apex is included in Performance Edition,Unlimited Edition,Enterprise Edition and Developer Edition.

1. Language features

1) Integration

Apex built-in support for DML operations, such as INSERT,UPDATE,DELETE and DML exception handling. It supports inline SOQL and SOSL query processing and returns a set of sObject records.

2) Java syntax is easy to use

Apex is easy to use because it uses syntax like Java. For example, variable declarations, loop syntax, and conditional statements.

3) High data integration

Apex dataset and design to execute multiple queries and DML statements together. It issues multiple database transaction statements.

4) strong type

Apex is a strongly typed language. It uses a direct reference architecture object, such as sObject, and any invalid reference will fail quickly if it is deleted or if it is the wrong data type.

5) Multi-tenant environment

Apex runs in a multi-tenant environment. Therefore, the Apex runtime engine is designed to closely guard against runaway code and prevent it from monopolizing shared resources. Any code that violates the limit fails and displays an easy-to-understand error message.

6) automatic upgrade

Apex is upgraded as part of the Salesforce version and does not have to be upgraded manually.

7) easy to test

Apex provides built-in support for unit test creation and execution, including test results that indicate how much code is covered and which parts of the code can be more efficient.

two。 Exception handling

Because Apex has a syntax similar to Java, we usually use keywords such as try, catch, finally, throw and so on for exception handling. For each try code snippet, there must be at least one catch or finally code snippet, while there can be at most one finally code snippet. Finally code snippet is bound to be executed, regardless of whether an exception occurs or not, these are the same as those in Java.

Standard format:

Try {/ / can also set a SavePoint for a transaction. When an exception occurs, you can roll back to the SavePoint Savepoint sp = Database.setSavepoint (); / / perform the operation, which may cause an exception. Place it in try to wrap} catch (exception type e) {/ / catch related types of exceptions / / rollback to a SavePoint Database.rollback (sp) } catch (Exception e) {/ / e.getMessage () get exception information} other actions that finally {/ / will (need) perform anyway

Three. Common exception types

The system-defined exception types are:

DmlException: exceptions about database operations

ListException: exceptions about list operations

NullPointerException: exceptions about null pointers

QueryException: about the exception of query statement

SObjectException: about exceptions to the SObject object

The common methods include:

GetCause (): give the cause of the exception

GetLineNumber (): gives the number of rows in which an exception occurred

GetMessage (): give details of the exception

GetStackTraceString (): gives stack information of exception occurrence

GetTypeName (): gives the type of exception, such as DmlException, NullPointerException, etc.

For each exception type, there is also its own method. For example, DmlException has getDmlFieldNames (), getDmlMessage (), and so on.

If you want to catch different exception types, put the "general exception type" (the largest exception type in Exception) at the end.

These are all the contents of how to handle Apex exceptions in Salesforce. For more information about how to handle Apex exceptions in Salesforce, you can search the previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report