Plat-Dev-201 practice question 11 of 30
Assuming that name is a String obtained by a Visualforce page, which two SOQL queries performed are safe from SOQL injection? (Choose two.)
Full set: 204 questionsSOQL injection is prevented by not concatenating user-supplied input directly into a dynamic query string. Option A uses a static SOQL query with a bind variable (:query), which is inherently safe as the input is treated as a literal value, not executable code. Option C uses dynamic SOQL but correctly sanitizes the input using String.escapeSingleQuotes(). This method escapes any single quotes in the input string, which is the primary mechanism for SOQL injection attacks, thus making the query safe.
B. name.noQuotes() is intended to prevent cross-site scripting (XSS) in Visualforce, not SOQL injection, and does not provide adequate protection.
D. This query directly concatenates the raw name variable into the query string, making it a classic example of a SOQL injection vulnerability.
- Salesforce Apex Developer Guide, "SOQL Injection," which explicitly states, "The primary defense against SOQL injection is to avoid using dynamic SOQL queries." and for dynamic cases, "use the escapeSingleQuotes method."
- Salesforce Secure Coding Guide, "SOQL Injection," page 10, which details using bind variables in static queries and String.escapeSingleQuotes() for dynamic queries as the two primary prevention methods.
Keep practicing
Take the free Plat-Dev-201 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Plat-Dev-201 practice questions
- Question 1Which three steps allow a custom Scalable Vector Graphic (SVG) to be included in a Lightn…
- Question 2Which two statements are true about using the @testSetup annotation in an Apex test class…
- Question 3Managers at Universal Containers want to ensure that only decommissioned containers are a…
- Question 4Universal Containers has a Visualforce page that displays a table of every Container__c b…
- Question 5A developer is alerted to an issue with a custom Apex trigger that is causing records to …
- Question 6Which two operations affect the number of times a trigger can fire? Choose 2 answers
