New answers tagged

1

Your first port of call should be this answer. See also this recent answer Normally, one needs to inject the mock UnitOfWork into the fflib factories as such: Application.UnitOfWork.setMock(mockUow); But in your case, this isn't necessary as the code under test is passed the mockUow directly: service.insertSerialNumbers(documentItems, assets, mockUow); ...


1

There is Database Isolation in Unit Tests, but users are not hidden from unit tests this way. You can always query real users in unit tests. If you want to make sure you get the user you created, you should include an ORDER BY clause: query = 'SELECT Id,Name,UserCategory__c from User WHERE IsActive = TRUE ORDER BY CreatedDate DESC LIMIT 1';


1

After no responses here or elsewhere, I contacted Salesforce. They mentioned that it's currently not possible to create test code for an Apex Trigger on the ActionCadenceTrackerChangeEvent because one can't generate the Action Cadence Tracker records via Apex. Support mentioned they can temporarily remove the production test code requirement so untested code ...


0

@isTest public class CreateQuotePDFController_Test { @testsetup static void data_setup(){ Account acc1 = new Account(); acc1.Name = 'test account'; insert acc1; system.debug('insert acc1 is success'); Opportunity Opp1 = new Opportunity(); Opp1.Name = 'testOpp'; Opp1.AccountId = acc1.Id; Opp1.StageName = 'Closed Won'; Opp1.CloseDate = ...


7

I wrote some unit tests: @isTest public class q359389 { static final Boolean IS_PERSON = true, IS_BUSINESS = false; static Account createAccountAndTask(Boolean isPerson) { RecordType rt = [SELECT Id FROM RecordType WHERE IsPersonType=:isPerson AND sObjectType='Account' LIMIT 1]; Account a = new Account(RecordTypeId=rt.Id); a....


0

No there is no alternation when used in Unit tests. Just in case I fired the same method multiple times and it's returning the same Id, on each execution. I also used hardcoded Id instead of method and reversed query if somebody asks this question :) Task[] tasks2 = [SELECT id from task where what.recordTypeId = '0120Y0000002lFXQAY' limit 1]; System.debug('...


0

Why is jest picking up the mock I created globally instead of the one that is within the scope of the test? In pure jest terms, I would expect the behavior you noted based on the code you shared. There's this large discussion on a closed jest issue that has some good information So jest.mock is being hoisted to the function scope, that's why it won't work ...


1

You're running into two errors. Thankfully, the error messages Salesforce emitted here are decent, and it should be fairly easy to see what the issues are if we examine those error messages. First up, the error in your @testSetup method The error you report is System.DmlException: Insert failed. First exception on row 0; first error: ...


1

Before the deployment, you will have to delete all the versions that have references to the class. On the same deployment or before you will have to remove all references to the class from LWC components and others. You can use a workbench (or sfdx or any similar tool) to perform this metadata deployment (which could include the destructive change - deleting ...


0

There was something in process builder assigning it.


0

Here is a solution that uses a ternary so it does not sacrifice code coverage: HttpResponse response = Test.isRunningTest() ? new Http().send(request) : toolkit.sendRequest(request); return response;


2

No. Absolutely nothing aside from a debug log and test metrics (success/fail/code coverage) will persist beyond the scope of a unit test, including any DML operations, events, emails, scheduled jobs, etc. Your only choices are either cause an assertion to cause the test to fail (e.g. if you're concerned about governor limits, you can force a failed test), or ...


1

At a basic level, you simply create a record, then change the value in memory, and update: Account record = new Account(BillingPostalCode='12345',...); insert record; record.BillingPostalCode = '54321'; Test.startTest(); update record; Test.stopTest(); // remember to check to make sure your logic ran.


0

As has been discussed in the comments, this is an issue of bad test data/setup. In unit tests, you are responsible for creating the test data and providing the appropriate inputs to the method you're testing. It's your job to craft the test environment so that your code executes in the manner you wish it to. Sometimes, we want to craft a test environment ...


Top 50 recent answers are included