PD1 Testing, Debugging & Deployment 4 — Questions and Answers
Question 1: In Apex, what method allows you to insert test data and bypass validation rules and triggers for faster test setup?
- Database.insert(records, false)
- Test.loadData()
- Database.upsert() with allOrNone=false
- There is no such method; all DML runs triggers (Correct answer)
Correct answer: There is no such method; all DML runs triggers
Apex DML always fires triggers and validation rules; there is no built-in way to bypass them during tests without disabling them in code.
Question 2: Which Salesforce deployment tool is best suited for automating CI/CD pipelines for metadata deployments?
- Change Sets
- Developer Console
- Salesforce CLI (sf/sfdx) (Correct answer)
- Setup Menu
Correct answer: Salesforce CLI (sf/sfdx)
Salesforce CLI supports scripted, automated deployments and integrates with CI/CD tools like GitHub Actions and Jenkins.
Question 3: What is a sandbox in Salesforce used for?
- Storing backup copies of production data permanently
- Developing and testing changes in an isolated environment (Correct answer)
- Hosting external-facing websites
- Managing user permissions in production
Correct answer: Developing and testing changes in an isolated environment
A sandbox is a copy of your production org used for development, testing, and staging before deploying to production.
Question 4: Which type of sandbox provides a full copy of production data and is typically used for final user acceptance testing?
- Developer Sandbox
- Partial Copy Sandbox
- Full Sandbox (Correct answer)
- Developer Pro Sandbox
Correct answer: Full Sandbox
A Full Sandbox replicates all production data and metadata, making it ideal for load testing and UAT.
Question 5: What happens to test data created inside an Apex test method after the test completes?
- It is permanently saved to the org
- It is rolled back automatically (Correct answer)
- It is archived in a log file
- It must be deleted manually in a cleanup method
Correct answer: It is rolled back automatically
Salesforce automatically rolls back all DML operations performed during a test method, leaving the org unchanged.
Question 6: Which Apex method is used to execute anonymous Apex code directly without creating a class or trigger?
- Apex.run()
- System.executeAnonymous()
- Execute Anonymous block via Developer Console or CLI (Correct answer)
- RunApex.execute()
Correct answer: Execute Anonymous block via Developer Console or CLI
Execute Anonymous (available in Developer Console or via 'sf apex run') runs ad-hoc Apex code without deploying a permanent class.
Question 7: In which scenario would you use System.assertNotEquals() in an Apex test?
- To confirm two values are identical
- To confirm a value is not null or not equal to a specific value (Correct answer)
- To check that a list contains items
- To assert that no exceptions were thrown
Correct answer: To confirm a value is not null or not equal to a specific value
System.assertNotEquals(val1, val2) fails the test if the two values are equal, confirming they differ as expected.
In Apex, what method allows you to insert test data and bypass validation rules and triggers for faster test setup?