Salesforce

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

1.

How do you create a custom Lightning component in Salesforce, and what are some
considerations to keep in mind?

Considerations: -
Security – Validate the user input, CRUD and filed level security permissions.
Performance – use asynchronous actions for long running operations to prevent blocking the user
interface
Reusability -
Accessibility - Follow WCAG (Web Content Accessibility Guidelines) standards and leverage
Salesforce's built-in accessibility features.
Lightning Design System - Utilize the Salesforce Lightning Design System (SLDS) to maintain a
consistent and professional look and feel with other Salesforce components. Adhere to SLDS
guidelines for styling and user experience
Testing and Error Handling –

-----------------------------------------------------------------------------------------------------------------------------------

2. How do you use Apex code to interact with the Salesforce database, and what are some best
practices for database access?

Define Apex class or trigger, querying data, modifying data (like insert, update, delete).

To use Apex code to interact with the Salesforce database, can perform various operations like
querying, inserting, updating, and deleting records.

Best Practices: -

Avoid Writing SOQL Queries or DML Operations Inside the Loop Statements. ...
Write a Single Trigger per sObject Type. ...
Always Bulkify Your Code. ...
Avoid Nested Loops. ...
Avoid Hardcoding IDs.
-----------------------------------------------------------------------------------------------------------------------------------

3. how to create and use Apex classes and triggers in a Salesforce application?

1. Creating an Apex Class:


a. Open your Salesforce Developer org.
b. Go to the Setup menu by clicking on the gear icon in the top-right corner.
c. In the Quick Find box, type "Apex Classes" and select the "Apex Classes" option.
d. Click the "New" button to create a new Apex class.
e. Provide a name for your class and write your Apex code in the editor. Apex classes use the
".cls" file extension.
f. Save the class by clicking the "Save" button.
a. Once you have created an Apex class, you can use it in various ways within your Salesforce
application.
b. In Apex classes, you can define methods that perform specific logic or operations. You can create
an instance of the class and call these methods to execute the desired functionality.
c. Apex classes can be used to handle business logic, process automation, integrations, data
manipulation, and more.
d. To use an Apex class, you can invoke its methods from other Apex classes, triggers, Visualforce
pages, Lightning components, or Process Builder.
-----------------------------------------------------------------------------------------------------------------------------------

4. How do you implement authentication and authorization in a custom Salesforce application?


1. Authentication:
 Choose an authentication method based on your application's requirements and the Salesforce
resources you need to access.
 Salesforce supports various authentication methods, including OAuth 2.0, SAML, username-
password flow, and more.
 Implement the chosen authentication method in your application by following Salesforce's
authentication documentation and guidelines.
 Obtain the necessary authentication credentials or tokens, such as access tokens or session IDs,
to authenticate your application with Salesforce.
2. Authorization:
 Determine the level of access and permissions required for different users or roles within your
application.
 Leverage Salesforce's built-in user and role management features to define roles, profiles, and
permission sets that align with your application's authorization requirements.
 Map the roles and permissions defined in Salesforce to the corresponding functionality and
resources in your custom application.

-----------------------------------------------------------------------------------------------------------------------------------

5. How do you use Visualforce to create custom pages and forms in Salesforce, and what are some
best practices for Visualforce development?

Create VF custom page: - From Setup, enter Visualforce Pages in the Quick Find box, then select
Visualforce Pages. Click New. In the Name text box, enter the text that should appear in the URL as
the page name. This name can contain only underscores and alphanumeric characters, and must be
unique in your org.

Create forms: - Building Forms with Visualforce:


a. Visualforce enables you to create custom forms for data entry or manipulation.
b. Use standard HTML form elements like <apex:inputText>, <apex:inputCheckbox>,
<apex:selectList>, etc., to capture user input.
c. Bind form elements to controller variables using the value attribute to store user input.
d. Leverage Visualforce's built-in validation capabilities or perform custom validation using
Apex controllers.
e. Use the <apex:commandButton> or <apex:commandLink> components to trigger actions
or submit the form to the server.
f. Handle form submissions and data processing in an associated Apex controller using
methods defined in the controller.

Best Practice for VF Page:-

 Design your Visualforce pages according to some general guidelines.


 Use standard objects and declarative features.
 Limit the amount of data that your Visualforce pages display.

-----------------------------------------------------------------------------------------------------------------------------------

9.How do you implement testing and debugging in Salesforce, and what are some best practices
for testing and debugging?
Switch on Debug Logs( time limit will be 24h), in the code system.debug.

Best Practice Test class: -


1. Code coverage should be 80%
2. Naming conventions
3. System.assert() to check the conditions
4. StartTest() and stopTest() to reset the governor limits in asynchronously
5. SeeAlldata=false

6. how to implement a custom REST API in a Salesforce application?

