---
title: "Salesforce tips"
url: "https://blog.beyondthecloud.dev/tips"
---

# Salesforce tips

100 one-minute Salesforce tips. Every tip with its full text in one file: https://blog.beyondthecloud.dev/tips/llms.txt

## Apex

- [Apex Comparator Interface](https://blog.beyondthecloud.dev/tips/apex-comparator-interface.md): Thankfully, in Winter ‘24 Apex got similar interface that we can use with Lists!
- [Apex sharing keywords](https://blog.beyondthecloud.dev/tips/apex-sharing-keywords.md): Apex code works based on the closest sharing keyword. This means that for every class you can define different behavior, and even run multiple scenarios from a single start point!
- [ApexLogs good practices](https://blog.beyondthecloud.dev/tips/apexlogs-good-practices.md): Go to Developer Console, Query Editor and do the following: 1. Enter SELECT Id, LogLength FROM ApexLog ORDER BY LogLength DESC into input and click “Execute” 2. Select all the logs (logs…
- [Assign record values dynamically in Apex](https://blog.beyondthecloud.dev/tips/assign-record-values-dynamically-in-apex.md): Each standard and custom object inherits methods from the SObject class.
- [Cache with getters and setters](https://blog.beyondthecloud.dev/tips/cache-with-getters-and-setters.md): Static data such as object metadata or user profiles Sets and Maps Results of SOQL queries Results of API callouts
- [Catch Multiple Exceptions](https://blog.beyondthecloud.dev/tips/catch-multiple-exceptions.md): Did you know that Exceptions can be chained?
- [Check Transaction Context](https://blog.beyondthecloud.dev/tips/check-transaction-context.md): The Request class is a viable solution to your problem. Check the next page for details.
- [Current class name](https://blog.beyondthecloud.dev/tips/current-class-name.md): To get the names, simply create a new exception and check a stack trace!
- [Database Operation Access Level](https://blog.beyondthecloud.dev/tips/database-operation-access-level.md): Apex code, by default, operates in system mode, granting it significantly higher permissions compared to the user executing it.
- [DataWeave in Apex](https://blog.beyondthecloud.dev/tips/dataweave-in-apex.md): DataWeave is a programming language, created by MuleSoft for accessing and transforming data. Salesforce allows to use DataWeave scripts in Apex, to simplify complex transformation…
- [Declare static functions in anonymous Apex](https://blog.beyondthecloud.dev/tips/declare-static-functions-in-anonymous-apex.md): Declare static functions and classes in Anonymous Apex
- [Do not check if List is empty](https://blog.beyondthecloud.dev/tips/do-not-check-if-list-is-empty.md): DML operations on empty lists are NOT consuming the transaction DML limits?
- [Don't name classes after System classes](https://blog.beyondthecloud.dev/tips/dont-name-classes-after-system-classes.md): Each defined object, custom or standard, is automatically represented by its own apex class.
- [Effective variable debugging](https://blog.beyondthecloud.dev/tips/effective-variable-debugging.md): When you use System.debug() to display values of lists or big objects you usually see that the output is truncated:
- [Fetch Metadata Records without using SOQL](https://blog.beyondthecloud.dev/tips/fetch-metadata-records-without-using-soql.md): You can save on SOQL query limits when fetching Custom Metadata records.
- [Generate Unique Ids](https://blog.beyondthecloud.dev/tips/generate-unique-ids.md): Starting from the Spring ’24 release, you can generate UUIDs (Universal Unique Identifiers) in Apex.
- [Generate UUID in Apex](https://blog.beyondthecloud.dev/tips/generate-uuid-in-apex.md): UUID, or Universally Unique Identifier, is a 128-bit label with a probability of duplication considered close enough to zero to be negligible.
- [Get set of Ids from SObject List](https://blog.beyondthecloud.dev/tips/get-set-of-ids-from-sobject-list.md): Get set of Ids from your SObject list without iteration
- [Methods inherited from the Object class](https://blog.beyondthecloud.dev/tips/methods-inherited-from-the-object-class.md): The problem with the Object class is that it is not properly documented in Salesforce documentation and it’s hard to find information about inherited methods. We can only get more…
- [Optimize Apex Triggers](https://blog.beyondthecloud.dev/tips/optimize-apex-triggers.md): 1. Refactoring 2. Checking entry criteria 3. Moving to asynchronous tools 4. Using frameworks
- [Prevent record insert in Apex](https://blog.beyondthecloud.dev/tips/prevent-record-insert-in-apex.md): You can create validations in the Apex trigger code to prevent the insertion of selected records?
- [Remove System.debugs](https://blog.beyondthecloud.dev/tips/remove-system-debugs.md): System.debugs statements are a straightforward way to debug our Apex code, but...
- [Running Reports in Apex](https://blog.beyondthecloud.dev/tips/running-reports-in-apex.md): You can utilize the ReportManager class to run reports directly in Apex!
- [Set Default Values for Invocable Action Parameters](https://blog.beyondthecloud.dev/tips/set-default-values-for-invocable-action-parameters.md): Starting with the Summer '24 release, you can now set default values for your invocable actions. These default values will be visible in Flow Builder. Let's see how easy this is!
- [Throw Apex built-in exceptions](https://blog.beyondthecloud.dev/tips/throw-apex-built-in-exceptions.md): I suppose you've used AuraHandledException many times, but you can throw also other exceptions.
- [Working with Salesforce limits](https://blog.beyondthecloud.dev/tips/working-with-salesforce-limits.md): We can use Limits class to check how many resources we have left. Check example on the next page!
- [You are doing validation in Apex wrong!](https://blog.beyondthecloud.dev/tips/you-are-doing-validation-in-apex-wrong.md): Chain of Responsibility is a behavioral design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request…

## LWC

- [Boolean parameters in LWC](https://blog.beyondthecloud.dev/tips/boolean-parameters-in-lwc.md): In first component we’ve skipped boolean-parameter - in that way our component will use the default value, which is false. In second component simple adding boolean-parameter as…
- [Control tabs with WorkspaceAPI](https://blog.beyondthecloud.dev/tips/control-tabs-with-workspaceapi.md): With the Spring ‘24 release, Salesforce enabled the Workspace API in Lightning Web Components!
- [Current User in LWC](https://blog.beyondthecloud.dev/tips/current-user-in-lwc.md): There’s additional property which can be imported - isGuest. isGuest s a boolean value indicating whether the user is a guest user and it should be used in the Experience Builder sites.
- [Custom Labels in LWC](https://blog.beyondthecloud.dev/tips/custom-labels-in-lwc.md): To use labels in HTML, you need to create an additional component variable (labels).
- [Debounce technique in LWC](https://blog.beyondthecloud.dev/tips/debounce-technique-in-lwc.md): Debouncing is a technique to make sure that the time consuming functions aren’t called too frequently.
- [Do not combine then and await in LWC](https://blog.beyondthecloud.dev/tips/do-not-combine-then-and-await-in-lwc.md): The code is confusing. Devs who are not familiar with Promises very well, will not follow the code flow. It's hard to understand. Why do we need “await“ if there is “then“? What is the…
- [Do not use JSON.stringify to pass params to Apex](https://blog.beyondthecloud.dev/tips/do-not-use-json-stringify-to-pass-params-to-apex.md): Serializing parameters before passing them to Apex is considered bad practice because it leads to unclean code and negatively impacts performance.
- [Dynamic CSS classes in LWC](https://blog.beyondthecloud.dev/tips/dynamic-css-classes-in-lwc.md): Nested ternaries in a class getter stop being readable the moment a second condition appears. A small classSet helper turns the same logic into a flat map of class name to condition.
- [Generic onChange event handler in LWC](https://blog.beyondthecloud.dev/tips/generic-onchange-event-handler-in-lwc.md): Some components have many input components or elements that we need to track in our variables. Creating handler methods for onChange events is the right way to update the variable in our…
- [GET URL Params](https://blog.beyondthecloud.dev/tips/get-url-params.md): The easiest way to obtain URL parameters is by using CurrentPageReference. Below, you can find an example of currentPageReference. As you can see, all parameters are stored in the state…
- [How to deal with asynchronous code in LWC](https://blog.beyondthecloud.dev/tips/how-to-deal-with-asynchronous-code-in-lwc.md): This approach results in a callback nest that is difficult to understand and debug. On the next page, you will learn how to do it properly!
- [How to format date in LWC](https://blog.beyondthecloud.dev/tips/how-to-format-date-in-lwc.md): In order to format date in LWC, you can use Intl.DateTimeFormat object which enables language-sensitive date and time formatting.
- [How to render Map in LWC](https://blog.beyondthecloud.dev/tips/how-to-render-map-in-lwc.md): LWC for:each can't use Map to show elements, but it's easy to make it happen!
- [How to share CSS styles between LWC components](https://blog.beyondthecloud.dev/tips/how-to-share-css-styles-between-lwc-components.md): Imagine that you want to build an internal CSS library or every component that you expose on the Experience Cloud site must reuse similar styling.
- [How to use errorCallback](https://blog.beyondthecloud.dev/tips/how-to-use-errorcallback.md): LWC have dedicated errorCallback lifecycle hook, which can catch any uncaught errors from descendent components in its tree!
- [How to use renderedCallback](https://blog.beyondthecloud.dev/tips/how-to-use-renderedcallback.md): LWC have dedicated renderedCallback lifecycle hook, which fires when component has finished rendering phase. It’s very useful, but can be dangerous when used incompetently.
- [Instantiate LWC components dynamically](https://blog.beyondthecloud.dev/tips/instantiate-lwc-components-dynamically.md): From the Winter’24 release, we can import and instantiate Lightning Web Components dynamically. LWC finally reached this feature, that Aura has from a long time.
- [Lightning Styling Hooks](https://blog.beyondthecloud.dev/tips/lightning-styling-hooks.md): You can use Lightning Styling Hooks to style standard LWC components provided by Salesforce that you wouldn’t necessarily want to write from scratch to make minor adjustments, such as…
- [LWC Spread](https://blog.beyondthecloud.dev/tips/lwc-spread.md): Instead of passing multiple parameters to child component one by one, you can use lwc:spread directive.
- [Refresh data from @wire](https://blog.beyondthecloud.dev/tips/refresh-data-from-wire.md): Do you like fetching data for your component by @wire adapter? Are you struggling with cache and refreshing that data? Check this tip and enjoy @wire!
- [RefreshView API](https://blog.beyondthecloud.dev/tips/refreshview-api.md): From the Spring’23 release, we can use RefreshView API in LWC components, to refresh data in standard and custom components.
- [SVG in LWC](https://blog.beyondthecloud.dev/tips/svg-in-lwc.md): You have received an SVG icon from a UX/UI designer and need to use it in an LWC.
- [Toast Module](https://blog.beyondthecloud.dev/tips/toast-module.md): Do you know that there is another way to show toast besides using platformShowToastEvent module? You can use a new toast module.
- [Use null coalescing operator](https://blog.beyondthecloud.dev/tips/use-null-coalescing-operator.md): You can even chain! The code skips the left side until it is null/undefined.
- [Use OR instead of Ternary Operator](https://blog.beyondthecloud.dev/tips/use-or-instead-of-ternary-operator.md): You probably used the logical JS operator OR (||) in your Lightning Web Components. The most common use cases involve conditional statements.

## DevOps & CLI

- [ANT Migration Tool End of Life](https://blog.beyondthecloud.dev/tips/ant-migration-tool-end-of-life.md): The Ant Migration Tool's last release was Winter '24 (v59.0). It still runs, but it gets no new functionality and no support — Salesforce CLI is the officially maintained client for the Metadata API.
- [Contribute to open source](https://blog.beyondthecloud.dev/tips/contribute-to-open-source.md): The contribution loop on GitHub, end to end: identify the repository, fork it, branch, commit, push to your fork, and open a pull request against the upstream project.
- [Deploy before Merge](https://blog.beyondthecloud.dev/tips/deploy-before-merge.md): "Deploy before merge" is a CI/CD technique: the pipeline deploys — and optionally runs tests — while the pull request is still open, and only merges if that deployment succeeds, so a broken main branch never blocks the team.
- [Deploy to production](https://blog.beyondthecloud.dev/tips/deploy-to-production.md): By default when deploying items to Production you would run local tests (all tests except for Unlocked/Managed Packages)
- [Handy Git commands](https://blog.beyondthecloud.dev/tips/handy-git-commands.md): Three commands for the everyday awkward moments: git stash to switch branches with dirty files, git checkout to pull one file from another branch, and git reset --hard to throw a local branch away.
- [Manage Dev Sandboxes](https://blog.beyondthecloud.dev/tips/manage-dev-sandboxes.md): From the Summer’24 release, we can assign new Manage Dev Sandboxes user permission.
- [Mass Delete Scratch Org](https://blog.beyondthecloud.dev/tips/mass-delete-scratch-org.md): Scratch orgs are ActiveScratchOrg records in the Dev Hub, so you can query them all in the Developer Console and use "Delete Row" to remove them in one pass instead of one at a time.
- [Monitor your API Limits](https://blog.beyondthecloud.dev/tips/monitor-your-api-limits.md): One Salesforce CLI command prints over 50 org limits — daily API requests, async Apex executions, bulk API batches, storage — with the maximum and remaining allocation for each.
- [Retrieve All Salesforce Metadata](https://blog.beyondthecloud.dev/tips/retrieve-all-salesforce-metadata.md): Two Salesforce CLI commands pull an entire org's metadata: generate a manifest from the org, including managed and unlocked packages, then retrieve against that manifest.
- [Run Apex code in command line](https://blog.beyondthecloud.dev/tips/run-apex-code-in-command-line.md): Did you know that you don’t have to open developer console to run apex scripts via Anonymous Apex? You don’t even have to open any IDE or create a text file, simply put your code in…
- [Scratch Org Snapshots](https://blog.beyondthecloud.dev/tips/scratch-org-snapshots.md): Did you know you can create scratch orgs based on already existing scratch org? This is possible thanks to the Scratch Org Snapshots feature.
- [Share access to Salesforce Environment](https://blog.beyondthecloud.dev/tips/share-access-to-salesforce-environment.md): sf org open --url-only prints a login URL backed by your access token, so a teammate can get into the environment for troubleshooting without you handing over credentials.

## Admin & Setup

- [Build Dynamic Report for Record Page](https://blog.beyondthecloud.dev/tips/build-dynamic-report-for-record-page.md): This example contains sum of amount for all opportunities related to the account. Check next pages to see how to do that in 6 simple steps!
- [Easily navigate to any record](https://blog.beyondthecloud.dev/tips/easily-navigate-to-any-record.md): Simply paste the record ID after your domain, and you will be redirected to your record page
- [Get notified when SF is down](https://blog.beyondthecloud.dev/tips/get-notified-when-sf-is-down.md): status.salesforce.com lets you subscribe to a specific instance and pushes an email or SMS the moment a service disruption, performance degradation or maintenance window is posted for it.
- [List View Intelligence](https://blog.beyondthecloud.dev/tips/list-view-intelligence.md): In Winter 24 Release, Salesforce released Intelligence View for leads and contacts List Views. This view brings in some activity metrics related to the displayed records activities, e.g…
- [Login as an API-only user](https://blog.beyondthecloud.dev/tips/login-as-an-api-only-user.md): 1. Open Visual Studio Code 2. Press Ctrl + Shift + P > Select SFDX: Authorize an Org 3. Select the appropriate login URL and Alias, when a browser opens a new tab, then enter credentials…
- [Set password in Salesforce](https://blog.beyondthecloud.dev/tips/set-password-in-salesforce.md): Well, not really, this is about setting up a password via Apex and SF CLI.
- [Show all records](https://blog.beyondthecloud.dev/tips/show-all-records.md): Setup list pages keep their page size in the URL. Click "more" once, then change rowsperpage from 35 to a large number and reload — the whole list renders on a single page.
- [User Access Policies](https://blog.beyondthecloud.dev/tips/user-access-policies.md): From the Summer’24 release, we can use User Access Policies to automate assignments (and removal of assignments) to permission set licenses, permission sets, permission set groups…

## SOQL

- [Get list of one column SOQL](https://blog.beyondthecloud.dev/tips/get-list-of-one-column-soql.md): The simplest way to retrieve record IDs without a for loop is by using a Map and the keySet() method.
- [SOQL All Rows](https://blog.beyondthecloud.dev/tips/soql-all-rows.md): You can use the SOQL ALL_ROWS clause for that. The resulting query includes the soft-deleted records (the ones in the recycle bin) with the results.
- [SOQL for loops](https://blog.beyondthecloud.dev/tips/soql-for-loops.md): SOQL for loops retrieve all sObjects, using efficient chunking with calls to the query and queryMore methods of SOAP API. Developers can avoid the limit on heap size by using a SOQL for…
- [SOQL for Polymorphic relationships](https://blog.beyondthecloud.dev/tips/soql-for-polymorphic-relationships.md): You can leverage TYPEOF keyword in your SOQL queries!
- [SOQL Semi-Join](https://blog.beyondthecloud.dev/tips/soql-semi-join.md): Consideration: Semi-joins do NOT count against the query limit. Semi-joins COUNT against the aggregated query limit.
- [Use RecordType.DeveloperName instead of RecordTypeId](https://blog.beyondthecloud.dev/tips/use-recordtype-developername-instead-of-recordtypeid.md): Use RecordType.DeveloperName! Each object has a reference to its RecordType. You can utilize that reference to query records by RecordType.
- [Use the RecentlyViewed table](https://blog.beyondthecloud.dev/tips/use-the-recentlyviewed-table.md): By running this simple query, you can get records that user recently viewed:

## Tooling

- [Document Design Mode](https://blog.beyondthecloud.dev/tips/document-design-mode.md): Do you know that there is a special HTML feature that allows you to modify the content of the web page without touching the underlying code? It is called document design mode
- [Generate code with Einstein](https://blog.beyondthecloud.dev/tips/generate-code-with-einstein.md): Fear no more, check how to use Einstein for Developers!
- [github.dev web-based editor](https://blog.beyondthecloud.dev/tips/github-dev-web-based-editor.md): Swap github.com for github.dev in any repository URL and a browser-based VS Code opens on that repo — search files, edit and commit, without cloning anything.
- [Metadata Coverage Page](https://blog.beyondthecloud.dev/tips/metadata-coverage-page.md): You can use Metadata Coverage, to find the exact API name of components you are trying to work with (link also in description): https://developer.salesforce.com/docs/metadata-coverage/60
- [npm script shortcuts](https://blog.beyondthecloud.dev/tips/npm-script-shortcuts.md): You can use the npm scripts to run bash scripts, and unleash the unlimited power of scripting.
- [Quickly delete Debug Logs](https://blog.beyondthecloud.dev/tips/quickly-delete-debug-logs.md): Have you ever encountered an issue with the debug log limit? You've probably seen the message at least once: '...Before you can edit trace flags, delete some debug logs.'

## Async Apex

- [Avoid too many Queueable jobs](https://blog.beyondthecloud.dev/tips/avoid-too-many-queueable-jobs.md): That means that in the sync context, you can enqueue up to 50 queueables, 50 futures, and 100 batches, but in a queueable context, only 1 queueable and 50 futures.
- [Handle Uncatchable Exceptions in Batch](https://blog.beyondthecloud.dev/tips/handle-uncatchable-exceptions-in-batch.md): However, there is another way to achieve this in Apex Batches. Check the next page to see how.
- [Manage Scheduled Jobs](https://blog.beyondthecloud.dev/tips/manage-scheduled-jobs.md): It will allow you to use Schedule Builder or Cron Expression to configure the job execution schedule
- [Run Finalizer after Queueable](https://blog.beyondthecloud.dev/tips/run-finalizer-after-queueable.md): There are few benefits: reusable post-Queueable actions controls what happens when Queueable succeeds or fails easy way of logging results running summarizing jobs enqueue other jobs

## CSS & Styling

- [Access HTML attributes in CSS](https://blog.beyondthecloud.dev/tips/access-html-attributes-in-css.md): You can use the attr() function to retrieve the value of an attribute of the selected element and use it in the stylesheet.
- [CSS calc()](https://blog.beyondthecloud.dev/tips/css-calc.md): You can use the CSS calc(expression) function to dynamically calculate the CSS props of the elements. You can mix the units inside. This feature is especially useful when combined with…
- [CSS max min functions](https://blog.beyondthecloud.dev/tips/css-max-min-functions.md): You can use the CSS min() and max() functions to dynamically calculate CSS props of the elements and put min/max constraints on them.

## JavaScript

- [Destructuring assignment](https://blog.beyondthecloud.dev/tips/destructuring-assignment.md): The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.
- [JavaScript snippets](https://blog.beyondthecloud.dev/tips/javascript-snippets.md): Navigate to the Sources tab and select Snippets from the left toolbar.
- [Object property shorthand](https://blog.beyondthecloud.dev/tips/object-property-shorthand.md): It applies only when the property name is the same as the name of the variable that stores a value.

## Testing

- [Debug with Assert class](https://blog.beyondthecloud.dev/tips/debug-with-assert-class.md): However, debugging with the Assert class is a straightforward and efficient way to debug both Apex and Apex Unit Tests.
- [Set Record Created Date In Test](https://blog.beyondthecloud.dev/tips/set-record-created-date-in-test.md): You can use Test.setCreatedDate to set the CreatedDate of the inserted record inside Unit Test. This is helpful when the logic you’re testing depends on the records’ creation date - for…
- [Use Map and JSON.serialize to mock HTTP Response](https://blog.beyondthecloud.dev/tips/use-map-and-json-serialize-to-mock-http-response.md): Since the HTTP Body is a JSON, in this way, the code is as much similar/formatted as standard JSON as possible.

## Integration

- [HTTP status codes](https://blog.beyondthecloud.dev/tips/http-status-codes.md): The value returned when an external ID exists in more than one record. The response body contains the list of matching records.
- [Use Builder Pattern for Integrations](https://blog.beyondthecloud.dev/tips/use-builder-pattern-for-integrations.md): In the metadata, we are saving Endpoint-specific information that won’t change in any condition. Note the “Credentials” column, there we can store Named Credentials name to use in Apex…
