Showing posts with label SOQL. Show all posts
Showing posts with label SOQL. Show all posts

Friday, December 29, 2023

How to download the developer console SOQL query results

 

Hi Friends today we are going to discuss, How to download the developer console  SOQL query results


Step 1: activate user select

enter image description here

Step 2: select results

enter image description here

Step 3: copy & paste it to excel

enter image description here

Saturday, December 16, 2023

Query Optimization Salesforce

 

Query optimization in Salesforce refers to the process of improving the performance and efficiency of your Salesforce queries. Salesforce uses a language called SOQL (Salesforce Object Query Language) for querying data. Here are some tips for optimizing your queries in Salesforce:

1.     Indexing:

·        Ensure that the fields used in WHERE clauses are indexed. Indexing allows Salesforce to quickly locate the records that match the specified conditions.

·        Standard fields are generally indexed, but custom fields may need to be manually indexed.

2.     Selective Filtering:

·        Design your queries to be selective. Selective queries are those that filter out a large portion of the records, allowing Salesforce to quickly retrieve the relevant data.

·        Avoid using "LIKE" queries without a leading wildcard ('%') as they are not selective and can result in full table scans.

3.       Query Plan Tool :

·        The Query Plan tool in the Developer Console can help speed up SOQL queries done over large volumes. Use the Query Plan tool to optimize and speed up queries done over large volumes.

4.     Limit the Number of Records Returned

·        Use the LIMIT clause to restrict the number of records returned by a query. This can significantly improve performance, especially when dealing with large datasets.

5.     Avoid Using "NULL" in WHERE Clauses:

·        Queries that include "IS NULL" or "IS NOT NULL" conditions can be less performant. Try to avoid these conditions if possible.

6.     Bulkify Your Code:

·        When writing triggers or batch processes, make sure your code can handle bulk data processing. Avoid using SOQL or DML statements inside loops to prevent hitting governor limits.

7.     Use Aggregate Queries Wisely:

·        Aggregate queries (e.g., using GROUP BY) can be resource-intensive. Use them judiciously and ensure that the fields you are aggregating are indexed.

8.     Query Plan Tool:

·        Use the Query Plan tool in the Developer Console to analyze the query performance. It helps you understand how Salesforce executes your query and identify any potential bottlenecks.

9.     Consider External Objects:

·        For large datasets that are not suitable for traditional Salesforce queries, consider using External Objects and External Data Sources to query data stored outside Salesforce.

10. Review Query Optimizer Warnings:

·        When running a query in the Developer Console, pay attention to any query optimizer warnings. These warnings provide insights into potential performance issues.

11. Use SOQL Best Practices:

·        Familiarize yourself with SOQL best practices outlined in the Salesforce documentation. This includes understanding query syntax, using relationships efficiently, and optimizing queries for performance.

 


 

Wednesday, November 22, 2023

To get recycle bin records in SOQL

 In Salesforce Object Query Language (SOQL), there isn't a direct query to retrieve records from the Recycle Bin. The Recycle Bin is a system feature that retains deleted records for a certain period before they are permanently deleted. SOQL queries only operate on active records, and the Recycle Bin is not directly queryable.

However, you can use the ALL ROWS keyword to include records that are in the Recycle Bin in your query results. Here's an example:

To return only the deleted rows.     SELECT Id, isDeleted FROM <Oblectname> WHERE isDeleted = true All ROWS To return only the archived rows.     SELECT Id, isDeleted FROM <Oblectname> WHERE isArchived = true All ROWS To return the deleted records, archived records and records that are     SELECT Id, isDeleted FROM <Oblectname> All ROWS

Replace YourObject__c with the actual API name of the object you are interested in. The IsDeleted field will indicate whether the record is in the Recycle Bin (true) or not (false).

Keep in mind that querying records from the Recycle Bin can return a large number of records, so it's important to use appropriate filters in your query to limit the results. Additionally, querying records from the Recycle Bin counts against your query limits just like querying active records.

Friday, June 4, 2021

SOQL FIELDS() Function

 

SOQL FIELDS() Function

With Salesforce Spring 21 release, Salesforce has introduced SOQL Fields functions. The FIELDS() function lets us select groups of fields without knowing their names in advance. This function simplifies SELECT statements, avoids the need for multiple API calls, and provides a low-code method to explore the data in the org. This function is available in API version 51.0 and later.

we can use FIELDS() as per below 

  • FIELDS(ALL)—to select all the fields of an object.
  • FIELDS(CUSTOM)—to select all the custom fields of an object.
  • FIELDS(STANDARD)—to select all the standard fields of an object.

For example we can use below query to get all data

SELECT FIELDS(ALL) FROM Account LIMIT 200

But we have some limitations here.

  1. If we try to use FIELDS(ALL) or FIELDS(CUSTOM) in Spring 21 we will get the error “The SOQL FIELDS function is not supported with an unbounded set of fields in this API”.
  2. LIMIT n—where n is less than or equal to 200.