Skip to main content

Best Practices to Avoid Security Vulnerabilities in Salesforce Development

About Us
Published by JET BI
21 November 2024
17

How to Prevent Security Vulnerabilities in Salesforce Development

 

Introduction

Salesforce acts as the foundation for numerous businesses, facilitating effective customer relationship management (CRM), simplified processes, and innovative connections. It also enables organizations to store confidential customer information, which also requires ensuring the platform's security. Developers and administrators can protect their Salesforce environments by being aware of vulnerabilities such as SOQL Injection, Data Access Control Issues, Third-Party Content Risks, Cross-Site Scripting (XSS), and Cross-Site Request Forgery (CSRF) and taking proactive measures. 

This article discusses common security vulnerabilities in Salesforce development and effective methods to avoid them.

SOQL Injection

Salesforce Object Query Language Injection occurs when attackers manipulate query strings in SOQL to gain unauthorized access to data or manipulate the database. This often happens when unvalidated user inputs are directly included in dynamic SOQL queries.

Techniques to Prevent SOQL Injection:

  • Use Static Queries: Wherever possible, use static queries rather than dynamic ones. Static queries are predefined and not influenced by user input.
  • Escape User Inputs: If dynamic queries are unavoidable, use String.escapeSingleQuotes() to sanitize user inputs, preventing harmful characters from being executed in the query.
  • Parameterized Queries: Leverage bind variables in Apex code to ensure user inputs are treated as data rather than executable code.
  • Input Validation: Implement robust input validation to restrict the format, length, and type of input users can provide.
String queryString = 'SELECT Id FROM Account WHERE Name LIKE \'%' + name + '%\')';
Database.query(queryString);

//To fix this vulnerability, static queries and variable binding are used: 
String queryName = '%' + name + '%'; 
queryResult = [SELECT Id FROM Account WHERE Name LIKE :queryName)];

 

Data Access Control Issues

Improperly configured access controls can lead to unauthorized data exposure. Users or integrations may gain access to sensitive records they shouldn't view or modify.

Techniques to Prevent Data Access Control Issues:

  • Enforcing Object and Field Permissions: Configure appropriate field- and object-level security to restrict access based on user roles. Object-level and field-level permissions can be enforced through code by explicitly using sObject and field describe result methods:

OBJECT-LEVEL: Schema.sObjectType.Lead.isDeletable()

FIELD-LEVEL: Schema.sObjectType.Lead.fields.Company.isUpdateable()

  • Sharing Rules and Role Hierarchies: Implement sharing rules to govern how data is distributed and accessed across users and teams. Role hierarchies should align with organizational structures.
  • Use “With Sharing” Keyword: In Apex classes, enforce sharing rules by using the “with sharing” keyword to ensure that the code respects access permissions defined for the user.
  • Audit Access Regularly: Periodically review profiles, permission sets, and sharing rules to ensure they align with current security policies.
  • Secure Retrieval and Display of Third-Party Content: Visualforce provides methods to safely display third-party content on the page such as IMAGEPROXYURL: <apex:image value="{!IMAGEPROXYURL('http://somedomain.com/pic.png')}"/>. HTML static resources can be isolated on a separate domain using iframes to protect Visualforce content from untrusted sources.

 

Third-Party Content Issues

Integrations and embedded third-party content may introduce vulnerabilities such as data leakage or reliance on untrusted sources.

Techniques to Prevent Third-Party Content Issues:

  • Verify Third-Party Vendors: Assess the security posture of third-party applications before integration. Review their compliance certifications, penetration test reports, and data handling policies.
  • Securing Sensitive Data: Salesforce provides multiple options for securing sensitive data such as passwords, encryption keys, OAuth tokens, etc. Sensitive data can be stored using the declarative features: protected custom metadata types, protected custom settings, encrypted custom fields, named credentials. Data can be programmatically secured through encryption and decryption.
  • Content Security Policy (CSP): Use Salesforce’s Content Security Policy settings to control which domains can interact with your Salesforce instance.
  • Sandbox Testing: Test integrations in a sandbox environment before deploying to production. This helps identify potential security issues without risking live data.

 

Cross-Site Scripting (XSS)

XSS vulnerabilities occur when attackers inject malicious scripts into web pages viewed by other users. In Salesforce, this often targets Visualforce pages, Lightning components, or custom UI elements.

