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

Sample Analysis in Salesforce

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, I will talk to you about the example analysis in Salesforce. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Friends who have come into contact with Salesforce should know that although Salesforce has always advocated code-free development and tried to use standard functions to achieve requirements, sometimes we still inevitably have to write some code.

Using standard features, Salesforce will be responsible for the quality of the code.

For some custom features, Salesforce has also developed its own set of metrics to ensure that our code will not be interrupted under any circumstances in production, such as:

Salesforce programs must have 75% code coverage before they can be deployed.

General Apex Code, like the code that appears in Trigger and Controller.

Test classes are easy to write, just follow

1. Prepare test data

two。 Execute business logic (function)

3. Assert the result of execution

Just follow the routine.

(warm reminder: every time you finish writing the program, remember to test it in the test class. If there are any missing points, it will be more difficult the next time you change the program and test again, so for the convenience of others and for your own convenience, the test class will be modified in time.)

Xiao Meow remembers changing the test class once, and found that there were several versions between the test class and the program, so she could only take the time to test the ┭┮ testing ┭┮ step by step.

So for convenience, I still hope that friends will modify the program and modify the test class to the latest version in time.

In addition, some other apex code require special measurements. As a CRM system, Salesforce inevitably has to exchange data with other systems. In most cases, we only need to provide the standard integration documents of salesforce and accounts with configured permissions to each other, but when we need to package the business, we need to build our own WebService.

Here's a brief answer to some of the main points of writing test classes:

1. You must start the class with the @ isTest annotation, and only Salesforce will treat this class as a test class.

two。 Keep the test class private. The best practice is to name the test class primitive class or trigger name + 'test',. For example, the program is CampaignController-> the test class is CampaignControllerTest

3. The methods of the test class must be static, void, and must use the testMethod keyword. For example:

Static testMethod void method name () {/ / method body}

4. Prepare the test data that needs to exist before the actual test runs. There are many techniques for creating test data every day, such as setup methods, static resources, and so on.

5. Use Test.startTest () and Test.stopTest () to ensure that the actual testing of the code takes place with a new set of governor restrictions. These methods help you reset the governor limits before the actual test code executes.

6. Once the test code is in Test.startTest () and Test.stopTest (), you must use assert statements to test whether the actual code executes correctly and give results as expected. For example, we are testing whether the price of this book is set at $90. If this assert statement returns false, your test class will fail and will let you know that there is something incorrect in the code, and you need to fix the original code.

7. Ideally, we should write multiple methods in the test class, few methods should test our positive cases, and other methods should test our negative test cases.

The function of 8.@TestVisible is to access private variables of a class, such as when some inner classes or private variables need to be accessed or given values

9. Friends can verify whether the expected result of the variable is consistent with the actual result by System.assertEquals () OR Sysetm.assert () OR System.assertNotEquals () in the test method. If it is not true, it will prompt the failure and explain the reason.

Example:

System.AssertException: Assertion Failed: Expected: 1, Actual: 0max / expectation is 1, actually it is 0

10. You can simulate different user operations through runAs

After reading the above, do you have any further understanding of the example analysis in Salesforce? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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