How to run SOQL and export the results to CSV
You need a quick list of records with a filter that no report gives you. Here are the ways to run a SOQL query and get the result as a CSV file.
Option 1: Developer Console
- Gear icon → Developer Console → Query Editor tab at the bottom.
- Type the query and click Execute. Tick Use Tooling API for objects such as ApexClass or CustomField.
Developer Console has no CSV export. You have to copy the grid by hand, and it is slow with many rows.
Option 2: Salesforce CLI
sf data query --query "SELECT Id, Name, Industry FROM Account WHERE CreatedDate = THIS_YEAR" --result-format csv --target-org myOrg > accounts.csv
Add --bulk for very large results, or --use-tooling-api for Tooling objects. Needs the CLI installed and logged in.
Option 3: Data Loader
Choose Export, pick the object, write or build the query, and Data Loader writes a CSV. Good for big exports, but it is a desktop install.
Useful queries to start with
SELECT Id, Name, Owner.Name, LastModifiedDate FROM Account WHERE LastModifiedDate = LAST_N_DAYS:30 SELECT Id, Name, Profile.Name, LastLoginDate FROM User WHERE IsActive = true ORDER BY LastLoginDate SELECT Id, Name, ApiVersion FROM ApexClass WHERE ApiVersion < 50 (Tooling API)
In the browser, next to your org (SF Manager)
- In SF Manager, open the SOQL Console.
- Type the query (or say it with the microphone, for example "top 10 accounts this month") and click Execute. Large results are fetched page by page and Total Records shows the full count.
- For ApexClass, ApexLog, Flow, CustomField or ValidationRule, tick Use Tooling API.
- Click Export CSV. Open more tabs with + to keep several queries side by side.
Errors are shown exactly as Salesforce returns them, with row and column, so you can fix the query quickly.