Skip to main content

Posts

Showing posts with the label Apex

Parsing Complex CSVs and JSON in Salesforce using DataWeave in Apex

  Processing multi-megabyte CSV files or deeply nested JSON architectures directly within Salesforce has historically been a perilous task. Developers frequently encounter   System.LimitException: Too many heap size   or   System.LimitException: Apex CPU time limit exceeded   when attempting to parse and transform this data. Traditional approaches relying on standard string manipulation or regex fail to scale gracefully. By leveraging DataWeave in Apex, data engineers and Salesforce developers can offload complex payload transformations to a purpose-built engine, drastically reducing CPU time and memory consumption. The Core Problem: Heap Limits and Immutable Strings To understand why it is so difficult to parse CSV Salesforce Apex implementations natively, we must look at how the JVM-backed Apex runtime manages memory. Strings in Apex are immutable. When you attempt to parse a CSV using  String.split('\n') , the runtime does not simply place pointers acros...

Solving 'Mixed DML Operation' Errors in Salesforce Apex Test Classes

  Encountering a   System.DmlException: MIXED_DML_OPERATION   is a strict blocker during Salesforce deployments. This error occurs when a developer attempts to perform Data Manipulation Language (DML) operations on both Setup objects and Non-Setup objects within the exact same transaction. In a testing environment, this typically manifests when provisioning a test user (Setup object) and immediately creating test records like Accounts or Opportunities (Non-Setup objects) assigned to that user. Resolving this requires explicit manipulation of transaction contexts. The Root Cause of Mixed DML Operation Exceptions To understand the fix, you must understand the platform's architecture. Salesforce categorizes database entities into two primary groups: Setup Objects:  Objects that affect system security, access controls, and organization structure (e.g.,  User ,  UserRole ,  Profile ,  PermissionSet ,  Group ). Non-Setup Objects:  Standard and...