New answers tagged

5

Salesforce has a governor limits! In a single apex execution context, you can only do 150 DML operations. Being a beginner to apex I suggest you read through some of the best practices highlighted here Instead of doing DML in a loop, use List to collect all objects and perform one DML instead. @isTest public static void testScenario(){ List<Account&...


0

While the other two answers are technically correct, that you can write extra code to somewhat replace the System.isFuture invocation during the test, I think you can write code in your test method that runs on both situations. If your class or method is being called from a scheduled, queueable or batchable context, you can easily test those sync and async ...


-1

Test.stopTest(); always converts your async code in sync manner and executes. If that is the code snippet in your code base then one option is to introduce a boolean variable like this in your class. public class TestClass{ public static boolean BOOL_TEST_FUTURE = true; public static void main() { if (System.isFuture() || ...


6

You can solve that exactely like you solve many other aspects that are hard or impossible to test, like Multicurrency or strange org settings. You let your production code talk to a Facade SystemFacade.isFuture() instead The Facade uses a mock during tests public with sharing class SystemFacade { @TestVisible private static Boolean isFuture = false; // ...


0

First of all, the error is quite clear: Opportunity.Pricebook2Id has no child PriceBookEntry record corresponding to customPrice.Id No, as to why it fails in PROD deployment rather than sandbox, I can think of two likely possibilities: Your test method is not mocking Pricebooks, Products, and PricebookEntries but instead relying on org data and these are ...


Top 50 recent answers are included