+ Start a Discussion
kumquatlilykumquatlily 

Help Needed 2 questions

Appreciate the correct answers for the following PD 1 exam questions and clarification?
My thoughts of answers in Italic.
thanks in advance!

1.  Given the following Anonymous Block:
List<Case> casesToUpdate = new List<Case>();
for(Case thisCase : [Select Id, Status FROM Case LIMIT 50000]){            thisCase.status = 'Working';
    casesToUpdate.add(thisCase);

} try{
       Database.update(casesToUpdate.false);
}catch(Exception e){
      System.debug(e.getMessage()); }

What should a developer consider for an environment that has over 10,000 Case records?
A. The transaction will fail due to exceeding the governor limit.  
B. The try/catch block will handle any DML exceptions thrown.
C. The transaction will succeed and changes will be committed.
D. The try/catch block will handle exceptions thrown by governor limits.

2. A developer has an Apex controller for a Visualforce page that takes an ID as a URL parameter. How should the developer prevent a cross site scripting vulnerability?
A. ApexPages.currentPage() .getparameters() .get('url_param')
B. ApexPages.currentPage() .getParameters() .get('url_param') .escapeHtml4()
C. String.ValueOf(ApexPages.currentPage() .getparameters() .get('url_param'))
D. String.escapeSingleQuotes(ApexPages.currentpages() .getParameters() .get('url_param'))
Best Answer chosen by kumquatlily
AnudeepAnudeep (Salesforce Developers) 
Hi kumquatlily, 

1. There is a DML Insert/Update Limit of 10,000 rows when running anonymous apex. Based on the code block above, we run into the error - "Too many DML rows: 10001" error when trying to insert/update so the answer would be B based on my knowledge

2. Option D because String.escapeSingleQuotes can be used to prevent attackers from accessing restricted data in the org

https://trailhead.salesforce.com/en/content/learn/modules/secdev_injection_vulnerabilities/secdev_inject_prevent_soql_injection

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. Thank You!

Anudeep

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi kumquatlily, 

1. There is a DML Insert/Update Limit of 10,000 rows when running anonymous apex. Based on the code block above, we run into the error - "Too many DML rows: 10001" error when trying to insert/update so the answer would be B based on my knowledge

2. Option D because String.escapeSingleQuotes can be used to prevent attackers from accessing restricted data in the org

https://trailhead.salesforce.com/en/content/learn/modules/secdev_injection_vulnerabilities/secdev_inject_prevent_soql_injection

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. Thank You!

Anudeep
This was selected as the best answer
kumquatlilykumquatlily
Thank you Anudeep!