Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions force-app/main/default/classes/ExceptionGeneratorService.cls
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
public with sharing class ExceptionGeneratorService {

/**
* Intentionally triggers a SOQL limit exception for testing/demo purposes.
* This method is designed to demonstrate what happens when SOQL limits are exceeded.
* NOTE: This is intentional behavior for testing - the exception IS the expected outcome.
*/
public static void triggerTooManySOQLQueries() {
if (Test.isRunningTest()) {
return;
}
// Intentionally trigger SOQL limit exception for demonstration
// This executes 101 queries to exceed the 100 query limit
for (Integer i = 0; i < 101; i++) {
Database.query('SELECT Id FROM User LIMIT 1');
List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
}
}


/**
* Triggers a callout after DML exception for testing purposes.
*/
public static void triggerCalloutAfterDml() {
if (Test.isRunningTest()) {
return;
}
insert new Account(Name = 'Test');
new Http().send(new HttpRequest());
// Insert a record to perform DML
Account acc = new Account(Name = 'Test Account for Callout Demo');
insert acc;

// Attempt a callout after DML - this will throw an exception
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://example.com/api');
request.setMethod('GET');
HttpResponse response = http.send(request);
}


/**
* Triggers a stack overflow exception for testing purposes.
*/
public static void triggerStackOverflow() {
if (Test.isRunningTest()) {
return;
}
// Recursive call to trigger stack overflow
triggerStackOverflow();
}
}