1. Home
  2. /
  3. Salesforce-apex
  4. /
  5. Apex Class - Call Salesforce Internal API (SOQL + DML)

Apex Class - Call Salesforce Internal API (SOQL + DML) - Salesforce-apex Typing CST Test

Loading…

Apex Class - Call Salesforce Internal API (SOQL + DML) — Salesforce-apex Code

Custom Apex class that queries Accounts and updates a field based on logic.

public class AccountUpdater {
	public static void normalizeAccounts() {
		List<Account> accs = [SELECT Id, Name FROM Account WHERE Name LIKE 'Test%'];
		for (Account a : accs) {
		a.Name = a.Name.replace('Test', '');
		}
		update accs;
	}
}

Salesforce-apex Language Guide

Salesforce Apex is a strongly typed, Java-like programming language used to implement custom business logic on the Salesforce Platform. It provides server-side execution within the multi-tenant Salesforce environment, enabling automation, integrations, transactional operations, and advanced customization beyond declarative tools.

Primary Use Cases

  • ▸Trigger-based automation for complex business rules
  • ▸Custom REST/SOAP services for integrations
  • ▸Batch and async processing for high-volume data jobs
  • ▸Custom Lightning Web Component (LWC) backend controllers
  • ▸Transactional orchestration and advanced validation logic

Notable Features

  • ▸Java-like syntax with Salesforce-specific data types and SObjects
  • ▸Trigger framework support for scalable event handling
  • ▸Built-in test framework with mandatory code coverage
  • ▸Async processing: Queueable, Batchable, Future, Scheduled
  • ▸First-class integration support (REST, SOAP callouts)

Origin & Creator

Created by Salesforce to allow controlled, secure server-side programming on the CRM platform, evolving since 2006 alongside the Force.com ecosystem.

Industrial Note

Large enterprises rely heavily on Apex to implement governed workflows, ERP-like processes, and integrations across distributed systems.

Quick Explain

  • ▸Apex extends point-and-click Salesforce capabilities with programmatic logic.
  • ▸It supports triggers, async jobs, web services, complex validations, and transaction control.
  • ▸Runs inside the Salesforce multi-tenant environment with strict governor limits.
  • ▸Often combined with declarative tools (Flows, Process Builder) to implement robust enterprise logic.
  • ▸Core to developing scalable, enterprise-grade applications on Salesforce.

Core Features

  • ▸DML and SOQL for data access
  • ▸Triggers to handle record lifecycle events
  • ▸Apex classes for reusable business logic
  • ▸Governor limit enforcement for multi-tenant safety
  • ▸Apex Tests and mock callouts for integration validation

Learning Path

  • ▸Master SOQL, DML, SObject basics
  • ▸Learn triggers and bulkification
  • ▸Practice writing and mocking tests
  • ▸Build async logic: Queueable, Batch, Scheduled
  • ▸Create REST APIs and integration patterns

Practical Examples

  • ▸Auto-assigning Leads based on weighted scoring rules
  • ▸Bulk invoice creation using Batch Apex
  • ▸Custom REST endpoint consumed by external ERP
  • ▸Queueable job that syncs high-volume opportunity updates
  • ▸Trigger framework enforcing global validation rules

Comparisons

  • ▸Apex vs Flows: Apex for complex logic; Flows for rapid development
  • ▸Apex vs LWC JS: Apex is server-side; LWC JS is client-side UI logic
  • ▸Apex vs Java: Apex runs inside Salesforce with strict limits
  • ▸Apex vs External Microservices: Apex handles CRM logic, microservices handle heavy compute
  • ▸Apex vs Triggers-only: Apex classes enable better abstraction and scaling

Strengths

  • ▸Fully native to Salesforce - high performance and strong ecosystem integration
  • ▸Transaction-safe with rollback and savepoint APIs
  • ▸Enterprise-ready integration patterns supported out-of-the-box
  • ▸Strong metadata-driven development experience
  • ▸Pairs well with declarative automation for hybrid workflows

Limitations

  • ▸Governor limits require careful design and optimization
  • ▸Cannot interact directly with external systems without callouts
  • ▸Multi-tenant architecture restricts unrestricted resource use
  • ▸Debugging large-scale automation requires strong logging discipline
  • ▸Deployment requires test success - higher initial development overhead

When NOT to Use

  • ▸When declarative automation (Flow) can fully handle logic
  • ▸For heavy ETL jobs better handled externally
  • ▸Operations that exceed synchronous governor limits
  • ▸Building large-scale UI logic better suited for LWC
  • ▸For complex reporting better suited to Analytics/BI tools

Cheat Sheet

  • ▸Always bulkify triggers
  • ▸Use SOQL limits: 100 queries per transaction
  • ▸Use @testSetup for reusable test data
  • ▸Prefer Queueable over Future
  • ▸Check CRUD/FLS with Security.stripInaccessible

FAQ

  • ▸Is Apex required? -> For complex logic, yes.
  • ▸Can Apex bypass limits? -> No; limits enforce multi-tenancy.
  • ▸Do Flows replace Apex? -> For simple use cases only.
  • ▸Can Apex call external APIs? -> Yes via callouts.
  • ▸Is 75% test coverage mandatory? -> Yes for deployment.

30-Day Skill Plan

  • ▸Week 1: Apex fundamentals, SOQL/SOSL
  • ▸Week 2: Triggers and frameworks
  • ▸Week 3: Async Apex and callouts
  • ▸Week 4: LWC + Apex controllers
  • ▸Week 5: Packaging, CI/CD, and performance tuning

Final Summary

  • ▸Apex is Salesforce’s server-side language for enterprise automation.
  • ▸Requires careful design due to governor limits and multi-tenancy.
  • ▸Combines strongly with declarative tools for hybrid solutions.
  • ▸Ideal for complex integrations, validations, and async jobs.
  • ▸Strong testing and CI/CD practices are key to success.

Project Structure

  • ▸force-app/main/default/classes - Apex classes
  • ▸force-app/main/default/triggers - Trigger files
  • ▸force-app/main/default/lwc - Lightning Web Components
  • ▸config/ - Org configuration and scratch org definitions
  • ▸tests/ - Apex Test Classes

Monetization

  • ▸Apex developers in high demand for enterprise Salesforce work
  • ▸Consulting firms leverage Apex for custom CRM/ERP transformations
  • ▸Independent ISVs monetize managed packages
  • ▸Training and certification opportunities
  • ▸Plugins, accelerators, and frameworks sold commercially

Productivity Tips

  • ▸Use trigger frameworks (e.g., TDTM, fflib)
  • ▸Use VS Code snippets
  • ▸Create reusable utility classes
  • ▸Follow consistent naming conventions
  • ▸Test early and automate CI/CD

Basic Concepts

  • ▸SObject - Salesforce data model entity
  • ▸Trigger - Automatically executed logic tied to DML events
  • ▸DML - Data Manipulation Language for insert/update/upsert
  • ▸SOQL - Salesforce Object Query Language
  • ▸Governor Limits - Runtime constraints per transaction

Official Docs

  • ▸https://developer.salesforce.com/docs/
  • ▸Salesforce Apex Developer Guide
  • ▸Salesforce Lightning Platform API documentation

More Salesforce-apex Typing Exercises

Apex Trigger - Enforce Validation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher