Salesforce Green Code: A Practical Guide to Sustainable Salesforce Development
Salesforce launched Green Code in 2023 to cut the carbon cost of building software. In 2026 the advice lives in Salesforce Well-Architected, and it reads like a checklist for a faster, cheaper org: bulkified Apex, selective queries, before-save flows, archived data and event-driven integrations. Here is what Green Code means, what it can and cannot change, and how admins, architects and developers apply it.
Key Takeaways
- Salesforce Green Code is a 2023 Salesforce initiative and guide for cutting the carbon emissions of the software development lifecycle. Its current form is the sustainability guidance in Salesforce Well-Architected, under Resource and Cost Optimization.
- On Salesforce, green code means doing the same work with fewer queries, less CPU time, less storage and fewer API calls. The same habits keep you inside governor limits and cut storage and integration costs.
- Salesforce is clear that one org's tuning does not directly cut data-centre emissions. The gain comes across all customers, so resource use is the honest proxy to track.
- The biggest levers are bulkified Apex, selective SOQL, before-save flows, retiring unused automation, archiving old data, and replacing polling with events.
- Measure with tools you already have: the Limits class and debug logs, the Query Plan tool, storage usage and, where licensed, Event Monitoring.
What is Salesforce Green Code? Salesforce Green Code is an initiative Salesforce launched in May 2023 to reduce the carbon emissions tied to building and running software. It came with a guide covering design and user experience, architecture, development and operations. For a Salesforce team, it means building solutions that do the same work with fewer server resources: fewer queries, less processing, less stored data and fewer calls between systems.
We first published this post in 2024 as a summary of the announcement. This version is rebuilt from Salesforce's own sources, checked in October 2026: the original guide, the current Well-Architected guidance, Apex, Flow and data documentation, and Salesforce's latest stakeholder impact report. It is written for admins, architects, developers and IT leaders at growing and mid-market companies who want an org that is faster and cheaper to run, with a lower footprint as part of the result.
What Is Salesforce Green Code, and Where Does the Guidance Live Now?
Green Code started as a Salesforce announcement and a downloadable guide in 2023, and its advice now sits inside Salesforce Well-Architected. The original guide is still published, but the current, maintained guidance is the sustainability section of Well-Architected's Resource and Cost Optimization area. Read the guide for the principles and Well-Architected for what to do in an org today.

