1. Home
  2. /
  3. Apex
  4. /
  5. Conditional Increment

Conditional Increment - Apex Typing CST Test

Loading…

Conditional Increment — Apex Code

Increment counter only if below 5.

public class ConditionalIncrement {
	public void run() {
		Integer count = 3;
		if(count < 5) count++;
		System.debug('Counter: ' + count);
	}
}

ConditionalIncrement ci = new ConditionalIncrement();
ci.run();

Apex Language Guide

Apex is a strongly typed, object-oriented programming language developed by Salesforce for building scalable, secure, and automated applications on the Salesforce platform. It allows developers to execute business logic on the server side, integrate external systems, and customize CRM workflows using a syntax similar to Java.

Primary Use Cases

  • ▸Salesforce triggers & automation
  • ▸Custom REST & SOAP APIs
  • ▸Batch & scheduled jobs
  • ▸Complex CRM business logic
  • ▸Integrations with external systems
  • ▸Custom Salesforce Apps & packages

Notable Features

  • ▸Java-like syntax
  • ▸Strong typing & OOP design
  • ▸Built-in Salesforce data access (SOQL/SOSL)
  • ▸Asynchronous processing
  • ▸Governor limits for resource control

Origin & Creator

Apex was introduced by Salesforce in 2006 as a proprietary cloud-based programming language enabling customization of the Force.com platform.

Industrial Note

Apex is widely used in enterprise CRM automation, financial workflow engines, healthcare records management, SaaS integrations, and large-scale automation pipelines inside Salesforce.

Quick Explain

  • ▸Apex runs natively on Salesforce servers and is optimized for multitenant architecture.
  • ▸It supports asynchronous processing, triggers, and declarative automation integration.
  • ▸Used to build custom business logic, APIs, batch processes, and advanced CRM customizations.

Core Features

  • ▸Classes & objects
  • ▸Triggers for automation
  • ▸SOQL/SOSL queries
  • ▸Batch Apex, Queueable Apex, Scheduled Apex
  • ▸Exception handling & testing framework

Learning Path

  • ▸Learn Salesforce fundamentals
  • ▸Master SOQL & DML
  • ▸Write triggers
  • ▸Learn async Apex
  • ▸Integrate external systems

Practical Examples

  • ▸Before/after insert trigger
  • ▸REST API endpoint
  • ▸Batch job processing thousands of records
  • ▸Scheduled Apex cleanup
  • ▸CRUD operations with SOQL

Comparisons

  • ▸Similar syntax to Java
  • ▸More restricted due to governor limits
  • ▸Cloud-executed vs local execution
  • ▸Deep CRM integration unlike general languages
  • ▸Strict testing requirements

Strengths

  • ▸Native integration with Salesforce objects
  • ▸Secure, scalable execution
  • ▸Excellent tooling and test framework
  • ▸Great for enterprise automation
  • ▸Powerful asynchronous capabilities

Limitations

  • ▸Vendor lock-in to Salesforce ecosystem
  • ▸Strict governor limits
  • ▸Cannot interact with system file I/O
  • ▸Restricted multithreading
  • ▸Must follow Salesforce deployment rules

When NOT to Use

  • ▸Front-end UI work (use LWC/Aura)
  • ▸Heavy ML computation
  • ▸File processing
  • ▸Desktop apps
  • ▸Systems that need OS-level access

Cheat Sheet

  • ▸SELECT Id, Name FROM Account;
  • ▸insert new Account(Name='Test');
  • ▸System.debug('Log');
  • ▸Test.startTest(); ... Test.stopTest();
  • ▸@future callout=true

FAQ

  • ▸Is Apex only for Salesforce?
  • ▸Yes - it runs exclusively on the Salesforce platform.
  • ▸Does Apex support multithreading?
  • ▸No - but async patterns exist.
  • ▸Do I need Java to learn Apex?
  • ▸No - but Java experience helps.
  • ▸Can Apex be used for APIs?
  • ▸Yes - REST & SOAP support built-in.

30-Day Skill Plan

  • ▸Week 1: Apex basics & SOQL
  • ▸Week 2: Triggers & bulkification
  • ▸Week 3: Async Apex (Batch/Queueable)
  • ▸Week 4: Integrations & APIs

Final Summary

  • ▸Apex is Salesforce's server-side programming language for enterprise automation.
  • ▸Ideal for CRM logic, integrations, API building, and workflow automation.
  • ▸Subject to governor limits requiring optimized coding patterns.
  • ▸Core technology for scalable Salesforce development.

Project Structure

  • ▸classes/
  • ▸triggers/
  • ▸testClasses/
  • ▸objects/ (metadata)
  • ▸lwc/ or aura/ for UI

Monetization

  • ▸Freelance Salesforce automation
  • ▸Custom app development
  • ▸Integration services
  • ▸Enterprise consulting
  • ▸AppExchange products

Productivity Tips

  • ▸Use VS Code shortcuts
  • ▸Automate deployments with SFDX
  • ▸Create reusable utility classes
  • ▸Follow naming conventions
  • ▸Use logs for debugging

Basic Concepts

  • ▸Classes, methods, and objects
  • ▸Triggers and automation events
  • ▸Governor limits
  • ▸SOQL/SOSL queries
  • ▸Asynchronous execution (Batch, Future, Queueable)

Official Docs

  • ▸Salesforce Apex Developer Guide
  • ▸SOQL & SOSL Reference
  • ▸Salesforce CLI Reference

More Apex Typing Exercises

Apex Counter and Theme ToggleApex Simple AdditionApex FactorialApex Fibonacci SequenceApex Max of Two NumbersApex Array SumApex Even Numbers FilterApex String ConcatenationApex Counter With Loop Simulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher