Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Apex Programming Language: A Comprehensive Guide for Salesforce Developers, Exams of Software Development

A comprehensive overview of the apex programming language, a key component of the salesforce platform. It covers fundamental concepts, data types, syntax, and best practices for developing custom applications within the salesforce ecosystem. The document delves into key aspects of apex, including classes, triggers, collections, and methods, offering insights into their functionality and practical applications. It also explores the differences between apex and traditional programming languages like java, highlighting the unique features and limitations of apex.

Typology: Exams

2024/2025

Available from 01/21/2025

Smartsolutions
Smartsolutions 🇺🇸

2.3

(3)

11K documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Salesforce Certified Platform Developer I Exam With
Complete Solutions 100% Verified
Describe differences between Apex and traditional Programming Languages like Java. -
ANSWER 1.) Traditional Programming Languages are fully flexible, and allow you to tell
the system to do just about anything. Apex is governed, and can only do what the system
allows.
2.) Apex is case-insensitive
3.) Apex is on-demand, and is compiled and executed in the Cloud (i.e. on the server)
4.) Apex needs to be unit tested to deploy it into a Production environment
5.) Apex is not a general-purpose Programming Language. It can only be used on the
Force.com platform.
What are the two major components of Apex code? - ANSWER Apex Classes and Apex
Triggers
What is an Apex Class? - ANSWER An Apex Class is a template or a blueprint from
which Apex objects are created.
What is an Apex Trigger? - ANSWER A procedure that automatically executes during a
DML operation.
What are the three FOR() loops that Apex code supports? - ANSWER 1.) Traditional
FOR() loops
2.) List Iteration FOR() loops
3.) SOQL FOR() loops
What are the three types of Collection data types in Apex code? - ANSWER 1.) Lists
2.) Maps
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Apex Programming Language: A Comprehensive Guide for Salesforce Developers and more Exams Software Development in PDF only on Docsity!

Salesforce Certified Platform Developer I Exam With

Complete Solutions 100% Verified

Describe differences between Apex and traditional Programming Languages like Java. - ANSWER 1.) Traditional Programming Languages are fully flexible, and allow you to tell the system to do just about anything. Apex is governed, and can only do what the system allows.

2.) Apex is case-insensitive

3.) Apex is on-demand, and is compiled and executed in the Cloud (i.e. on the server)

4.) Apex needs to be unit tested to deploy it into a Production environment

5.) Apex is not a general-purpose Programming Language. It can only be used on the Force.com platform.

What are the two major components of Apex code? - ANSWER Apex Classes and Apex Triggers

What is an Apex Class? - ANSWER An Apex Class is a template or a blueprint from which Apex objects are created.

What is an Apex Trigger? - ANSWER A procedure that automatically executes during a DML operation.

What are the three FOR() loops that Apex code supports? - ANSWER 1.) Traditional FOR() loops

2.) List Iteration FOR() loops

3.) SOQL FOR() loops

What are the three types of Collection data types in Apex code? - ANSWER 1.) Lists

2.) Maps

3.) Sets

What are Collections used for in Apex code? - ANSWER Collections are used to store groups of elements, such as primitive data types, or sObjects.

Where are the three areas where you can develop Apex code? - ANSWER 1.) The Force.com IDE

2.) The Developer Console

3.) The Setup menu

What conditional statements does Apex support? - ANSWER if-else

Which of the following conditional statements are not used in Apex? - ANSWER 1.) case

2.) switch

What is the sObject data type? - ANSWER The sObject data type is a generic data type and is the parent class for all standard and custom objects in Apex.

Which two of the following data types are native to Apex? - ANSWER 1.) sObject

2.) ID

What is a List? - ANSWER A List is an ordered collection of elements of a single data type. Elements added to a List are assigned an implicit index, and therefore, Lists can contain non-unique values (i.e. elements can be duplicated within a List).

What is a Set? - ANSWER A Set is an unordered collection of unique elements. There are no indexes assigned to elements in a Set, and therefore, elements in a Set much be unique.

using the Map.keySet() method. Then, use a FOR() loop to iterate through the key set to access and work with each value in the Map.

What do classes consist of? - ANSWER Methods and Attributes

What is an inner class? - ANSWER A class within another class

Does the name of a class need to start with a capital letter? - ANSWER No. But, it is advisable that this be done. More specifically, it is advisable that the Java notation be followed.

What are some ways in which Apex classes are different from Java classes? - ANSWER In Apex:

1.) Inner classes can only be nested one level deep

2.) Static methods and attributes can only be declared in a top-level class definition (i.e. an "outer class").

3.) The system-defined "Exception" class must be extended in order to create new exception classes.

What two ways can an Apex class be created from the UI - ANSWER Under Setup > Develop > Apex Classes.

1.) Click the "New" button to write the code by hand.

2.) Click the "Generate from WSDL" button and upload a WSDL file.

What are the three access modifiers for an Apex class? - ANSWER 1.) Public

2.) Private

3.) Global

What are some optional definition modifiers for an Apex class? - ANSWER 1.) with sharing

2.) without sharing

3.) virtual

4.) abstract

What is the syntax for a class definition? - ANSWER [access modifier] [definition modifier (optional)] class [class name] [implements (optional)] [extends (optional)] { //class body }

Where is a global class accessible? - ANSWER A global class is accessible within and outside of the org or namespace.

The following illustrates when the global access modifier is mainly used. ANSWER The global modifier primarily allows:

1.) The implications to expose an e-mail service or a web service.

2.) You want an API call allowed into an appExchange code or managed package published into an appExchange

3.) Allow the users that come from out of the namespace.

What would occur while using the Public access modifier? - ANSWER While using the keyword Public, that class will be assessed anywhere in that application, org, or namespace which composes the class.

What is it when the Private access modifier used? - ANSWER By using the keyword Private in defining an inner class, that Inner class will access only from an outer class.

What access is the default given a toplevel class sometimes called an outer class? -

What would happen if the class is not specified by the "with sharing" or "without sharing" definition modifiers? ANSWER The sharing model access is enforced only if this class will be invoked from another class "with sharing", otherwise, the default is "without sharing"

What if a class is called from a class that does not have sharing enforced? - ANSWER Sharing is not enforced for the called class either.

What is an interface? - ANSWER An interface is a class that only contains method signatures. The methods are not implemented in the interface. A different class must be developed to provide the implementation.

True or False: You are not required to implement all the methods of an interface class in order to implement the interface. - ANSWER False.

What is the syntax of an attribute? - ANSWER [access modifier] [data type] [attribute name] [initialization]

Ex. public Integer myInt = 0;

What is the value of an attribute if it is not initialized? - ANSWER null

What is overloading a method? - ANSWER Overloading a method is to declare multiple methods with the same name, but with different signatures.

What is the syntax for a method? - ANSWER [access modifier] [return type] [method name] [parameters] { //method definition. }

Is the access modifier portion of a method declaration optional? - ANSWER Yes

What are four access modifiers for methods and attributes? - ANSWER 1.) public

2.) private

3.) protected

4.) global

What can access a protected method or attribute? - ANSWER Only instance methods and member attributes can access a protected method or attribute.

True or False: A global method or attribute may be declared within a private class. ANSWER False. If you declare a global method or attribute within a class, that class must also be declared as global.

Describe what a static method is. - ANSWER Static methods are methods that do not require an instance of an object to run. They are called off of the class itself. They are typically utility methods that don't depend on an instance of the class.

Give an example of a standard static method. - ANSWER system.debug();

Describe static attributes. - ANSWER Static attributes are accessed through the class itself, and not through an instance of the class. They are used to store data that is shared within the class. All instances of the same class invoked in the same context share the same copy of static attributes. They can be used to set recursive flags to prevent recursive logic from performing the same operation more than once.

What is a constant? - ANSWER Constants are attributes that can be assigned a value only once. Constants are defined using the "static" and "final" keywords.

When can a constant be initialized? - ANSWER Either in the declaration itself, or via a static initializer method, if the constant is defined within a class.

What is the syntax to declare a class object? - ANSWER [class name] [object name] = new [constructor()];

What is the return type for the Database.undelete method? - ANSWER Database.UndeleteResult

What are the three methods of a SaveResult object? - ANSWER 1.) ID getId()

2.) List<Database.Error> getErrors()

3.) Boolean isSuccess()

What other options does the Database.DMLOptions object let you control? - ANSWER 1.) Truncation behavior

2.) Trigger assignment rules

3.) Locale options

4.) Trigger email notifications based on specific events such as:

  • Creation of a new Case, Case Comment, or Task
  • Conversion of a Case email to a Contact
  • New User email notification
  • Password reset

