nerdexam
Salesforce

CRT-450 · Question #54

A developer is tasked to perform a security review of the ContactSearch Apex class that exists in the system. Whithin the class, the developer identifies the following method as a security threat…

The correct answer is A. Use variable binding and replace the dynamic query with a static SOQL. B. Use the escapeSingleQuote method to sanitize the parameter before its use. See the full explanation below for the reasoning.

Question

A developer is tasked to perform a security review of the ContactSearch Apex class that exists in the system. Whithin the class, the developer identifies the following method as a security threat:

List<Contact> performSearch(String lastName){ return Database.query('Select Id, FirstName, LastName FROM Contact WHERE LastName Like %'+lastName+'%); } What are two ways the developer can update the method to prevent a SOQL injection attack? Choose 2 answers

Options

  • AUse variable binding and replace the dynamic query with a static SOQL.
  • BUse the escapeSingleQuote method to sanitize the parameter before its use.
  • CUse a regular expression on the parameter to remove special characters.
  • DUse the @Readonly annotation and the with sharing keyword on the class.

How the community answered

(27 responses)
  • A
    74% (20)
  • C
    7% (2)
  • D
    19% (5)

Community Discussion

No community discussion yet for this question.

Full CRT-450 Practice