Show answer
Answer: A, C
A. Use a bind variable, for example WHERE Name LIKE :pattern, with pattern built from the input. ✓Correct. Bind variables are treated as data, not as part of the query text, so input cannot change the query structure.
B. Declare the controller class with the without sharing keyword.Sharing keywords control record access; they do nothing to stop injected query text.
C. Pass the input through String.escapeSingleQuotes() before adding it to the query string. ✓Correct. escapeSingleQuotes() escapes single quotes so user input stays inside the string literal and cannot add new clauses.
D. Wrap the input with HTMLENCODE() in the Visualforce page before sending it to the controller.HTMLENCODE() protects against XSS in HTML output; it is not designed to sanitize SOQL query text.
E. Add a LIMIT 200 clause to the end of the query string.A LIMIT clause limits rows returned, but injected text can still change the WHERE logic.
Why: Prevent SOQL injection by using static SOQL with bind variables where possible, or by escaping input with String.escapeSingleQuotes() when dynamic SOQL is required.