Salesforce Apex Developer Practices
28 Questions
100 Views

Salesforce Apex Developer Practices

Created by
@StatelyComposite

Questions and Answers

A method is passed a list of generic sObjects as a parameter. What should the developer do to determine which object type (Account, Lead, or Contact, for example) to cast each sObject?

  • Use the first three characters of the sObject ID to determine the sObject type.
  • Use a try-catch construct to cast the sObject into one of the three sObject types.
  • Use the getSObjectType method on each generic sObject to retrieve the sObject token. (correct)
  • Use the getSObjectType method on the sObject class to get the sObject name.
  • Which two strategies should a developer use to avoid hitting governor limits when developing in a multi-tenant environment? Choose 2 answers.

  • Use collections to store all fields from a related object and not just minimally required fields.
  • Use variables within Apex classes to store large amounts of data.
  • Use SOQL for loops to iterate data retrieved from queries that return a high number of rows. (correct)
  • Use methods from the 'Limits' class to monitor governor limits. (correct)
  • Which tool allows a developer to send requests to the Salesforce REST APIs and view the responses?

  • Force.com IDE REST Explorer Tab
  • REST resource Path URL
  • Workbench Rest Explorer (correct)
  • Developer Console REST tab
  • What is a capability of the ltng:require tag that is used for loading external Javascript libraries in Lightning Components? Choose 3 answers.

    <p>Loading scripts in parallel.</p> Signup and view all the answers

    What should a developer consider when working with multiple triggers on the case object?

    <p>Trigger execution order is not guaranteed for the same sObject.</p> Signup and view all the answers

    In a single record, a user selects multiple values from a multi-select picklist. How are the selected values represented in Apex?

    <p>As a String with each value separated by a semicolon.</p> Signup and view all the answers

    Which two statements are true about using the @testSetup annotation in an Apex test class? Choose 2 answers.

    <p>Test data is inserted once for all test methods in a class.</p> Signup and view all the answers

    What are three characteristics of static methods? Choose 3 answers.

    <p>Excluded from the view state for a Visualforce page.</p> Signup and view all the answers

    What should a developer do to deploy a Visualforce page with a custom controller?

    <p>Create a test class that provides coverage of the custom controller.</p> Signup and view all the answers

    Which three attributes need to be defined with values in the apex:commandButton tag to create a custom button for the Account object? Choose 3 answers.

    <p>action</p> Signup and view all the answers

    How should a developer implement setting a picklist field to 'Monitor' on any new Leads owned by a subset of Users?

    <p>Create a Lead Workflow Rule Field Update.</p> Signup and view all the answers

    Which two environments meet the requirements for testing a system integration that requires about 2 GB of data storage? Choose 2 answers.

    <p>Partial Sandbox</p> Signup and view all the answers

    What are three ways for a developer to execute tests in an org? Choose 3 answers.

    <p>Developer Console</p> Signup and view all the answers

    Which three declarative fields are correctly mapped to variable types in Apex? Choose 3 answers.

    <p>Date/Time maps to Datetime</p> Signup and view all the answers

    Which two ways should a developer create functionality to generate and save a PDF quote document formatted using the company’s branding guidelines? Choose 2 answers.

    <p>Create a Visualforce Page with custom styling.</p> Signup and view all the answers

    What action will allow the developer to relate records in the data model without knowing the Salesforce ID?

    <p>Create and populate a custom field on the parent object marked as an External ID.</p> Signup and view all the answers

    When is an Apex Trigger required instead of a Process Builder Process?

    <p>When an action needs to be taken on a delete or undelete, or before a DML operation is executed.</p> Signup and view all the answers

    Which attributes should be included in a Visualforce page to correctly implement controller functionality?

    <p>standardController = 'Case' and extensions = 'myControllerExtension'</p> Signup and view all the answers

    Which two exceptions may occur when executing a query to retrieve a list of contacts for each account?

    <p>SOQL query row limit exception due to the number of accounts.</p> Signup and view all the answers

    In which two ways can a developer retrieve the available fields for an object if the variable myObject represents the name of the object? Choose 2 answers.

    <p>Use Schema.describeSObjects(new String[] {myObject}).fields.getMap() to return a map of fields.</p> Signup and view all the answers

    What should a developer do to assign machinery to different construction jobs and track the dates and costs associated with the jobs?

    <p>Create a junction object with Master-Detail Relationships to both the Machinery object and the Construction Job.</p> Signup and view all the answers

    Which approach should a developer use to make total hours for each timecard available to application users?

    <p>A Roll-Up Summary field on the Timecard Object that calculates the total hours from timecard entries for that timecard.</p> Signup and view all the answers

    Which two valid options exist for iterating through each Account in the collection List named AccountList? Choose 2 answers.

    <p>for (integer i=0; i &lt; AccountList.size(); i++) {...}</p> Signup and view all the answers

    Which SOQL query successfully returns the Accounts grouped by name?

    <p>SELECT Name, Max(CreatedDate) FROM Account GROUP BY Name</p> Signup and view all the answers

    Which approach should a developer use to add pagination to a Visualforce Page?

    <p>A StandardSetController</p> Signup and view all the answers

    What is a requirement for a class to be used as a custom Visualforce controller?

    <p>Any top-level Apex class that has a default, no-argument constructor.</p> Signup and view all the answers

    What is the end result when attempting to change the API name of a field that is referenced in an Apex test class?

    <p>The API name is not changed and there are no other impacts.</p> Signup and view all the answers

    Which two strategies should a developer use to lock down Opportunities from editing when reaching the Closed/Won stage? Choose 2 answers.

    <p>Use a validation rule.</p> Signup and view all the answers

    Study Notes

    Developer Practices and Tips

    • Use the getSObjectType method on each generic sObject to determine object types.
    • Avoid governor limits by using SOQL for loops and methods from the "Limits" class.
    • The Workbench REST Explorer is a useful tool for sending requests to Salesforce REST APIs.

    Lightning Components and JavaScript

    • Loading external JavaScript libraries in Lightning Components allows specifying loading order, loading scripts in parallel, and preventing duplicate script loading.

    Trigger Management

    • Multiple triggers on an object do not guarantee execution order for the same sObject.
    • A before insert trigger is recommended to set default values in new records.

    Apex Data Representations

    • Multi-select picklist values are represented as a string separated by semicolons in Apex.
    • The @testSetup annotation allows certain test data to be inserted once for all test methods, and cannot be used with @isTest(SeeAllData=True).

    Apex and Visualforce Requirements

    • Static methods are initialized when a class loads and are excluded from Visualforce view state.
    • Deploying a Visualforce page requires creating a test class that provides coverage for the custom controller.

    Button and Attribute Configurations

    • For custom buttons, attributes such as extensions, action, and renderAs must be defined in the <apex:page> tag for functionality.

    Data Management and Relationships

    • To assign machinery to jobs and track associated costs, create a junction object with Master-Detail relationships to both machinery and construction job objects.
    • Roll-Up Summary fields are an effective tool for calculating totals from related records declaratively.

    SOQL Queries and Object Field Retrieval

    • Use Schema.describeSObjects(new String[] {myObject})...fields.getMap() to retrieve available fields for an object.
    • The first field in a SOQL query's GROUP BY clause must always be the field being aggregated.

    Controller Class Requirements

    • Custom Visualforce controllers must be top-level Apex classes with a default constructor that does not take arguments.

    Data and Debugging Behavior

    • Changing an API name in Schema Builder does not automatically update related references in test classes, which may lead to issues.

    Strategies for Data Control

    • To lock Opportunities from editing at Closed/Won stage, use a trigger or validation rule for enforcement.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge on Salesforce Apex development practices, including trigger management, data representations, and Lightning component usage. This quiz covers essential tips for efficient Salesforce development and best practices to avoid governor limits.

    More Quizzes Like This

    Use Quizgecko on...
    Browser
    Browser