Suppose "c" is an existing Contact, and "a" is an existing Account. Which of the following are valid?

c.Account = a;

c.Account.Name = 'Salesforce';

c.LastName = 'Smith';

update c;

update c.Account; - ANSWER Yes.

What is the governor limit for DML statements in a single context? - ANSWER 150.

When should you include DML operations within a FOR() loop? - ANSWER NEVER.

What is the best practice to process bulk DML operations? ANSWER Use a SOQL FOR() loop to loop lists of sObjects. Process DML operations in chunks. This helps prevent heap limits. For example.

for(List<Position__c> myList: [SELECT Id FROM Position__c])

{

for(Position__c p: myList)

{

//some logic here.

}

Database.update(myList);

}

What if I go over the total number of SOQL queries? - ANSWER Move SOQL queries outside of loops.

What if I go over the number of DML operations? - ANSWER Process DML operations in bulk.

What if I have more than the total number of records that are retrieved by SOQL queries? - ANSWER Use selective queries which filter on indexed fields. The following fields are indexed: Primary keys, Foreign keys, Name, Audit dates, or External Id fields.

If you believe that you still will exceed governor limits for DML operations after following the best practices of your code, what other option might you have? ANSWER Use Apex asynchronous batch processing to perform DML operations.

Define what a Database Transaction is. ANSWER A transaction is a series of actions that are dependent on the first action you take.

version returns the amount of a resource used, and the second version returns the amount of a resource left.

Ex. getQueryRows

Ex. getLimitQueryRows

What are the three process classes? - ANSWER 1.) ProcessRequest

2.) ProcessSubmitRequest

3.) ProcessWorkItemRequest

What is the ProcessRequest class used for? - ANSWER ProcessRequest is used to process the results from a workflow process.

What is the ProcessSubmitRequest class used for? - ANSWER ProcessSubmitRequest is used to submit a workflow item for approval.

What is the purpose of the ProcessWorkItemRequest class? - ANSWER ProcessWorkItemRequest is used to process an item that has been submitted

What is the structure of the Parent-to-Child relationships? - ANSWER Parent-to-Child relationships use plural version of the child object name.

Ex. Contacts

If the relationship is a custom relationship, the relationship is appended with "__r"

Ex. Interviewers__r

Describe the syntax of Child-to-Parent relationships. - ANSWER Child-to-Parent relationships use the singular version of the parent object name.

Account

If the relationship is a custom relationship, the relationship is tagged with "__r"

Position__r

True or False: Relationships in Apex are expressed in dot notation. - ANSWER True.

myRecord.Position__r.Status__c;;

Describe the three parts of a relationship field. - ANSWER 1.) ID (position__c)

2.) Reference (position__r)

3.) Related List (job_applications__r)

How many member variables exist on the child object to reference the parent object? - ANSWER Two.

1.) Foreign key ( record.relationship_field__c = '001234567891ABC'; )

2.) Object reference ( record.relationship_field__r = new ParentObject__c (); )

How many member variables exist on the parent object to reference the child object? - ANSWER One.

What does SOQL stand for? - ANSWER Salesforce Object Query Language

In which of the following contexts can you construct a SOQL query? - ANSWER 1.) The queryString parameter in the call to the query()

2.) Apex statements

3.) Visualforce controllers and getter methods

4.) Using the schema explorer in the Force.com IDE.

5.) Using the Query Editor in the Developer Console

What three components or clauses does a SOQL statement comprise? - ANSWER 1.) SELECT

2.) FROM

3.) WHERE

What does MAX() do within the SOQL query? - ANSWER MAX() returns maximum value of a field

What does SUM() do within the SOQL query? - ANSWER SUM() returns total sum of a numeric field

What does CALENDAR_MONTH() do within the SOQL query? - ANSWER CALENDAR_MONTH() returns number represents the calendar month of a date field

What does the DAY_IN_MONTH() function do within a SOQL query? - ANSWER DAN_IN_MONTH() returns a number representing the day in the month of a date field

What does the FISCAL_YEAR() function do within a SOQL query? - ANSWER FISCAL_YEAR() returns a number representing the fiscal year of a date field

What does the WEEK_IN_YEAR() function do within a SOQL query? - ANSWER WEEK_IN_YEAR() returns a number representing the week in the year for a date field