Salesforce announced Green Code on May 4, 2023 as "a new initiative to help reduce carbon emissions associated with the software development lifecycle". The launch cited Salesforce research from the same year: in a YouGov survey of 1,059 technologists in the US, UK and Australia, 75% said they want to build software that does less harm to the environment, and 45% said they don't know how. That gap is what the guide set out to close.
| Source | Date | What it gives you |
|---|---|---|
| Sustainability Guide for Salesforce Technology (PDF) | 2023, not revised since | Principles in four areas, with examples and suggested KPIs |
| Green Code Quick Look (Trailhead) | 2023 | A 10-minute introduction to the initiative and the guide |
| Well-Architected: Resource and Cost Optimization | Current | The maintained guidance: sustainability, efficiency patterns, anti-patterns and a checklist |
Does Green Code in Your Salesforce Org Actually Cut Carbon?
Indirectly, and Salesforce says so plainly. Salesforce runs the data centres, so one customer's efficient code does not switch off a server. Efficiency across all customers lets Salesforce run its infrastructure at higher utilisation and delay adding capacity. That is why Well-Architected treats queries, CPU time, heap and storage as proxy measures for sustainability.
Well-Architected describes this as a shared responsibility. Salesforce manages power usage effectiveness, cooling and hardware. You control "the resource consumption patterns of your solutions within that multitenant environment". The guidance is explicit that "a single tenant's optimizations don't directly reduce data center emissions". Be wary of any vendor that promises a carbon figure for tuning your org.
What your team controls: how much work each transaction does, how much data you keep, how often systems poll each other, which automation still runs, and how large your AI prompts and models are. Every one of these also shows up as performance, limits headroom or cost.
What Salesforce controls: the data centres, their energy sourcing and efficiency, and where Hyperforce runs. Inside your org you cannot choose the electricity grid, so carbon-aware scheduling means running heavy jobs in quiet hours, not chasing renewable peaks.
What Salesforce reports about its own footprint
The figures in the 2024 version of this post were from 2023. Here is how they read now, from Salesforce's FY26 Stakeholder Impact Report (February 2025 to January 2026) and its earlier Green Code material.
| Claim | What Salesforce states |
|---|---|
| Carbon to Serve | Salesforce's metric for the emissions it takes to deliver a service, covering software efficiency, data-centre power usage effectiveness and grid carbon. Salesforce reported a 26% reduction between 2020 and 2023, with a goal of 10% a year. The FY26 report no longer uses the term. |
| Infrastructure efficiency | Infrastructure is about 21% of Salesforce's market-based emissions. Salesforce owns no data-centre buildings, says Hyperforce on public cloud "can be 40% more efficient" than the colocated facilities it leases, and reports a 4% year-over-year gain in carbon efficiency in FY26. |
| Renewable energy | Salesforce buys renewable electricity or certificates equal to 100% of the electricity it uses globally, every year since FY22. This is an annual match across operations, not a statement that every Hyperforce region runs on renewable power. |
| Emissions trend | A 66% cut in scope 1 and 2 emissions and a 67% cut in scope 3 emissions intensity against its science-based target baseline (FY19). |
| MuleSoft example | MuleSoft cut its yearly public cloud infrastructure spending by 14% by decommissioning underused systems and moving storage to more efficient options. This is a cost figure, not an emissions figure. |
What Are the Four Areas of the Salesforce Sustainability Guide?
Design and UX, Architecture, Development and Operations. Each one asks the same question at a different stage: can this be done with less? Fewer screens and page loads, fewer integrations and polls, fewer queries and loops, and fewer idle environments and wasted job runs. Here is each area, with what it means in a Salesforce org in 2026.
Fewer steps, lighter pages
Make sustainability a design requirement. Cut steps from user journeys, combine screens and reduce page loads. Build on the Lightning Design System so improvements to the framework reach every app. The guide warns that "dynamic elements that continuously ping a server" add traffic and computing load. In practice: lean Lightning pages, fewer components per page, and no auto-refreshing widgets nobody watches.
Reuse, events and data lifecycle
Prefer reusable APIs to point-to-point integrations, push events instead of polling, limit fields and rows with pagination, and set retention policies so unneeded data is deleted. The guide also frames governor limits as a sustainability control: they stop runaway code from monopolising shared resources on the multitenant platform.
Efficient code and client-side caching
Use bulk patterns in Apex, keep SOQL and DML out of loops, avoid nested loops and drop unused dependencies. On the front end, the guide reports that Lightning Web Components showed a 2–60% decrease in Experience Page Time compared with Aura components, and points to Lightning Data Service and cacheable Apex methods for client-side caching.
No idle environments, smarter scheduling
Clean up sandboxes regularly and give scratch orgs short lives: they expire after 7 days by default, and you can set 1 to 30 days. The guide's advice on instance sizing, spot instances and low-carbon regions applies to workloads you host yourself, such as MuleSoft runtimes. Inside Salesforce, operations means scheduling and monitoring jobs well.
How Do You Write Green Apex, SOQL and Lightning Web Components?
Do each piece of work once, for many records, with only the data you need. Bulkify triggers, query outside loops, select only the fields you use, make queries selective, cache what does not change, and move heavy work to asynchronous Apex. These are standard Salesforce best practices; Green Code adds a second reason to follow them.
| Practice | What to do | Limit or cost it protects |
|---|---|---|
| Bulkify triggers | Collect IDs in sets, query once, hold results in maps, and do one DML per object. Triggers receive records in batches of up to 200. | 100 SOQL queries and 150 DML statements per synchronous transaction |
| Select only needed fields | No "select everything" habits. Query the fields the logic uses. | Heap: 10 MB synchronous, 25 MB asynchronous |
| Make queries selective | Filter on indexed fields and check the plan in the Query Plan tool before running against large objects. | Query timeouts and full table scans on large data volumes |
| Process large sets in chunks | Use SOQL for loops or Batch Apex for large result sets. | 50,000 rows retrieved per transaction |
| Go asynchronous for heavy work | Move complex calculations to Queueable or Batch Apex. | CPU time: 10,000 ms synchronous, 60,000 ms asynchronous |
| Cache on the client and server | Use Lightning Data Service, cacheable Apex and Platform Cache for reference data read again and again. | Repeated server round trips and repeated queries |
Limits from Salesforce's Apex governor limits reference; patterns from the bulk trigger idioms and the Trailhead Bulk Apex Triggers unit. Well-Architected calls query selectivity "the single largest lever on whether a solution scales to millions of records". Salesforce's Query Plan tool article explains how to see whether a query uses an index or scans the whole table. For the async options, our guide to asynchronous Apex covers Batch Apex, future methods and Queueable Apex.
Lightning Web Components
Before calling the server, check whether the data is already available. Salesforce's LWC performance best practices recommend Lightning Data Service or caching wherever possible, requesting only the fields a component shows, and avoiding metadata-heavy calls unless you need them. Mark read-only Apex methods as cacheable, and paginate lists instead of loading every row. If you still run Aura components, migrating the busiest ones to LWC is the change the guide links to faster pages.
How Can Salesforce Admins Make Flows and Automation More Efficient?
Use before-save flows for same-record updates, keep one entry point per object, and switch off automation nobody needs. Most org waste is not exotic code. It is after-save flows that update the record that triggered them, overlapping automation on the same object, and processes still running years after the business stopped using them.
For a deeper look at building flows well, see our Salesforce Flow guide for admins.
How Do Data Retention and Archiving Reduce Your Salesforce Footprint?
Data you keep is data the platform stores, indexes, backs up and scans. A retention policy decides what to keep, for how long and where. Archive aged records out of busy objects, delete what you are allowed to delete, and keep test environments short-lived. Your queries get faster, and storage costs stop growing.
Both the 2023 guide and Well-Architected say to define retention or lifecycle policies so unneeded data is deleted in good time. Well-Architected's specific patterns are to archive aged records to Big Objects or external storage on a schedule, hard delete when compliant instead of leaving records in the Recycle Bin, and set Field Audit Trail retention field by field. It also flags a compliance catch: Big Object records cannot be modified after insert, so deleting archived personal data later means deleting and recreating records. Plan privacy requests before you archive.
Why Should Salesforce Integrations Use Events Instead of Polling?
Because most polls find nothing new. Salesforce's sustainability guide states that 98.5% of API polls return no new information, and recommends a push mechanism wherever possible. With Change Data Capture or platform events, the other system hears about a change when it happens, instead of asking every few minutes and spending an API call each time.
Events, not polling
Well-Architected names Change Data Capture and other event-driven patterns as the way to remove polling calls.
Fewer, bigger calls
Composite API groups several operations into one call, and Bulk API v2 handles large volumes far more efficiently than thousands of single REST calls.
Staggered jobs
Schedule archiving, enrichment and clean-up for low-usage windows, and stagger jobs instead of launching 20 at midnight.
Reusable APIs are the other architecture point in the guide: one well-designed API used by many systems, instead of a new point-to-point link for each. That is the approach behind MuleSoft's API-led connectivity. Our MuleSoft integration best practices cover it in detail, and our integration services design and rebuild integrations across Salesforce, HubSpot and ERP systems.
How Does Green Code Apply to Agentforce and AI Features?
Every prompt, retrieval and model call uses compute, so size them to the task. Well-Architected asks teams to keep prompts short, summarise conversation history instead of resending it, use the smallest model that does the job well, and retrieve only the results the agent will actually use. Its example: retrieving 50 vector-search results when only 5 are evaluated wastes resources.
Salesforce has also worked on measuring this. In February 2025 it launched the AI Energy Score with Hugging Face, Cohere and Carnegie Mellon University, a public rating of AI models' energy efficiency. In practice, the green choices in an Agentforce rollout are the same ones that control cost and response time: clear topics, focused instructions, grounded data with tight retrieval, and actions that query only what they need. Our Agentforce optimization service tunes agents after go-live with these trade-offs in mind.
How Do You Measure Green Code Progress in Salesforce?
Track resource use per transaction and per month, and set thresholds. Count SOQL queries, CPU time and heap for key transactions, storage growth month by month, API calls by integration, and how many automations actually run. Well-Architected recommends actionable thresholds, such as a target SOQL count per transaction or a monthly storage growth limit.
| What to measure | Tool | Notes |
|---|---|---|
| Queries, DML, CPU and heap per transaction | Debug logs and the Apex Limits class | Available in every org; capture a baseline for your busiest processes |
| Query selectivity | Query Plan tool in the Developer Console | Check before deploying queries on large objects |
| Storage growth | Setup › Storage Usage | Watch the largest objects and their monthly growth |
| CPU time at scale | Event Monitoring, with the open-source Developer Carbon Dashboard | Needs Event Monitoring and CRM Analytics; the dashboard converts CPU time to an estimate using carbon coefficients (published 2023) |
| Your own hosted apps | Green Software Foundation Software Carbon Intensity | A standard (ISO/IEC 21031:2024) for scoring the carbon per unit of work of software you run |
| Company-wide emissions | Agentforce Net Zero (formerly Net Zero Cloud) | Carbon accounting and reporting under the Greenhouse Gas Protocol; a separate job from code efficiency |
The Green Software Foundation sums up the field in three activities that reduce software emissions: energy efficiency, carbon awareness and hardware efficiency. On Salesforce, the first is where your team has the most control.
What Does a 90-Day Green Code Plan for a Salesforce Org Look Like?
Baseline first, then remove waste, then build the habit. Start by measuring the busiest transactions, largest objects and noisiest integrations. Fix the items that are both wasteful and risky, such as code near governor limits. Then add the checks to code review and release so new work stays efficient.
| Phase | Work | Done when |
|---|---|---|
| Days 1–30: Baseline | Inventory automation per object; list storage by object; list integrations with their call volumes; profile the five busiest transactions | A baseline sheet with thresholds you agree on |
| Days 31–60: Remove waste | Deactivate unused automation; migrate remaining Process Builders; convert same-record updates to before-save; fix non-selective queries; agree retention rules | Fewer automations per object and more limits headroom on key transactions |
| Days 61–90: Make it stick | Replace a polling integration with events; schedule archiving; add selectivity, bulk and caching checks to code review; plan the next quarterly audit | Green checks are part of every release |
An independent review speeds up the first 30 days. Our Salesforce health check covers automation, code, data and integrations, and our Salesforce developers can carry out the refactoring. Twopir Consulting also publishes its own sustainability commitments, including a net-zero goal.
Mistakes to avoid
The Bottom Line
Salesforce Green Code is good engineering with a sustainability reason attached. The same habits that lower your org's resource use also keep it inside governor limits, speed up pages, slow storage growth and cut integration costs. Twopir Consulting helps growing and mid-market companies audit and optimize their Salesforce orgs. We implement, rescue, optimize, and integrate complex CRM and revenue systems.
- 1
Use Well-Architected's Resource and Cost Optimization guidance as your current Green Code reference.
- 2
Bulkify, query selectively, cache, and move heavy work to async Apex.
- 3
Use before-save flows, keep one entry point per object, and retire unused automation every quarter.
- 4
Set retention rules, archive aged data, and clean up sandboxes.
- 5
Replace polling with events, and measure resource use against agreed thresholds.
Find the Waste in Your Salesforce Org
Tell us where your org feels slow, close to its limits or expensive to run. We will review your automation, code, data and integrations and show you where to start.
Schedule a Discovery CallFrequently Asked Questions
Salesforce Green Code is an initiative Salesforce launched in May 2023 to reduce the carbon emissions of the software development lifecycle. It came with the Sustainability Guide for Salesforce Technology, covering design and UX, architecture, development and operations. The current guidance sits in Salesforce Well-Architected, under Resource and Cost Optimization.
The 2023 guide is still published and its principles still hold, but it has not been revised. Salesforce now maintains its sustainability advice in the Well-Architected Resource and Cost Optimization area, which adds current patterns such as quarterly automation audits, Process Builder migration and AI prompt efficiency.
Only indirectly. Salesforce runs the data centres, and its Well-Architected guidance states that a single tenant's optimizations do not directly reduce data-centre emissions. Efficiency across all customers lets Salesforce run at higher utilisation, so queries, CPU time, heap and storage serve as proxy measures. The direct benefits to you are performance, limits headroom and lower cost.
Convert same-record flow updates to before-save, deactivate automation with no executions in 90 days, migrate remaining Process Builders to Flow, fix non-selective queries on large objects, bulkify triggers that query inside loops, archive aged records, and replace polling integrations with Change Data Capture or platform events.
Salesforce's sustainability guide describes governor limits as a guard against inefficient, carbon-intensive use of the shared multitenant platform, because they stop runaway code from monopolising resources. Code designed to stay well inside the limits, such as bulkified Apex with selective queries, is also code that uses fewer server resources.
Salesforce does not state that today. Hyperforce runs on public cloud providers such as AWS and Google Cloud. Salesforce reports that it procures renewable electricity or certificates equal to 100% of the electricity it uses globally, matched annually, and that Hyperforce can be 40% more efficient than the colocated facilities it leases.
Measure resource use: SOQL queries, CPU time and heap per transaction from debug logs or the Limits class, query selectivity in the Query Plan tool, storage growth in Storage Usage, and API calls per integration. Teams with Event Monitoring and CRM Analytics can use Salesforce's open-source Developer Carbon Dashboard for an estimate.
Agentforce Net Zero, formerly Net Zero Cloud, is Salesforce's carbon accounting product. It converts energy, travel and other activity data into emissions under the Greenhouse Gas Protocol and supports reporting frameworks such as CSRD, SASB, GRI and CDP. It measures a company's footprint; it does not optimize Salesforce code.
Twopir Consulting
Twopir Consulting helps growing and mid-market companies solve complex CRM, integration, and business system challenges. We implement, rescue, optimize, and integrate complex CRM and revenue systems, from Apex and Flow refactoring to integration redesign, for 500+ clients over 12+ years.