6
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&...
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;
// ...
answered Jan 4 at 12:17
Robert Sösemann
31.4k1818 gold badges107107 silver badges334334 bronze badges
2
Thanks to @Robert Sösemann, I believe you can apply Facade logic for all Platform methods.
You can just change the return type to String, because all Ids are string, but not all strings are ID in apex.
public with sharing class SiteFacade {
@TestVisible
private static String strSiteId = 'DummySiteId';
public static String getSiteId(){
...
2
Not sure why you'd get an "infinite loop" run, but you've looked at the wrong example(s). You use the RestContext method when your main class uses it. For a parameterized call (e.g. @HttpPost), you call the method directly, just as you'd test any other method. You'd do something like this:
LeadManager.JSONLead testLead = (LeadManager.JSONLead)JSON....
2
You should be using an IDE. As it would have suggested its not Limit its Limits, so Limits.getCpuTime(), also I the just ran the code for testSetup, and it hardly took 400 ms to run. So i believe your org might be having either PB, or WF or Triggers on Leads. Its better to use a Log Analysis window to debug which process is taking time.
Generate your logs ...
2
Your text variable (the lightning-button) is null because it's absent from the DOM.
It's absent from the DOM because it's inside the <template if:true={showModalButton}> element. showModalButton, which controls that template element, is going to evaluate to false the way your code looks currently.
As far as I can see, the only way for showModalButton ...
1
Two immediate causes I can see and there may be others:
Your trigger (handler) is coded to respond to changes for a custom object called Attachment__c but your test is manipulating the standard Salesforce object Attachment.
Your test only does insert DMLs but your trigger (handler) starts with a guard that means it only responds to update DMLs.
1
David Reed's suggestion of switching from properties to member declarations is a good one. As the member declarations aren't considered something that requires code coverage you no longer need to test them.
Another alternative is to use a representative sample JSON payload in a tool like JSON2Apex. This will generate a test method that ensures the sample ...
answered Jan 14 at 2:02
Daniel Ballinger
93.6k2424 gold badges213213 silver badges507507 bronze badges
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
code-coverage × 1077apex × 693
unit-test × 672
trigger × 159
failing-tests × 76
deployment × 52
batch × 45
visualforce × 37
class × 36
code × 36
callout × 24
test-setup × 23
httpcalloutmock × 22
scheduled-apex × 20
salesforcedx × 18
rest-api × 16
controller × 16
developer-console × 16
schedulebatch × 10
wrapper-class × 10
community × 9
json × 9
exception × 9
apexrest × 9
tooling-api × 9