Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

The tag has no usage guidance.

7
votes
2answers
285 views

@testSetup vs DataFactory?

When testing, how/when will @TestSetup annotation be preferable to a "DataFactory"? I understand how both works, but I don't see any case where I'd rather use the @testSetup annotation. I use this ...
2
votes
1answer
72 views

Test Class failing in production [closed]

I have a test class failing while validating it and its base class deployment to production. The test setup is creating several records in 2 objects (1 standard 1 custom) and inserting them as a ...
0
votes
1answer
20 views

A-B Test - clean random distribution

I´d like to use the AB Test function in the Email Studio. I´ve got one big sending data extension. That DE contains all subsrcibers from different countries. Now I want to test 2 different ...
0
votes
0answers
38 views

Efficiently send and test a email template to different groups (data extensions)

Request for email sends are coming in daily with a specific requested sending date and a list to send to. All these emails will use the same template and every receiver within one list will have ...
0
votes
1answer
56 views

How to Test Omni-Channel User Service Presence in Apex Test Class

I have a class I need to write an apex test class for that uses the UserServicePresence object for Omni-Channel as a major filter for a SOQL query in the class. The majority of the logic in the class ...
1
vote
2answers
35 views

How many records can be created in TestSetup method in test class?

How many records can be created in Test Setup method in test class
1
vote
1answer
17 views

Case Number duplicates found for case insert in Test Class

I faced a weird scenario today. I have a @testSetup method for inserting my case records and then used another method to query those case records to fetch CaseNumber field and pass it to a JSON String ...
2
votes
2answers
66 views

Am I setting up a Pricebook Entry incorrectly?

Update with More Code: The Test Class contains: Product2 plc = new Product2(Name='My Product', ProductCode='PC-1'); insert plc; Id pricebookId = Test.getStandardPricebookId()...
1
vote
1answer
169 views

How do I create Test Data for an Org. Wide Email Address?

I need to create an Org. Wide Email address for my Test Class, and I can't seem to find documentation for this. One forum led me to believe it wasn't possible, but it wasn't clear if I was ...
2
votes
1answer
131 views

Test.startTest() in testSetup method

An year ago I asked a question regarding the advantages of using testSetUp annotation instead of having a method for common data and calling it in every test method. My main issue at the time with ...
0
votes
1answer
319 views

regarding External entry point

i have one custom field called Unique_Vendor_Id__c on account object (external id checkbox checked) and its auto-number. now in test class when i create account for test data Unique_Vendor_Id__c ...
1
vote
1answer
193 views

Empty picklist value is getting saved as null

I am trying test a piece of code by changing a Status__c field on Save_Attempt__c Object. I am explicitly setting the value of Status picklist to an empty string and not null but when I query, it's ...
6
votes
1answer
160 views

Testing with ApexMocks vs Stub API

We are looking into using ApexMocks to improve the tests in our managed package. The problem is that it looks like we will need to bring it into our package which will increase the number of classes/...
0
votes
2answers
66 views

How efficient is to use Future call in Test class?

We have scenario where we are trying to create test data in tetsSetup method. We wrote a test data creation script in Util method and marked it as future and calling it from testsetup method. Is it ...
0
votes
1answer
66 views

Batch test class not working!

I have managed to put together a batch test class using Trailhead, but it is not correct, all I need is for it to populate values in new custom fields with values in other fields all from the Account ...
0
votes
1answer
138 views

Is org data visibility(seeAllData = true) required for test method to create test data?

I am writing a test class for testing webservice callouts as a part of one of the challenges of Data Integration Specialist superbadge. Here I am creating test data by inserting some custom object ...
0
votes
0answers
46 views

Apex @testSetup

I have the below test but I can't figure out why the opportunity won't query. When I run this test class, the error I keep getting is "System.QueryException: List has no rows for assignment to SObject"...
2
votes
2answers
178 views

What is the scope and level of isolation of @TestSetup data in a test class?