What is SOQL binding? - ANSWER SOQL binding is the act of referencing a variable or expression within a square-bracketed SOQL query.

What is the syntax to bind a variable or expression to a SOQL query in Apex? - ANSWER Use a colon. For example.

[SELECT Id FROM Account WHERE Type = :myTypeValue]

[SELECT Id FROM Account WHERE Type = :('Active' + 'Client')]

True or False: SOQL only returns data for fields that are specified in the SELECT clause of the query - ANSWER True WITH ONE EXCEPTION: The Id field value is implicitly included for records returned in a SOQL query, even if the Id field is not specified in the

SELECT clause.

What do you get if you attempt to access a field for a record returned by a SOQL query that was not specified in the SELECT clause? - ANSWER A system.objectException will be thrown.

What two types of iteration variables are supported by SOQL FOR() loops? - ANSWER 1.) A single variable. Here, one record will be processed at a time.

2.) A collection of variables. Here, records will be queried in sets of 200.

SOQL "IN" keyword - ANS Used for bulk queries. Accepts a Set or List of sObjects as an argument.

.

WHERE Id IN :accountIdSet

.

SOQL "LIKE" keyword - ANS Allows you to retrieve records based on wildcards.

.

WHERE Name LIKE 'Senior%'

.

SOQL "GROUP BY" keyword - ANS Provides summary information for selected groupings.

.

Sample:

List agr = [SELECT Zip_Code__c, COUNT(Name) FROM Account GROUP BY Zip_Code__c];

True or False: SOQL queries containing aggregate functions do not support queryMore(). - ANSWER True. A LIMIT should be applied to these queries to ensure that an exception is not thrown by exceeding the limit of 2,000 rows for queries containing aggregate functions.

SELECT Id FROM Job_Application__c WHERE Position__c = null

Describe a Left Anti-Join SOQL Query - ANSWER Used to retrieve Parent objects that do not have any Child records. For example:

SELECT Id, Name FROM Position__c WHERE Id NOT IN (SELECT Position__c from Job_Application__c)

Describe a Right Inner Join Without Remote Condition SOQL Query - ANSWER Used to query for Child records that have Parent records that meet certain criteria (i.e. certain Parent records only). For example:

 SELECT Id, Position__r.Name FROM Job_Application__c WHERE Position__r.Type = 'Technology' What is a Multi-Level Relationship? - ANSWER When you chain relationships together to access Grandparent records, and beyond. For example: Job_Application__r.Candidate__r.Email What are the limits of Multi-Level Relationships? Two. - ANSWER 1.) In any single query you can reference up to 5 child-to-parent relationships. 2.) You can only have one parent-to-child relationship in a single query. In the Developer Console, where can you run a SOQL query? - ANSWER In the Query Editor Within the Developer Console, is there a way to look at an object to see what fields are available? - ANSWER Yes. Go to File > Open Resource and choose an object file (ex. Job_Application__c). The result is a tab listing available fields for the object. Perfect for running those ad hoc SOQL queries without needing to dig around manually through the native Setup menu, etc. True or False: In the Query Editor of the Developer Console, after opening an object resource, you can click to select fields from the resource, then click Add Fields to automatically build a default SOQL query that includes those fields. - ANSWER False. After opening an object resource you are able to click to select fields from the resource then click Query to automatically build a default SOQL query that includes those fields. Does Schema Builder have an option to clear the default layout in the application? ANSWER Yes. The "Clear All" option removes all objects and their relationships from the workspace area. True or False: Within the Schema Builder, objects must be moved manually if you would like it to better fit the viewing area after additional objects have been added to the workspace area. - ANSWER False. To auto arrange the layout to best fit the viewing area, click "Auto Layout". Schema Builder In the Schema Builder, can I toggle between Labels and API Names in my view of Objects and Fields? - ANSWER Yes. In the View Options, click either "Display Element Labels" or "Display Element Names" What does SOSL stand for? - ANSWER Salesforce Object Search Language What are some ways in which SOSL differs from SOQL? - ANSWER 1.) SOSL allows the ability to search multiple objects simultaneously. 2.) SOSL is used to execute text searches. What is the return type of a SOSL query? - ANSWER A list of lists of sObjects. By default, SOSL excludes: (three answers) - ANSWER 1.) Dates 2.) IDs