A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [test-setup]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
49 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
66 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 ...
4
votes
1answer
267 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
779 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
67 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
19 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> ...
1
vote
1answer
201 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
5k 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
1k 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 ...
10
votes
1answer
527 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
524 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
104 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
2k 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
11k 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
104 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. ...
12
votes
5answers
3k 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
81 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
522 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
4k 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
20 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() { ...
9
votes
2answers
361 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
627 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
615 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
203 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
539 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
44 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....
2
votes
1answer
996 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 ...
3
votes
1answer
1k 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
129 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 ...
0
votes
1answer
125 views

Writing test method on List<SelectOption>

What is the best practice when it comes to writing a test code, should I just write code on just to make sure its returning the correct size? and also check the getValue and label is returning ...
2
votes
3answers
349 views

Use ANT to execute existing ApexTests [closed]

I would like to periodically execute local tests in an org outside of a package deployment. I have a deploy entry in my build.xml file that sets testLevel="RunLocalTests", and has an entry for ...
1
vote
1answer
421 views

Test Method Null Pointer Exception on Custom Controller Test

I am setting up the test class for a custom controller, but running into a null pointer exception after the controller has been set running the deleteRow method. I'm not sure what else I need to pass ...
10
votes
3answers
923 views

Why do Methods marked @TestSetup in Classes marked @IsTest count against test coverage requirements?

Every test class on my org that has a TestSetup annotated method shows 0/n lines covered in the developer console (Where n is the number of lines in the annotated method). I thought maybe this was ...
0
votes
1answer
276 views

How is a salesforce custom field with htmlFormatted attribute created?

So I know about text areas and rich text areas (extraTypeInfo). But a customer has some custom fields which are string types but with htmlFormatted = true returned in metadata. Looks like this is just ...
1
vote
1answer
846 views

Delete failed exception when creating test data in an @TestSetup method

I'm trying to create an @TestSetup method for my test class, but I'm getting an exception that makes no sense to me whatsoever and I have no idea how to get past it. Consider the code: @TestSetup ...
6
votes
3answers
884 views

@testSetup method and System.CalloutException: You have uncommitted work pending

Apologies ahead of time for the lengthy post, but I'm receiving the following error when attempting to run the test method below. The error occurs when the upsertProject method is called. System....
0
votes
1answer
81 views

I am not able to write Test class for below code

I am having class which is firing on trigger Before update Here is the class code public class UpdateAbscenceRecord { public static void UpdateAbsenceOnUpdate(Map<id,account> NewAccountMap,...
2
votes
0answers
160 views

Unit Test data setup is hitting Apex CPU time limit

I have written a set of methods in a test class that can be called to create and insert relational test data. I am using Test.StartTest() and Test.StopTest() to keep the operations for the test in ...
10
votes
1answer
927 views

How to create test data for a class that checks for historical data?

I have a class that processes some data returned by a query. The query is based on the createddate column of the object. In this case, the query specifically retrieves data created 3 days before today....
0
votes
1answer
65 views

How to write a test method/class

I have created a simple apex class to be used in conjunction with a visualforce page. Everything is working as I had intended it to in the sandbox and I am now ready to push it over to production. ...
0
votes
1answer
279 views

Want to write test class for the QuoteLineItem Trigger

trigger QuoteLineItemTrigger on QuoteLineItem (after update) { if(Trigger.IsUpdate && trigger.isafter){ QuoteLineItemTriggersHandler objQuoteHandler = new ...
1
vote
1answer
45 views

Data to use in unit tests, how to manage?

while doing unit testing in Salesforce, how do you handle the test data? Do you make new sets of data each time? (thats what Im doing right now) Any other suggestions? On a tangent, how do I ...
0
votes
0answers
257 views

Running Tests in Production WHILE Deploying to Production - Row Lock Error

In our test classes, we utilize testSetup methods that create and insert records in preparation for their use in the test methods of the class. I found today that if I'm running tests in Production ...
1
vote
1answer
761 views

Testing InvocableMethod

so basically I ripped off http://www.iterativelogic.com/using-invocable-methods-with-skuid/ in order to integrate an automatic Lead Convert Method that can be called from Skuid and I'm unable to test ...
6
votes
2answers
1k views

Set CreatedById Field in Apex Test Class

I have created a trigger on the Account object that is validated only if the records are being created by an non-admin account. In order to test this functionality I would have to set the ...
-1
votes
1answer
110 views

How to write test case for this method where try and catch code is cover? [closed]

@RemoteAction public Static List < Document__c > GetMarketingDocuments(string opportunityId) { try { string queryString = ''; List < DroisysOne__Document__c > docs = ...
2
votes
1answer
1k views

Create test data with more than 10000 rows dynamically in apex

I am trying to Create test data with more than 10000 rows dynamically in a test class. Am hitting the dml row limit error (Too Many DML Rows: 10001). I dont want to use loaddata feature as I need to ...
10
votes
1answer
286 views

Why does an autonumber sequence get “stuck” when creating records after a @testSetup method?

I ran into this while writing unit tests for my org but I simplified it in a developer account to make sure it would happen there. I have custom object Thing__c. The Name field is autonumber. I wrote ...
2
votes
2answers
53 views

Regarding Apex class

While Executing Apex Class only Top Level Class should Be Declared as Static in Test Class,Why this Error is Occuring ,How to Avoid this Error? @isTest public class BusinessProfile1 { public void ...
1
vote
0answers
89 views

Understanding coverage when @TestSetup is used in a test class

I have a Test class which include a method with @testSetup annottation. After saving this class it was added in list Overall Code Coverage like in the picture bottom. I was confused after that. When ...