I would like to use @TestSetup in my unit tests to create common data for each of my test methods: @isTest private class AwesomeTests { // how many awesome things to setup static final ...
1
vote
1answer
295 views

Can I use the @TestSetup from a separate test class?

I have a class I want to test that has an associated test class with it. I am wondering if I use a TestDataFactory class if the @TestSetup annotation will allow me to access the data inserted from my ...
0
votes
1answer
29 views

After update trigger fires from UI but not in test class

I've got a simple trigger written to update attributes of a child record when the value of the attribute in the related parent changes. The trigger works fine for actions triggered in the UI, but it ...
0
votes
1answer
36 views

Test class no inserting object

I have a test class that seems not to be inserting some setup objects I need for the test. My test class is as follows: @isTest(seealldata=false) private class Alertas_The_Influence_isTest{ public ...
0
votes
1answer
42 views

Test Class Having More Issues Setting Basic Dummy Info

I'm having issues with setting the dummy data as there are a lot of required fields on the system. I'm getting this error when attempting to create a dummy Marketing Source. And I apologize on the ...
3
votes
1answer
124 views

Do governor limits like Apex CPU time limit apply to @testSetup methods?

I have a test method written by a third party that occasionally results in Apex CPU time limit errors. The part of the method that includes setting up a semi-large amount of data on multiple objects (...
1
vote
1answer
566 views

What is the easiest way to test a journey?

I have a journey built and I'm wondering the easiest way to test it. Would you create a replicated test Data Extension and copy the journey?
0
votes
1answer
50 views

Running a test in developer console v.s. setup

I'm running a unit test in developer console and in setup and I appear to be getting two different results. Within the dev console, my unit tests appear to be passing. But when I run the tests in ...
0
votes
0answers
17 views

loading bulk data for testing gives : System.LimitException: Apex CPU time limit exceeded

I am trying to test my batch process by loading bulk data: I am creating the data as follows: List<Account> accounts = new List<Account>(); List<Account_Plan__c> ...
0
votes
0answers
21 views

Partner Community Sharing issue in Test Code

I've created a partner enabled Account and an associated Contact (enabled as Partner User) not in code, and that user has access to their own Contact record. I'm running a lightning component that ...
1
vote
1answer
92 views

Test class works in sandbox, fails in production validation

I'm at a loss. I don't understand why my test class works fine in the sandbox (100% coverage), yet when I run a deployment validation in production, I get the following error for each test method: ...
0
votes
3answers
982 views

Using the same test setup for multiple test classes

So here's the situation, I have a lot of things that I want to test, and each of these things requires the same data to be present in the org. I was hoping to be able to use the @testSetup annotation ...
4
votes
1answer
390 views

Avoiding Governor limits on test classes

We have a custom application created on force.com platform which has a lot of unwanted SOQL Queries and DML Statements written in a poor format. We are trying to stabilize the code now and looking ...
9
votes
1answer
248 views

Are @future methods ignored in @TestSetup blocks?

Ok, this is going to become a quite long question. The main goal is to document strange platform behavior and maybe learn more why this happens. It all started with that test which failed because ...
0
votes
2answers
145 views

Unable to use setup in test class @testSetup

When i use the @testSetup method, and try passing the myContact in ApexPages.StandardController sc = new ApexPages.StandardController(myContact); the line returns error Argument cannot be null @...
0
votes
0answers
85 views

How to fix unneeded Code Coverage?

I have a testclass with the following structure: @isTest public class UnitTests { @testSetup static void setupTestData(){ // insert some sObjects } @isTest static void ...
0
votes
1answer
717 views

Test a Method Which has no Parameters or Return Type

I having written a lot of code and there are like 25 Function which have no parameter and no Return Type. What is the best way to test the Method? Below is my code: public void solenoidPriceUpdate(){...
5
votes
2answers
7k views

How to use the annotated @TestSetup method in Tests?

I'm working on how to use methods annotated with @TestSetup. I didn't find a way to pass the caseId from the initData method to the methodTest, so I request the case with limit 1. Is that the right ...
2
votes
2answers
57 views

Best Practice for testing with RunAs method

I noticed that when you create a user in a test class that the username must be unique in the real production environment. Most of my test classes are creating a user to then run the test method as. ...
9
votes
5answers
2k views

What are the advantage of the @testSetUp annotation

Before Salesforce introduced @testSetup annotation in 2015, I used to create common data in a method and call it in every test method. Ex: @isTest private class clsAccountTest { private static ...
0
votes
0answers
38 views

Test class failure during execution from console, but not during deployment

I have test class that fails in production while executing it from the developer console, but when deploying other things it pass. Note, that it is not related to the user, same run/delpoyment is with ...
-1
votes
1answer
317 views

Testing the apex class which implements Comparable [closed]

How can I test the below test class? Any thing to get me started? global with sharing Class FieldSetDetail implements Comparable { global String fieldSetName {get; public set;} global String ...
0
votes
2answers
1k views

how to create a Sobject object

I am trying to create a test class for below class. I have to create an Sobject object and call the function by passing sibject in parameter. How can I write a complete test class for below class: I ...
1
vote
1answer
19 views

problems with test methods

I'm having problems with my test methods. For example, I stripped everything else down from this code @isTest global class RestSalesData_TEST { testmethod static void testRestSalesData() { ...
8
votes
2answers
299 views

Does assert methods needed in @testSetup?

I ran force.com security scan on my managed package i got the following report Query: Test Methods With No Assert L 4: @testSetup static void defConnSetup(){ so is it necessary to add assertion ...
0
votes
1answer
181 views

How to cover code related to Custom Metadata logic?

I have a custom metadata called Custom_Metadata__mdt. I have one custom boolean field in that custom metadata called Custom_Boolean_Field__c. I need to execute some logic only if value of ...
1
vote
2answers
337 views

Cannot query Contact records when runAs a Portal User in a test class

I have created a service which allows a portal user to query records based on some values set up on their own contact record. In my test scenario, I want to set up something similar, where I first ...
2
votes
2answers
128 views

How do I read the Id for an object instantiated by my @testSetup method?

I've setup a @testSetup method to share amongst my Unit Test methods. One of my methods relies on the auto-incremented Id of the object created by my test method. Here's my code: @testSetup static ...
1
vote
1answer
295 views

How to write test class for DTO

I have a DTO class where lots of inncer classes are defined like..if i am wiring public OuterClass{ innerClass1{ //variables declarations } innerClass2{ //variables declarations } ... ... ...
0
votes
2answers
23 views

Trigger's Test Case Help (Trigger Works fine)

I have 3 objects Master Contact, Master Volunteer_Project__c and Detail Participation__c. Means Participation__c is detail for both Master. Now One Volunteer_Project__c can have many Participation__c....
3
votes
1answer
729 views

use testsetup for common methods in test class

As per my understanding and salesforce documentation, class annotated with @isTest should contain "only test methods". But there are some situations where we might need to have utility methods and ...
2
votes
1answer
698 views

Unit Testing ConnectApi.ChatterFeeds.getFeedElementBatch with auto-created feed posts

I have created a webservice APEX class that I need to write a Unit test for. The webservice assembles a custom filtered list of Chatter 'FeedElements'. All 'FeedElements' are system created, i.e. they ...
1
vote
1answer
95 views

Test Coverage Drops from 92% to 21% if @testSetup inserts more than 200 records through a Trigger with a RunOnce boolean

A few months ago, I asked this question: Question regarding "RunOnce" Booleans on AfterUpdate methods in a Salesforce Transaction The answer provided indicated that I should move my RunOnce ...