Skip to main content

Questions tagged [test-setup]

Filter by
Sorted by
Tagged with
-1 votes
1 answer
32 views

Create permission set in test class

Let's say there is a need to create Permission Set like PermissionSet ps = new PermissionSet(); ps.Label = 'dummy-test'; ps.name = 'dummy_test'; insert ps; inside @TestSetup method. Can be we sure ...
pincet's user avatar
  • 933
0 votes
0 answers
30 views

User.LastLoginDate is not not writable in test class using salesforce [duplicate]

My test class: @isTest public class DeactivateInactiveUsersBatchTest { @testSetup static void setup() { // Create sample User records with LastLoginDate more than a year ago and ...
Sridhar's user avatar
  • 63
2 votes
1 answer
133 views

Why isn't my Salesforce test method returning null when querying a deleted record created in TestSetup?

I have a Salesforce test class with @TestSetup alongside two test methods. In the last method (testQueryDeletedRecord), I attempt to query a record that I deleted in a previous test method (...
Licytede's user avatar
0 votes
0 answers
39 views

Is there any to automate the process of Quality assurance for data and campaigns in SFMC?

Currently, our team does a lot of manual work for Quality assurance to validate data in data extensions and checks on the campaigns to make sure they are going to the correct population. Is there any ...
kl2's user avatar
  • 353
0 votes
1 answer
108 views

Test Class Data Setup - Cant Access Data outside

Within my test class's "setup()" method, I am calling a class that creates and inserts Salesforce objects and the necessary related objects to create that object (if any). @TestSetup static ...
plowrey's user avatar
1 vote
1 answer
87 views

Formula Field with Custom Metadata Type that is created in test method

I have a test method that needs to assert the creation of a document, the creation of such document is blocked by the evaluation of a (Boolean) Formula Field that depends on a Custom Metadata Type ...
djpeluca's user avatar
  • 187
0 votes
1 answer
123 views

Test Class Data for PlatformEventUsageMetric

I have a simple, invocable class to query delivered platform events using the PlatformEventUsageMetric object and it is working in flow, but I'm not sure how to create a test class for it if I can't ...
Kendra Broom's user avatar
0 votes
1 answer
855 views

Getting System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Enter a role-based external user

Im trying to create a record of an Object (DelegatedAccount) in a Test class inside the test Setup method. Its an entity that has 2 Lookups - To Account and User Object. while creating the User record ...
Amax1's user avatar
  • 121
1 vote
0 answers
141 views

Use of UserRecordAccess in queries during System.runAs()

I am building a feature that uses apex-managed sharing to define granular levels of record sharing. I would like to have end-to-end tests that sets up records, users, runs the feature, then validates ...
Jeff Kranz's user avatar
  • 2,047
-1 votes
1 answer
53 views

How to get information which tests are required for specified scope

our deployment pipeline works on diff. So every time only differences between source and target branch are deployed to environment. We are wondering if there is possibility to run only required tests ...
kamil Walo's user avatar
0 votes
1 answer
2k views

AssertEquals not working as expected

I have a test class that works on my org dev, I'm trying to make deploy in another org but it's having a strange behavior, the error is in the first assertEqual: @isTest static void testUserStore()...
Alexia's user avatar
  • 83
0 votes
0 answers
246 views

Price book entry is in a different pricebook than the one assigned to the opportunity Error

I'm facing the issue while deploying the test class in production. System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: ...
Yassine El Moustachir's user avatar
-1 votes
1 answer
144 views

Create APex object for testing

Is there a way, customer can create APEX object for testing? We are exposing APEX object for external developers to work on, but we do not expose constructor.( The object is built in the Java Layer ...
Arpit Shah's user avatar
0 votes
0 answers
44 views

How do I test child accounts? Test code shows nothing for child accounts ANSWERED

How do I test child Accounts? The test I've written finds the parent account, but returns nothing from the child query. Work: Display a button if the Account has a set of fields properly populated, OR ...
afandre's user avatar
  • 73
0 votes
1 answer
341 views

Lookup's related Lookup is blank in test class, even with test data inserted

My Lookup's(MD) related lookup field is coming up as null in testclass. So I have 3 objects, lets Objects X, Y and Z Z is the detail and Y is the Master. Y has a lookup to X In the test class I am ...
Mavsav Sauve's user avatar
0 votes
0 answers
252 views

Are Salesforce Account Territories Available in Test Class without seeAllData = true

Are territories visible in test class without SeeAllDate=true ?? I have an account created and then I try to query the territory, but it is coming as blank. List<ObjectTerritory2Association> ...
Superwoman's user avatar
-1 votes
1 answer
2k views

QUEUEABLE TEST CLASS

I have a request to create a queueable test class where the test class is to use @testsetup using a testdatafactory returning a complex wrapper class. The idea is the testDataFactor should populate ...
Daryn's user avatar
  • 251
0 votes
1 answer
950 views

Lwc controller apex test class

Say I haven apex class that is being used in a lwc to bring in the name of a group via a wired method to variable accid. The apex class looks something like this. Public controllerclass { Public ...
nllops's user avatar
  • 1
1 vote
1 answer
4k views

How to use methods from Assert Class

According to this doc from the Apex reference guide, I can use methods from the Assert class in my test methods but when I am trying this in my code I am getting an error message:- "Variable ...
RDrathi's user avatar
  • 53
0 votes
0 answers
260 views

How to cover for loop with wrapper class in test method?

I am not getting coverage from " for (FileInfoWrapper file : caseInfo.files)" @AuraEnabled public static String loadData(String strCaseInfo) { System.debug('caseInfo ' + strCaseInfo); ...
Raffus Kh's user avatar
-2 votes
1 answer
5k views

Test Class for custom metadata

Getting the error of List has no row assignment in test class. How should i query the custom metadata in test class Apex - public with sharing class GetAccountsController { @AuraEnabled(cacheable=...
user111906's user avatar
0 votes
0 answers
19 views

test class for attachments for events in salesforce [duplicate]

Hi can anyone please help me with a test class for below two methods global static void insertAttachment(string eventid, Map<String, Object> json_body) { try { Map&...
sfdcpanther's user avatar
2 votes
1 answer
2k views

How to use Cobertura and JUnit reporters with LWC Jest?

When creating a new SFDX project, the default Jest configuration for LWC unit tests looks like this: jest.config.js const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config'); module.exports =...
Sebastiano Schwarz's user avatar
0 votes
1 answer
26 views

Test Code Coverage for Querying

I'm having some problems trying to write a test class. The issue is, the class which is being tested is composed of 5 methods that receive some information and use that information for querying. They'...
Julia de Lucca Ribeiro's user avatar
0 votes
0 answers
98 views

System.runAs() does not function as expected

static testMethod void testForDeletePrevent(){ PCA_Settings__c pcaConfig = TestDataFactory.createPcaSettings(); Common_Settings__c config = TestDataFactory.createCommonSettings(); ...
David Zemlyanker's user avatar
1 vote
1 answer
70 views

Testing a Field Sync utility without creating custom fields

I've created a utility in Apex that syncs a Lookup(User) field on Account or Opportunity with a specified Account or Opportunity Team Member Role, based on a custom metadata configuration. It's all ...
Mike's user avatar
  • 1,199
1 vote
1 answer
559 views

How do I write test class for an OpportunityContactRole that has a loockup field for contacts?

the situation is as follows, I have the opportunity, and inside it I have the Contact Roles and inside the contacts roles I have a lookup field that points out contacts, my test coverage is at 97% but,...
Souza's user avatar
  • 305
0 votes
1 answer
82 views

Test Class in Auto-populate

Hi can you help me build my Test Class? Below are my Apex Class and Test Class. Apex Class public void autoPopulate(List<SObject> newList){ System.debug('#####alignTaskSubCategory'); ...
Lhanz_404's user avatar
1 vote
0 answers
90 views

How to handle namespace for Test.loadData method

I am trying to insert test data with Test.loadData for custom object with fields in my managed package. The problem is my developer org do not have a namespace and packaging org has it. How we can ...
Ferhat Özsavran's user avatar
-3 votes
1 answer
1k views

Test Apex class that has void as the return type

How to test an apex class that does not have a return value? Here this is the test class I wrote so far. It creates two content documents and then a case, what I am testing is linking the content ...
Sumesh Chandran's user avatar
0 votes
1 answer
2k views

Cypress as UI test automation tool for Salesforce [closed]

Does anyone have experience using Cypress as a UI test automation tool for a Salesforce based project? If so, what are the drawbacks, constraints or implications, e.g. regarding login or possible ...
Sebastiano Schwarz's user avatar
1 vote
3 answers
2k views

@testSetup best practice

I'm trying to understand something so I can use @testSetup annotation wisely. As i read here: https://developer.salesforce.com/docs/atlas.en-us.202.0.apexcode.meta/apexcode/...
Benj's user avatar
  • 45
3 votes
1 answer
186 views

Flaky apex tests fail unreproducible with UNABLE_TO_LOCK_ROW when inserting Product2

Recently, our tests started to fail randomly with the dreaded UNABLE_TO_LOCK_ROW. The only fix seems to "Restart on Failed" the pipeline until it succeeds. This is the fixture code in ...
J. Schreiber's user avatar
  • 1,764
0 votes
1 answer
117 views

How can i test my Apex method

I am not sure how to write test class for this method. Any help would be greatly appreciated! @AuraEnabled(cacheable=true) public static List<Map<String, String>> getPickListValues() { ...
Tsimaphei's user avatar
2 votes
2 answers
1k views

How to use a constant in SOQL in a test class

I have the following test class: @isTest(SeeAllData=false) private with sharing class classNameTest { @isTest static testMethod void methodName(){ // declare a constant ...
MShal's user avatar
  • 31
0 votes
0 answers
54 views

Query in Batch Apex returns "List has no rows for assignment to SObject" [duplicate]

I have test class where I am using a csv file to insert 200 records Account data. First 100 are like: remaining 100 are like: I am using above created test class to test a batch apex class which has ...
SunnyG's user avatar
  • 421
0 votes
1 answer
1k views

Cannot insert a quotelineitem in my Test Class

I try to insert a quotelineitem in my test class but it fails with this error ,Please help me to resolve this issue . See below my code used in the test class Quote quote = new Quote(Name = 'devis1' ,...
user3499987's user avatar
0 votes
2 answers
2k views

Test Coverage for trigger on ActionCadeneSteptracker CDC

We are working on Updating Lead status on meaningful connect of call in HVS (High Velocity Sales), so we went ahead with the proposed solution of creating CDC on ActionCadenceStepTracker object. https:...
user97546's user avatar
0 votes
2 answers
284 views

How to test Job states for a Apex Test with CronTrigger being read only?

I have the following function in a class that implements System.Schedulable: @TestVisible private void rescheduleJob(CronTrigger me, ISchedulable item, MySchedulableContext myCtx) { if (me....
kratos's user avatar
  • 541
0 votes
0 answers
397 views

How Do You Test Multi-Currency Logic?

You cannot setup any currency during apex tests, and therefore any logic that works on the currency of records is untestable. Am I correct? The CurrencyType does not support DML (https://developer....
J. Schreiber's user avatar
  • 1,764
0 votes
1 answer
903 views

Setup and NonSetup object insertion in Test Class

we've a factory class method to create sObject: Class: DataFactory: public static SObject createSObject(SObject sObj, String defaultClassName, Boolean doInsert) { SObject retObject = ...
Krishna Chaitanya's user avatar
0 votes
0 answers
93 views

Where is the data in batch class coming from?

First of all, I'm very new to salesforce so It's possible that I'm ignoring something very basic. I was writing a test class for the following batch (I've removed all the irrelevant parts). global ...
randomperson's user avatar
0 votes
1 answer
644 views

Creating a dummy Visualforce page for an apex test class

Im working on creating a test class for two apex classes(one is scheduled another is batch apex. The scheduled is linked to the batch apex to have it run regularly.) The issue that I am running into ...
Jebert's user avatar
  • 15
0 votes
0 answers
45 views

How can I get a list of fields that I added to one form in Salesforce?

I'm pretty new to Salesforce and I'm wondering if there is a way to get all the fields and HTML elements that I'm using with those forms to do some future testing with cypress and selenium. Does ...
Hvaandres's user avatar
  • 111
-1 votes
2 answers
477 views

What is test class for below code? [duplicate]

public class UtilityClass { public static String getDescribedObjects( List lstSObjectType ) { // Globally desribe all the objects Map<String, SObjectType> globalDescribe = Schema....
aishwarya gotarkar's user avatar
1 vote
1 answer
109 views

Test Class Id Error

I trying to get better and have built a trigger/test class using my knowledge I have learned however I am running into an error with the test class that for some reason I just cannot resolve and ...
Craig Phoenix's user avatar
1 vote
1 answer
588 views

Mocking Object list issue

This question is sort of a continuation to this question. I have this method: public static void sendMail(List<Object> selectedRows) { if (selectedRows.size() > 0) { for (...
Jayesh Babu's user avatar
1 vote
1 answer
2k views

how to mock Object list in a test class?

This is a method in my apex controller class: @AuraEnabled public static void sendMail(List<Object> selectedRows) { if (selectedRows.size() > 0) { for (Object obj : ...
Jayesh Babu's user avatar
0 votes
1 answer
258 views

No code coverage in sandbox and partial sandbox before preparing changeset

we have developed one solution in Salesforce in the developer sandbox the solution contains the Apex Class,Trigger, Custom Objet and LWC. Eventually, We are planning to release this solution as a ...
Hunt's user avatar
  • 245
1 vote
3 answers
1k views

Is it really needed to check whether a list has a record in a test class?

I have a scenario like this, I have created Opportunities in a Test setup and tried to access it in a test method to clone that record like, testSetup { // Create a list of Opportunity Records. ...
Hariprasath's user avatar