1. Define the API Requirements:


 Determine the functionality and data that your custom REST API needs to expose.
 Identify the resources (objects) and operations (GET, POST, PUT, DELETE) that your API
will support.
2. Create an Apex REST Class:
 Write an Apex class that serves as the entry point for your custom REST API.
 Annotate the class with the @RestResource annotation to indicate that it is a REST
service.
 Specify the URL mapping for the class using the urlMapping attribute.
 Define methods within the class corresponding to the desired REST operations (e.g.,
@HttpGet, @HttpPost, @HttpPut, @HttpDelete).
3. Implement the API Logic:
 Within each method, write the logic to handle the requested operation.
 Query or manipulate data using SOQL or DML statements.
 Transform the data into the desired response format (e.g., JSON, XML) using Apex
classes like JSON.serialize() or custom serialization.
4. Handle Authentication and Authorization:
 Implement authentication mechanisms such as OAuth, JWT, or API keys to secure
access to your custom REST API.
 Use Salesforce's built-in security features like profiles, permission sets, or sharing rules
to enforce proper authorization and data access control.
5. Handle Error Handling and Responses:
 Implement appropriate error handling to handle exceptions and return meaningful
error responses to API consumers.
 Use HTTP status codes to indicate the success or failure of API requests.
 Construct response payloads using proper data formats (e.g., JSON, XML).
6. Test and Validate the API:
 Write unit tests to validate the functionality of your custom REST API.
 Test the API using tools like Postman or cURL to ensure it behaves as expected and
returns the correct responses.
 Validate the API against your defined requirements and use cases.
7. Document and Publish the API:
 Create documentation for your custom REST API, including details about the available
resources, operations, request/response formats, and any required authentication or
headers.
 Publish the documentation to make it accessible to API consumers.
-----------------------------------------------------------------------------------------------------------------------------------
8.Can you explain how to create and deploy custom Salesforce packages, and what are some best
practices for package development?

1. Package Creation:
a. In your Salesforce org, go to Setup by clicking on the gear icon in the top-right
corner.
b. In the Quick Find box, type "Package Manager" and select the "Package Manager"
option.
c. Click the "New" button to create a new package.
d. Provide a name, description, and version number for your package.
e. Choose the package type: Unlocked or Managed. Unlocked packages are
recommended for most use cases as they offer more flexibility and easier upgrades.
f. Select the components you want to include in the package, such as custom objects,
fields, Apex classes, Visualforce pages, Lightning components, etc.
g. Specify any dependencies on other packages, if applicable.
h. Review and confirm the package details.
i. Save the package.

How to deploy package in salesforce


1. Create a folder the package XML file in the root and a sub level folder with the component
name.
2. Zip the folder.
3. Visit the Workbench site and login with username and password, if not already logged in.
4. Click the Migration tab.

Best Practices for Package development: -


 OEM vs ISV Packages. First you need to determine which type of application fits your
business and your use cases. ...
 One or Many Packages. ...
 First and Second Generation Packaging. ...
 Namespacing and Governor Limits. ...
 Development Org Strategy. ...
 Security Review.

-----------------------------------------------------------------------------------------------------------------------------------
10.How do you optimize SOQL queries for performance in a Salesforce application?

 Retrieve only the required fields in your SELECT statement.


 Use WHERE clauses to filter records directly in the query.
 Leverage indexed fields for filtering whenever possible.
 Minimize the number of records returned by filtering on relevant criteria.
 Use relationship queries (e.g., parent-to-child or child-to-parent) to retrieve related
records in a single query, instead of making separate queries.
 Use the dot notation to traverse relationships and retrieve fields from related objects.
 Avoid placing SOQL queries inside loops, as it can quickly lead to hitting governor
limits and degrade performance.
 Bulkify your code by fetching required data before the loop and use collections to
process the data.
 Utilize aggregate queries (e.g., COUNT(), SUM(), MAX(), MIN(), etc.) when appropriate
to retrieve summarized data instead of retrieving all records and performing
calculations in Apex.
 Ensure your queries are selective to avoid hitting governor limits.
 Selective queries use indexed fields and return a smaller subset of records.
 Use query limits (LIMIT) to restrict the number of records returned by a query.
 Use offset (OFFSET) when implementing pagination to fetch subsequent pages of
data.

--------------------------------------------------------------------------------------------------------------------------------------

11.How do you handle exceptions and errors in Apex code.


Exception handling is done in apex by using the try and catch mechanism, basically any code which
can throw an exception is enclosed in a try block and each try block is followed by a catch block which
is entered if the try block throws an exception. Exception occurs during the run time / execution of a
program.

Best practices:-
 Send error logs to an external service. ...
 Use error objects in rules. ...
 Use meaningful error code descriptions. ...
 Exception handling. ...
 Avoid uninitialized objects in rules. ...

12.How to implement apex sharing rule?


1. Assign Managers for Users.
2. Create a Sales Organization Record.
3. Set Up Your Sales Org. Assign Users to the Sales Org. Add the Sales Org Field to Search
Layout.
4. Update Cache Allocation.
5. Enable Continuous Data Sync for Objects.
13. How do you implement data migration and data transformation in Salesforce?

1. Identify Source and Target System


2. Understand Source System
3. Identify data for migration
4. Data Cleansing
5. Create/update Metadata in Target
6. Select tools for data migration
7. Map Source and Target data
8. Perform Data migration
9. Identity Migration Issue
10. Perform Data Validation

14.How do you implement Salesforce APIs in a custom application

1. Choose the appropriate Salesforce API:


 Salesforce provides various APIs, including SOAP, REST, Bulk, Streaming, Metadata, and more.
 Select the API that best fits your application's requirements and the functionality you need to
implement.
2. Authenticate your application with Salesforce:
 Salesforce APIs require authentication to access Salesforce data and services.
 Depending on the API, you can authenticate using different methods such as OAuth,
username-password flow, or session ID.
 Follow the authentication process specified in the API documentation to obtain the necessary
credentials or tokens.
3. Understand the API documentation:
 Familiarize yourself with the API documentation for the chosen Salesforce API.
 The documentation provides details on available resources, endpoints, request/response
formats, parameters, and authentication requirements.
4. Set up API requests:
 Use the programming language or framework of your choice to make HTTP requests to the
Salesforce API endpoints.
 Construct the appropriate request headers, parameters, and payloads based on the API
documentation.
 Make sure to include the required authentication credentials or tokens in the request headers.
5. Handle API responses:
 Receive the API responses in your custom application.
 Parse the response data according to the specified format (XML or JSON) and extract the
relevant information.
 Handle any errors or exceptions returned by the API and implement appropriate error handling
and logging.
6. Implement desired functionality:
 Use the Salesforce API calls to perform the specific operations you need in your custom
application.
 Depending on the API, you can retrieve, create, update, or delete Salesforce records, execute
SOQL or SOSL queries, access metadata, or perform other actions.
15. How to use Salesforce DX to manage and develop Salesforce applications

1. Install Salesforce CLI:


 Salesforce CLI is a command-line interface tool that provides a set of commands for Salesforce
DX.
 Install Salesforce CLI on your local machine by following the installation instructions provided
by Salesforce.
2. Create a Salesforce DX Project:
 Open a terminal or command prompt and navigate to the directory where you want to create
your Salesforce DX project.
 Run the command sfdx force:project:create -n MyProjectName to create a new Salesforce DX
project.
 This will create a project structure with a default configuration file.
3. Authorize an Org:
 Use the command sfdx force:auth:web:login to authorize a Salesforce org.
 This will open a browser window where you can log in to your Salesforce account and grant
access to the CLI.
 Once authenticated, the org will be added to your Salesforce DX project configuration.
4. Create a Scratch Org:
 Scratch orgs are temporary Salesforce orgs that you can use for development and testing.
 Run the command sfdx force:org:create -s -f config/project-scratch-def.json -a
MyScratchOrgAlias to create a scratch org.
 This command creates a new scratch org based on the configuration defined in the project-
scratch-def.json file.
5. Develop in the Salesforce DX Project:
 Use your preferred development tools (IDE, text editor) to write code and make changes in
your Salesforce DX project.
 The source code and metadata reside in the force-app directory within your project structure.
 You can create and modify Apex classes, Visualforce pages, Lightning components, objects, and
other Salesforce metadata.
6. Push Changes to the Scratch Org:
 To deploy your local changes to the scratch org, run the command sfdx force:source:push.
 This command synchronizes your local source code and metadata with the scratch org,
reflecting your changes.
7. Test and Validate:
 Run tests against your code to ensure its functionality and integrity.
 Use the command sfdx force:apex:test:run to run Apex tests or sfdx force:lightning:test:run to
run Lightning component tests.
8. Retrieve Changes from the Scratch Org:
 If you want to pull the changes made in the scratch org back to your local project, use the
command sfdx force:source:pull.
 This command retrieves the metadata changes from the scratch org and updates your local
project accordingly.
9. Collaborate and Share Changes:
 Use scratch orgs and version control (such as Git) to collaborate with team members and
manage changes.
 Scratch orgs provide isolated development environments that can be easily shared among
team members.
 Version control allows you to track changes, create branches, and merge changes made by
different developers.
10. Deploy to Other Orgs:
 Use the Salesforce CLI commands to deploy your changes from the scratch org to other Salesforce orgs,
such as sandboxes or production orgs.

You might also like