1. Home
  2. /
  3. Apex Typing Test
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - Apex Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Counter {
public Integer count = 0;
public Boolean isDark = false;

public void updateUI() {
System.debug('Counter: ' + count);
System.debug('Theme: ' + (isDark ? 'Dark' : 'Light'));
}

public void increment() { count++; updateUI(); }
public void decrement() { count--; updateUI(); }
public void reset() { count = 0; updateUI(); }
public void toggleTheme() { isDark = !isDark; updateUI(); }
}

// Simulate actions
Counter c = new Counter();
c.updateUI();
c.increment();
c.increment();
c.toggleTheme();
c.decrement();
c.reset();
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Counter and Theme Toggle — Apex Code

Demonstrates a simple counter with theme toggling using Apex classes and console output (system debug).

public class Counter {
	public Integer count = 0;
	public Boolean isDark = false;

	public void updateUI() {
		System.debug('Counter: ' + count);
		System.debug('Theme: ' + (isDark ? 'Dark' : 'Light'));
	}

	public void increment() { count++; updateUI(); }
	public void decrement() { count--; updateUI(); }
	public void reset() { count = 0; updateUI(); }
	public void toggleTheme() { isDark = !isDark; updateUI(); }
}

// Simulate actions
Counter c = new Counter();
c.updateUI();
c.increment();
c.increment();
c.toggleTheme();
c.decrement();
c.reset();

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 Simple AdditionApex FactorialApex Fibonacci SequenceApex Max of Two NumbersApex Array SumApex Even Numbers FilterApex String ConcatenationApex Counter With Loop SimulationApex Conditional Increment

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher