New answers tagged unit-test
0
votes
Accepted
HttpCalloutMock is not working. Methods defined as TestMethod do not support Web service callouts
As pointed out by user254875486, the mockout class was not being called because, the rest method was executed by the trigger action due to the insert operation done on the TestSetup method, instead of ...
1
vote
Accepted
Can I mock out lookup relationship using FFLIB ApexMocks
In response to your comment about not being able to use SObjectFabricator, you can deserialize a string into an object with these fields/relationships set.
This is pretty crude, but it works. Use it ...
- 2,823
0
votes
MileStoneUtils apex class requires code coverage. Stops at 57%
The if statement is testing if Case Milestones were found for the case Id(s) and Milestone Types passed to the completeMilestone method. If it is not being covered, that means no such milestones were ...
- 11.4k
2
votes
Accepted
Testing the Selector Layer
My selector classes (fflib - and I have a lot of them), all have a corresponding testmethod.
Three reasons
Classes should have unit tests, period.
Classes with unit tests can be deployed efficiently ...
- 66.8k
1
vote
Testing the Selector Layer
I don't think there's any difference in best practice here (compared to best practice in testing anything else).
That is to say, your goal here is still to execute code (to gain coverage for it) and ...
- 54.7k
0
votes
How to write testclass for custom exception
In a nutshell, by using a try/catch in your unit test.
@isTest
static void testExceptionThrown() {
// We need something to detect whether the exception has been thrown
// (and caught by this ...
- 54.7k
1
vote
Test class coverage required for Custom metadata that turns a Trigger on and Off
Another way to handle this would be to make a proxy class that is responsible for accessing Custom Metadata Type records (instead of accessing them directly). Having this additional layer gives you ...
- 54.7k
4
votes
Accepted
Test class coverage required for Custom metadata that turns a Trigger on and Off
You have here a great example of why you should not put your code in a trigger body, but rather in a class. If you put this flag in your handler instead, you can just hook it up to a static variable ...
- 147k
0
votes
Apex Test Class Error: There is more than one Individual record type for Account or Contact. The record type must be unique
Financial Services Cloud and Health Cloud
Description
Users may see the following error when creating an Account record:
Your account record type is missing, a duplicate, or invalid. Ask your admin to ...
- 2,173
3
votes
Create APex object for testing
You can use @TestVisible for that purpose:
public inherited sharing class MyClass {
@TestVisible
private MyClass() {
...
}
...
}
as that allows a test to use the constructor ...
- 133k
1
vote
Accepted
How to Write test class for OutOfOffice Standard Object trigger in SF?
After some trials , it appears that OutOfOffice object is a part of metadata and visible in test classes.
I was not able to find documentation supporting the same.
In this case , current logged in ...
- 1,003
1
vote
Test Class for an existing Apex Class
Nithin just wanted to know if it is possible to call methods from the Apex Class if he/she wants to test them.
Response yes.
Nevertheless, some errors can impact "cross method".
You just ...
2
votes
How to cover try and catch block in test apex class
Will the exception ever actually occur? For conditions you don't plan on happening best not to add exception handling and allow the exception to pass up and be reported.
If the exception handling is ...
- 133k
2
votes
How to cover try and catch block in test apex class
Try to execute your method wrapped in the try-catch block in your unit test method. It will catch the exception and you can assert if it was really caught.
@IsTest
static void testMethodException() {
...
0
votes
Can we prove security using Apex Tests & System.runAs()?
I am getting some value in using System.RunAs(u) to confirm FLS for Users and queries. This is very powerful when the users are in a collection. Then you can loop through the collection, change the ...
- 562
0
votes
Accepted
I need some help to deploy apex class that is for a visualforce page from Sandbox to Production
In a nutshell, unit testing is just about calling your code so that it runs. It's usually said that there are 3 parts to a unit test: AAA
Arrange
This is setting up the test data, and all of the ...
- 54.7k
0
votes
Apex test class method not working
Your issue is here in the testmethod:
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
List<String> referenceId = email.references;
the value of email.references is null so the ...
- 66.8k
0
votes
Apex test class method not working
@marjan : Above error is seen since you are not inserting EmailMessage records in test class.
Please try to insert EmailMessage record before Test.startTest() using below code :
EmailMessage email = ...
- 1,003
0
votes
Test class for community to get network id
When you create a community user, and the profile used in the community is assigned to the user — a Network Member object record is created in Salesforce.
Thus, if your Alex user has the profile that ...
Top 50 recent answers are included
Related Tags
unit-test × 4651apex × 2909
code-coverage × 809
trigger × 551
failing-tests × 306
class × 205
batch × 196
visualforce × 186
callout × 124
test-setup × 119
soql × 117
deployment × 113
controller × 108
httpcalloutmock × 105
scheduled-apex × 87
community × 56
exception × 55
lightning-web-components × 51
rest-api × 49
webservices × 48
controller-extension × 47
error × 45
future × 43
managed-package × 40
salesforcedx × 39