Questions tagged [test-data-isolation]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
135 views

My test class (not annotated seeAllData=true) actually sees data for ContentNote SObject

I know test methods should not see any data except the data created in test context, but when I run the test below, the query returns an org record. It should not I have a REST class like @...
user avatar
1 vote
1 answer
228 views

Updating Object during isUpdate and isBefore trigger

I have a trigger that fires on the event trigger.isUpdate && trigger.isBefore for the Account object. In this trigger, I need to update a field in the Account object. I tried to add an update ...
user avatar
  • 35
0 votes
2 answers
244 views

A way to put sobjects to a relationship for faking data?

I'm trying to build a database fake using StubAPI to use in Apex tests. I want to do it to save time on Database interaction (no DMLs and SOQLs) and make tests faster. But I faced an issue with ...
user avatar
  • 951
9 votes
1 answer
764 views

Unit Testing problem with Product2 records: A Product with this SKU already exists

I'm using the Product object and store the product sku within the StockKeepingUnit field. According to the Winter 18 release notes, this field is considered unique, which is totally fine and expected ...
user avatar
  • 181
4 votes
2 answers
2k views

How to use Stub API in the following scenario?

I am trying to understand Stub API a bit: My Class: public class DistributedMSelector { public static Map<string, user> getUserMap(Set<String> employeeIdSet){ Map<String,...
user avatar
  • 461
4 votes
1 answer
106 views

Testing an approval process - should I create metadata just to test?

I have an Apex test that is testing if a record is in an approval process. To test, I have to submit a record for approval - but there is no guarantee that there will be an approval process set up in ...
user avatar
2 votes
3 answers
1k views

How do I pass record IDs from testSetup to isTest methods?

I want to create data in a test class that can be used by multiple test methods. However, for the test method to be able to access that test data, I need a way to pass the record IDs to from the @...
user avatar
2 votes
0 answers
52 views

Workflow rule has access to Org data when running in a test context

I have an interesting situation, and I am working a Case with SF Support on. I though I would ask the same question here and see if anyone else has seen something similar. It starts with a Custom ...
user avatar
2 votes
2 answers
316 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 ...
user avatar
2 votes
1 answer
254 views

MocksApex - behaviour verification

I am using the ApexMocks framework and I am having the following error message: Class.MockTest.testBehavior: line 13, column 1 11:53:56.3 (10709808)|FATAL_ERROR|System.NullPointerException: ...
user avatar
  • 1,410
7 votes
2 answers
1k views

Writing tests for Managed Package

I'm developing a managed package and I need to implement some test classes to test my code. However, I'm not sure how to write my tests in such a way so that they don't break due to custom rules put ...
user avatar
  • 5,188
3 votes
0 answers
524 views

Test passes when run alone; fails when run with other methods in the same class

I've got a test that passes when run by itself, but fails when run alongside another method in the same class. No changes were made between test runs, and I have made sure to select Disable Parallel ...
user avatar
  • 178
2 votes
1 answer
558 views

Seeing all Territory data in test, but SeeAllData is False

For some reason, am I seeing territory data (Territory2Model, Territory2) in my tests, but I have not set SeeAllData=True and I've even set SeeAllData=False. Without perform any test setup and ...
user avatar
4 votes
1 answer
675 views

Changing username in Apex Test is emailing the user

I'm testing a controller for a Customer Community page where users can change their email address. To keep things simple for the user, I'm getting the controller to also change their username to match ...
user avatar
  • 12.7k
1 vote
1 answer
53 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 ...
user avatar
  • 313
3 votes
1 answer
410 views

Test coverage for a user trigger: How to prevent "DML not allowed on User" in test-class?

I want to deploy a trigger on user. Therefore I need > 1% coverage on the trigger. To invoke the trigger in my test class, I've tried this: @isTest public class elfTriggerFrameworkTest { public ...
user avatar
  • 33.5k
3 votes
1 answer
646 views

Using Test.IsRunningTest(), Risks and use-cases

Through our testing coverage implementation on a project, we encountered some collisions on a trigger which assigns a Pricebook to a Product and our test data factory (uses "@test setup" tag => no ...
user avatar
1 vote
1 answer
2k views

UserTerritory2Association trigger test

I have a trigger for UserTerritory2Association standard object like: trigger MyUserTerritoryAssociationTrigger on UserTerritory2Association(after insert, after update, after delete, after undelete) { ...
user avatar
  • 931
2 votes
1 answer
949 views

How to catch custom exception in a test that causes a DML exception

I am writing a test for a 'before insert' trigger. In the trigger, an exception is thrown if there is a problem with the validation (by design). In production, the trigger catches the exception and ...
user avatar
0 votes
2 answers
51 views

Testing a List "Searchable" Controller

Will someone please explain, or correct, my testing logic for the following code? The first image is the test, and second image is the code. Here's the test Here's the code Here's the code again, ...
user avatar
2 votes
0 answers
425 views

Issue with Query during Test on User Object after Winter 15

Specific example that I did not see in other questions: Unable to query user object when filtering on ProfileName and Limiting result during test in production Have a test class passing in full ...
user avatar
  • 53.1k
0 votes
1 answer
895 views

Test.loadData with sObject Throws Unknown field: Exception

Iam loading a CSV file via Static Resourced to test my APEX code. I am using the following code in my test: List<sObject> ls1 = Test.loadData(Account.sObjectType, 'TestAccount'); CSV file ...
user avatar
4 votes
0 answers
575 views

S2S Test Data Isolation

Goal - Avoid using SeeAllData=true for testmethods against APEX code that inserts PartnerNetworkRecordConnection objects (to test outbound sharing) What I believe to be true PartnerNetworkConnection ...
user avatar
  • 61.4k
1 vote
0 answers
196 views

seeAllData = false vs. ConnectApi

I have a trigger on FeedItem that auto-tags a topic. It does so by creating a TopicAssignment record and inserting it via DML. The problem is that I am getting a gack if I attempt to auto-assign a ...
user avatar
  • 14.5k