Techniques to Prevent Cross-Site Scripting (XSS):

  • Use Standard Components: Prefer standard Lightning and Visualforce components whenever possible, as these are inherently secure. All standard Visualforce components, which start with <apex> have anti-XSS filters in place.
  • Strict Input Validation: Only allow specific, expected input formats and lengths, especially for form fields. Note that labels of <apex:inputField> tags are automatically escaped for security.
  • Escape User Inputs: Use Salesforce-provided encoding functions to sanitize user inputs displayed in UI elements.
  • Output Filters: Salesforce has implemented filters that screen out harmful characters in most output methods as one of the anti-XSS defenses.

 

Cross-Site Request Forgery (CSRF)

CSRF attacks exploit authenticated users by tricking their browsers into executing unwanted actions on a web application. In Salesforce, this could mean unauthorized data changes or approvals.

Techniques to Prevent Cross-Site Request Forgery (CSRF):

  • Use built-in protection: Salesforce provides built-in CSRF protection mechanisms for Visualforce and Lightning pages. Ensure these settings are activated in your org.

Setup → Session Settings → CSRF Protection 

  • Anti-CSRF Tokens: Salesforce implements built-in anti-CSRF tokens in all its standard controllers and methods
  • Limit Session Duration: Shorten session expiration times to minimize the risk of session hijacking and CSRF attacks.
  • Secure Cookies: Enable HTTPS for all Salesforce interactions to ensure session cookies are transmitted securely.

 

Conclusion

Ensuring the security of Salesforce development requires staying alert and taking a proactive stance in identifying and addressing potential risks. Vulnerabilities can lead to severe consequences if left unaddressed. By following recommended guidelines companies can establish strong protections against possible attacks. Check out other articles on our blog, where we share insights on Salesforce optimization, best practices, and the latest industry trends. Stay informed and stay secure.


Anzhelika Makarova
Junior Salesforce Developer
image
Expertise
Question to the expert
image

We have available resources to start working on your project within 5 business days

1 UX Designer

image

1 Admin

image

2 QA engineers

image

1 Consultant

image
Related Articles
All articles
image
Is Salesforce Winning the Public Sector Race?
An analysis of Salesforce's rapid expansion into the U.S. public sector, tracing its path from cautious early government licensing deals in the 2010s through the launch of Government Cloud in 2012, its pivotal role in COVID-19 vaccine rollouts, and its 2025–2026 push into military and intelligence work via Agentforce and Missionforce. The piece covers major 2026 contracts — including a $5.6 billion Army deal, a $1.6 billion VA agreement, and Pentagon Impact Level 5 authorization — alongside real-world case studies like California's REAL ID processing and the UK's NHS back-office operations. It also examines the structural obstacles still facing Salesforce and other vendors in government tech: legacy IT systems decades old, outdated federal procurement rules, budget constraints, and organizational caution around AI adoption, plus the competitive pressure from Palantir, Microsoft, and Oracle in the race for public sector AI spending.
28 August 2026
image
Why Your Salesforce Flows Are Agentforce's Biggest Problem
This article argues that the most underestimated risk in Agentforce deployments isn't data quality — it's the automation layer: years of overlapping Flows, Process Builder processes, Apex triggers, and managed package logic that no one has reviewed end-to-end. It explains why AI agents inherit automation complexity without the tribal knowledge human admins carry, why technical debt only becomes visible after an agent hits it in production, and why a clean demo is no indicator of production readiness. The article closes with a concrete, tool-by-tool inventory approach using Flow Trigger Explorer, Salesforce Optimizer, Setup Audit Trail, Apex Debug Logs, Agent Builder, and Health Check — scoped to the specific processes the agent will actually use rather than the whole org.
23 July 2026
image
How to Wire Multiple Salesforce Projects in One Org Without Breaking Everything
This article maps the real integration patterns that emerge when multiple Salesforce projects — both managed packages and unpackaged code — share a single org. It covers four concrete patterns: attaching custom triggers to package-owned objects, calling global members exposed by managed packages, writing directly into another project's objects, and runtime-guarded reads of package data. It then addresses access control for authenticated and guest users, including the Master-Detail wall and the without sharing elevation pattern. The piece closes with eight concrete risks (compile-time dependencies that block uninstall, upgrade coupling, silent cascade failures, access invisible to admins) and six actionable recommendations for keeping cross-project coupling manageable.
08 July 2026