New answers tagged

0

same happened to me and I had to create a schedule class that class a batch class, and then create the respective test classes Test.start(); Database.executeBatch(new UserActivationJob_JCS()); Test.stopTest(); //assert the logic Test.startTest(); String jobId = System.schedule('TestScheduledApex', '0 0 0 3 9 ? 2022', new UserActivationJobSchedule_JCS()); ...


0

After removing System.abortJob Replace your query with 'SELECT Id, POP_User__c FROM User where Name not in (\'Chatter Users\')' +(Test.isRunningTest()?' LIMIT 50':''); and it should work. This is because you're querying on a Setup object (one not affected by SeeAllData=false), so you'll need to limit your query. So all your records gets executed within a ...


4

Currently, I came up with some ugly but efficient solution for mocking Database.QueryLocator and to be precise, its substitution. To change the return type of AccountSelector.locatorByIds() method from Database.QueryLocator to Object: public with sharing class AccountSelector extends fflib_SObjectSelector { public override SObjectType getSObjectType() {...


1

Your issue is that proposta.technologies is null. It's declared as a list, but your test never initializes it. Your code right now basically evaluates to null.add(tec); null.<something> gives you a Null Pointer Exception. Adding proposta.technologies = new List<AquirersPJRest.Technology>(); prior to your proposta.technologies.add(tec); line ...


1

I don't think you can mock it. I assume you need this b/c you want to mock out some records to test Batchable classes? If so, I just call each method (start, execute, finish) independently. The records I want to process are passed in manually within the execute method. The first method here will require you to have real records inserted for your tests. ...


0

As you mentioned that you were new to Salesforce, it is quite common that this question has bugged you. In order to understand the answer to this in a better way, we will first focus on this question - Why do we need to write unit tests in Apex? As it is widely known, a unit test ensures that a particular piece of the class which it tests, works as expected. ...


2

Looks like your test class is missing custom setting records for ServiceTokens__c . Create a custom setting record using the same name and add test data on the below lines ServiceTokens__c serviceToken = new ServiceTokens__c(); serviceToken.Name = 'ProjectServiceToken'; serviceToken.Token__c = 'XYZ'; insert serviceToken;


0

Calling Database.executeBatch method from another actually inserts a record of ApexAsyncJob in the database. so calling Id batchId1= callBatches('CLOSE'); inside startTest and stop test will try executing your batch and make the callout. And thus you will get your result uncommited work pending error. The solution is to directly call the batch execute in ...


0

In the test class are u making a DML just before calling the method that does the callout ? And in test class we follow two practices have you executed them ? Callouts should have mock class https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm Async calls are enclosed inside Test....


2

Looks like you're just missing update batchSchedEnc; after the line batchSchedEnc.Scheduled_Id__c = ct.Id;


0

I think I figured it out. In my test classes I have used the annotation isTest, When I changed it to IsTest (note the capitalization), the plug-in started to identify my test methods. May be there is no "equalsIgnoreCase" in the plug-in code :-)


1

You are populating BatchSchedule__c.Scheduled_Id__c with a value that is not an Id. BatchSchedule__c batchSched = new BatchSchedule__c(); batchSched.Scheduled_Id__c = '1'; insert batchSched; Naturally when you ask the system to abort that nonexistent job, it fails: System.abortJob(b.Scheduled_Id__c); You need to populate that setting with an ...


1

Remove the try-catch block. It is not possible to have an exception here. Generally speaking, if you're having problems trying to cover a try-catch block, it is either untestable, or unnecessary. It's important to learn when exceptions can occur in order to catch them effectively. Also see Pokemon Catch - Generic Exception Handling In Apex and Test Code ...


0

I believe that the accepted answer here is incorrect. The accepted answer states that any DML statement within the context of @testSetup will not count against your overall test class limits but SOQL statements will. I tested this with something simple (in a scratch org, no other automation going on) @IsTest private class LimitTest { @TestSetup ...


4

Having all/most unit tests runAs users is usually overkill in most organizations. Permission requirements frequently change as roles, profiles, and permission sets are added and updated, so having lots of tests that rely on this may result in needing to deploy code changes to apply security permissions. This can quickly become unmanageable. I've always ...


0

As the other answers have mentioned, the DUPLICATE_DEVELOPER_NAME error suggests a conflict with an existing Group in the org. I found the following worked. It is likely that the DeveloperName I defined in the test was unique for the scratch org. The only other catch was inserting the GroupMember needed to be coded to avoid mixed DML operations. User ...


2

From your screenshot, looks like the fourth argument to the LifeLargeCaseReviewCtrl.createLLCRCase method should be a ContentDocumentid. Instead you are passing in ContentDocumentLink Id. Change LifeLargeCaseReviewCtrl.createLLCRCase(caseObj, policyList, propObj, cdl.Id); to LifeLargeCaseReviewCtrl.createLLCRCase(caseObj, policyList, propObj, documents[0].Id)...


1

I'm not sure that inserting a ContentVersion implicitly creates a ContentDocument that has an id that can be used in a cdl's ContentDocumentId field. Try creating one explicitly. Also, to see what type of object that id is actually of, try calling documents[0].Id.getSobjectType().getDescribe().getName()


2

Based on your other question here: can't seem to get proper code coverage. any ideas? your method returns a string. Test.startTest(); String returnData = LifeLargeCaseReviewCtrl.createLLCRCase(caseObj, policyList, propObj, cdl.Id); Test.stopTest(); System.assertEquals('Success', returnData, 'Case was not able to be created.');


0

2492/2496 = 99.84% It appears that sfdx is simply rounding that number up rather than showing any decimals. Beyond that, that 61% test run coverage is concerning.


0

I hope this helps you get started, it's not meant to be 100% the solution to your inquiry, but I hope it helps you. @IsTest private class invocableUpdateAgentCache_Test { @TestSetup private static void testSetup() { <--- Build your Required Records here ---> } @IsTest static void testBehavior() { <--- Do your ...


0

I don't know why but changing the RecordTypeId value in your csv file to 15 characters instead of 18 makes it work. 0120O0000003bewQAA ===> 0120O0000003bew


2

After a little more searching, I found this article: Unit Testing, Apex Enterprise Patterns and ApexMocks – Part 1 And reviewed the example code here: fflib_Application Which gave me inspiration for this: public with sharing class ServiceLocator { private static Map<Type, Object> mockLookup = new Map<Type, Object>(); @TestVisible ...


1

The field might be set to be required at the object level. You can modify the test created to include values for the pse__Assignment__c object that is inserted in the test. To do this, you should build the rollup in a sandbox first. Then you can edit the dlrs_pse_AssignmentTest class and modify the line dlrs.RollupService.testHandler(new pse__Assignment__c())...


Top 50 recent answers are included