MODULE REFERENCE / psfdx-data

psfdx-data

Salesforce data

Query Salesforce with SOQL and SOSL and get PowerShell objects back, create, update, get, delete and upsert single records, upload files, move records between orgs as tree data, and run Bulk API 2.0 jobs from a CSV.

Part of the psfdx package, which installs every module: see the installation and update instructions. This module was psfdx-bulk, and the record and query commands moved here from psfdx; the names and parameters of every command are unchanged.

PS> Get-Command -Module psfdx-data

Commands

Download Markdown · Source history on GitHub

Bulk API 2.0

Export-SalesforceBulkData

Synopsis

Exports the records of a SOQL query to a file with Bulk API 2.0 (sf data export bulk).

Syntax

Export-SalesforceBulkData [-OutputFile] <String> [[-Query] <String>] [[-QueryFile] <String>] [[-ResultFormat] <String>] [-AllRows] [[-ColumnDelimiter] <String>] [[-LineEnding] <String>] [[-WaitMinutes] <Int32>] [[-TargetOrg] <String>] [<CommonParameters>]

Description

Give the query as -Query or -QueryFile (a file avoids line breaks, which the Windows CLI shim rejects as an argument). The query is passed to the CLI unchanged. Without -WaitMinutes the job is created and its JobId returned; finish it later with Resume-SalesforceBulkJob -Operation Export. With -WaitMinutes the cmdlet waits and returns TotalSize.

Parameters

-OutputFile String, required
File where records are written. Passed to sf as --output-file. Required.
-Query String
SOQL query to execute. Passed to sf as --query.
-QueryFile String
File that contains the SOQL query. Passed to sf as --query-file.
-ResultFormat String
Format to write the results. Passed to sf as --result-format. Default: csv. Valid values: csv, json.
-AllRows switch
Include records that have been soft-deleted due to a merge or delete. By default, deleted records are not returned. Adds --all-rows.
-ColumnDelimiter String
Column delimiter to be used when writing CSV output. Default is COMMA. Passed to sf as --column-delimiter. Valid values: BACKQUOTE, CARET, COMMA, PIPE, SEMICOLON, TAB.
-LineEnding String
Line ending to be used when writing CSV output. Default value on Windows is is `CRLF`; on macOS and Linux it's `LR`. Passed to sf as --line-ending. Valid values: LF, CRLF.
-WaitMinutes Int32
Time to wait for the command to finish, in minutes. Passed to sf as --wait. Default: 0. Range: 0 to 1440.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data export bulk

Examples

PS> Export-SalesforceBulkData -Query 'SELECT Id, Name FROM Account' -OutputFile .\accounts.csv -WaitMinutes 10 -TargetOrg myorg

Remarks

  • To see the examples, type: "Get-Help Export-SalesforceBulkData -Examples"
  • For more information, type: "Get-Help Export-SalesforceBulkData -Detailed"
  • For technical information, type: "Get-Help Export-SalesforceBulkData -Full"
  • For online help, type: "Get-Help Export-SalesforceBulkData -Online"

Related Links

Get-SalesforceBulkJobStatus

Synopsis

Shows the status of a bulk data load job, or of one batch in it (sf data resume).

Syntax

Get-SalesforceBulkJobStatus [-JobId] <String> [[-BatchId] <String>] [[-TargetOrg] <String>] [<CommonParameters>]

Description

Runs sf data resume, which reads the state of a bulk job from the org and returns it as an object. It only reads: it does not continue or change the job. For a Bulk API 2.0 job started with -WaitMinutes 0, use Resume-SalesforceBulkJob to continue it and Get-SalesforceBulkResult for its row results.

Parameters

-JobId String, required
ID of the bulk job. Passed to sf as --job-id. Required.
-BatchId String
ID of one batch in the job. Passed to sf as --batch-id.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data resume

Examples

PS> Get-SalesforceBulkJobStatus -JobId 750xx0000000001AAA -TargetOrg myorg

The state of the job.

Remarks

  • To see the examples, type: "Get-Help Get-SalesforceBulkJobStatus -Examples"
  • For more information, type: "Get-Help Get-SalesforceBulkJobStatus -Detailed"
  • For technical information, type: "Get-Help Get-SalesforceBulkJobStatus -Full"
  • For online help, type: "Get-Help Get-SalesforceBulkJobStatus -Online"

Related Links

Get-SalesforceBulkResult

Synopsis

Gets the outcome of a Bulk API 2.0 ingest job and saves its row results as CSV files (sf data bulk results).

Syntax

Get-SalesforceBulkResult [-JobId] <String> [[-OutputDirectory] <String>] [[-TargetOrg] <String>] [<CommonParameters>]

Description

The CLI writes <JobId>-success-records.csv, <JobId>-failed-records.csv and <JobId>-unprocessed-records.csv into its working directory, so the cmdlet runs it in -OutputDirectory (the current directory by default) and returns the full paths of the files it wrote. Records that failed do not make this cmdlet throw: check HasFailures or FailedRecords. A job that has not finished is an error. Works for any job in the org, including ones this computer did not create.

Parameters

-JobId String, required
Job ID of the bulk job. Passed to sf as --job-id. Required.
-OutputDirectory String
Folder the result files are written to. It is created if it does not exist. Defaults to the current folder. The cmdlet runs the CLI there and returns the full paths of the files it wrote.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data bulk results

Examples

PS> $r = Get-SalesforceBulkResult -JobId 750xx0000000001 -OutputDirectory .\bulk -TargetOrg myorg; if ($r.HasFailures) { Import-Csv $r.FailedFilePath }

Remarks

  • To see the examples, type: "Get-Help Get-SalesforceBulkResult -Examples"
  • For more information, type: "Get-Help Get-SalesforceBulkResult -Detailed"
  • For technical information, type: "Get-Help Get-SalesforceBulkResult -Full"
  • For online help, type: "Get-Help Get-SalesforceBulkResult -Online"

Related Links

Import-SalesforceBulkData

Synopsis

Inserts the rows of a CSV file with Bulk API 2.0 (sf data import bulk).

Syntax

Import-SalesforceBulkData [-File] <String> [-Object] <String> [[-ColumnDelimiter] <String>] [[-LineEnding] <String>] [[-WaitMinutes] <Int32>] [[-TargetOrg] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

Creates records. Asks for confirmation only when $ConfirmPreference is Medium or lower, and -WhatIf makes no CLI call. Without -WaitMinutes the job is created and its JobId returned; with it the cmdlet waits and returns the counts. A job with failed rows throws PsfdxBulkJobFailed (see Get-SalesforceBulkResult for the row results).

Parameters

-File String, required
CSV file that contains the Salesforce object records you want to import. Passed to sf as --file. Required.
-Object String, required
API name of the Salesforce object, either standard or custom, into which you're importing records. Passed to sf as --sobject. Required.
-ColumnDelimiter String
Column delimiter used in the CSV file. Passed to sf as --column-delimiter. Valid values: BACKQUOTE, CARET, COMMA, PIPE, SEMICOLON, TAB.
-LineEnding String
Line ending used in the CSV file. Default value on Windows is `CRLF`; on macOS and Linux it's `LF`. Passed to sf as --line-ending. Valid values: LF, CRLF.
-WaitMinutes Int32
Time to wait for the command to finish, in minutes. Passed to sf as --wait. Default: 0. Range: 0 to 1440.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data import bulk

Examples

PS> Import-SalesforceBulkData -File '.\new accounts.csv' -Object Account -WaitMinutes 10 -TargetOrg myorg

Remarks

  • To see the examples, type: "Get-Help Import-SalesforceBulkData -Examples"
  • For more information, type: "Get-Help Import-SalesforceBulkData -Detailed"
  • For technical information, type: "Get-Help Import-SalesforceBulkData -Full"
  • For online help, type: "Get-Help Import-SalesforceBulkData -Online"

Related Links

Remove-SalesforceBulkData

Synopsis

Deletes the records whose IDs are in a CSV file with Bulk API 2.0 (sf data delete bulk).

Syntax

Remove-SalesforceBulkData [-File] <String> [-Object] <String> [-HardDelete] [[-LineEnding] <String>] [[-WaitMinutes] <Int32>] [[-TargetOrg] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

The CSV needs an Id column. By default the records go to the Recycle Bin; -HardDelete deletes them permanently, which cannot be undone, and needs the Bulk API Hard Delete permission. Asks for confirmation by default, naming the object, the file, the org and whether the delete is permanent; -WhatIf makes no CLI call. Scripts that run unattended need -Confirm:$false. Without -WaitMinutes the job is created and its JobId returned; finish it with Resume-SalesforceBulkJob -Operation Delete. With -WaitMinutes the cmdlet waits and returns the counts. A job with failed rows throws PsfdxBulkJobFailed (see Get-SalesforceBulkResult for the row results).

Parameters

-File String, required
CSV file that contains the IDs of the records to delete. Passed to sf as --file. Required.
-Object String, required
API name of the Salesforce object, either standard or custom, that you want to delete records from. Passed to sf as --sobject. Required.
-HardDelete switch
Delete the records permanently, without moving them to the Recycle Bin. Adds --hard-delete. The user needs the Bulk API Hard Delete permission.
-LineEnding String
Line ending used in the CSV file. Default value on Windows is `CRLF`; on macOS and Linux it's `LF`. Passed to sf as --line-ending. Valid values: LF, CRLF.
-WaitMinutes Int32
Time to wait for the command to finish, in minutes. Passed to sf as --wait. Default: 0. Range: 0 to 1440.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data delete bulk

Examples

PS> Remove-SalesforceBulkData -File .\old-accounts.csv -Object Account -WaitMinutes 10 -TargetOrg myorg -WhatIf

Preview the delete without sending anything.

Remarks

  • To see the examples, type: "Get-Help Remove-SalesforceBulkData -Examples"
  • For more information, type: "Get-Help Remove-SalesforceBulkData -Detailed"
  • For technical information, type: "Get-Help Remove-SalesforceBulkData -Full"
  • For online help, type: "Get-Help Remove-SalesforceBulkData -Online"

Related Links

Resume-SalesforceBulkJob

Synopsis

Resumes a Bulk API 2.0 job started without -WaitMinutes (sf data export|import|update|upsert|delete resume).

Syntax

Resume-SalesforceBulkJob -Operation <String> -JobId <String> [-WaitMinutes <Int32>] [-TargetOrg <String>] [<CommonParameters>]
Resume-SalesforceBulkJob -Operation <String> -UseMostRecent [-WaitMinutes <Int32>] [-TargetOrg <String>] [<CommonParameters>]

Description

Pass the JobId from the earlier step and the -Operation that created it, or -UseMostRecent for the job the CLI started last. The CLI remembers jobs it created on this computer, so import, update and export resumes find the org from that record; they do not take -TargetOrg (it is ignored with a warning), and a job created elsewhere cannot be resumed here: use Get-SalesforceBulkResult with -TargetOrg instead. Upsert and Delete resumes do take -TargetOrg. Export resumes do not take -WaitMinutes. Resuming only continues the existing job, so it does not ask for confirmation. Errors are as for the cmdlet that created the job.

Parameters

-Operation String, required
The kind of bulk job to resume: Export, Import, Update, Upsert or Delete. It selects which command runs: sf data export, import, update, upsert or delete resume. Required. Valid values: Export, Import, Update, Upsert, Delete.
-JobId String, required
Job ID of the bulk job. Passed to sf as --job-id. Required unless you give -UseMostRecent.
-UseMostRecent switch, required
Resume the job that was started most recently, instead of giving -JobId. Adds --use-most-recent.
-WaitMinutes Int32
Time to wait for the command to finish, in minutes. Passed to sf as --wait. Default: 0. Range: 0 to 1440.
-TargetOrg String
Username or alias of the target org. Not required if the "target-org" configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data export resume

sf data import resume

sf data update resume

sf data upsert resume

sf data delete resume

Examples

PS> Resume-SalesforceBulkJob -Operation Upsert -JobId 750xx0000000001 -WaitMinutes 10 -TargetOrg myorg

Remarks

  • To see the examples, type: "Get-Help Resume-SalesforceBulkJob -Examples"
  • For more information, type: "Get-Help Resume-SalesforceBulkJob -Detailed"
  • For technical information, type: "Get-Help Resume-SalesforceBulkJob -Full"
  • For online help, type: "Get-Help Resume-SalesforceBulkJob -Online"

Related Links

Update-SalesforceBulkData

Synopsis

Updates records from the rows of a CSV file with Bulk API 2.0 (sf data update bulk).

Syntax

Update-SalesforceBulkData [-File] <String> [-Object] <String> [[-ColumnDelimiter] <String>] [[-LineEnding] <String>] [[-WaitMinutes] <Int32>] [[-TargetOrg] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

The CSV needs an Id column. Asks for confirmation only when $ConfirmPreference is Medium or lower, and -WhatIf makes no CLI call. Results are as for Import-SalesforceBulkData.

Parameters

-File String, required
CSV file that contains the Salesforce object records you want to update. Passed to sf as --file. Required.
-Object String, required
API name of the Salesforce object, either standard or custom, which you are updating. Passed to sf as --sobject. Required.
-ColumnDelimiter String
Column delimiter used in the CSV file. Passed to sf as --column-delimiter. Valid values: BACKQUOTE, CARET, COMMA, PIPE, SEMICOLON, TAB.
-LineEnding String
Line ending used in the CSV file. Default value on Windows is `CRLF`; on macOS and Linux it's `LF`. Passed to sf as --line-ending. Valid values: LF, CRLF.
-WaitMinutes Int32
Time to wait for the command to finish, in minutes. Passed to sf as --wait. Default: 0. Range: 0 to 1440.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data update bulk

Examples

PS> Update-SalesforceBulkData -File .\changes.csv -Object Contact -WaitMinutes 10 -TargetOrg myorg

Remarks

  • To see the examples, type: "Get-Help Update-SalesforceBulkData -Examples"
  • For more information, type: "Get-Help Update-SalesforceBulkData -Detailed"
  • For technical information, type: "Get-Help Update-SalesforceBulkData -Full"
  • For online help, type: "Get-Help Update-SalesforceBulkData -Online"

Related Links

Upsert-SalesforceBulkData

Synopsis

Inserts or updates records from the rows of a CSV file by external ID with Bulk API 2.0 (sf data upsert bulk).

Syntax

Upsert-SalesforceBulkData [-File] <String> [-Object] <String> [-ExternalIdField] <String> [[-ColumnDelimiter] <String>] [[-LineEnding] <String>] [[-WaitMinutes] <Int32>] [[-TargetOrg] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

-ExternalIdField names the external ID field the CSV matches on, and its column must be in the file. Asks for confirmation only when $ConfirmPreference is Medium or lower, and -WhatIf makes no CLI call. For one record use Upsert-SalesforceRecord.

Parameters

-File String, required
CSV file that contains the IDs of the records to update or delete. Passed to sf as --file. Required.
-Object String, required
API name of the Salesforce object, either standard or custom, that you want to update or delete records from. Passed to sf as --sobject. Required.
-ExternalIdField String, required
Name of the external ID field, or the Id field. Passed to sf as --external-id. Required.
-ColumnDelimiter String
Column delimiter used in the CSV file. Passed to sf as --column-delimiter. Valid values: BACKQUOTE, CARET, COMMA, PIPE, SEMICOLON, TAB.
-LineEnding String
Line ending used in the CSV file. Default value on Windows is `CRLF`; on macOS and Linux it's `LF`. Passed to sf as --line-ending. Valid values: LF, CRLF.
-WaitMinutes Int32
Number of minutes to wait for the command to complete before displaying the results. Passed to sf as --wait. Default: 0. Range: 0 to 1440.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data upsert bulk

Examples

PS> Upsert-SalesforceBulkData -File .\accounts.csv -Object Account -ExternalIdField Ext_Id__c -WaitMinutes 10 -TargetOrg myorg

Remarks

  • To see the examples, type: "Get-Help Upsert-SalesforceBulkData -Examples"
  • For more information, type: "Get-Help Upsert-SalesforceBulkData -Detailed"
  • For technical information, type: "Get-Help Upsert-SalesforceBulkData -Full"
  • For online help, type: "Get-Help Upsert-SalesforceBulkData -Online"

Related Links

Tree data

Export-SalesforceTreeData

Synopsis

Exports records, with their related child records, to JSON files for Import-SalesforceTreeData (sf data export tree).

Syntax

Export-SalesforceTreeData [-Query] <String[]> [-Plan] [[-Prefix] <String>] [[-OutputDirectory] <String>] [[-TargetOrg] <String>] [<CommonParameters>]

Description

Each -Query is a SOQL query; a query with a subquery exports parent and children together. The queries go to the CLI unchanged, so use one line and no double quotes (the Windows CLI shim rejects line breaks and double quotes in an argument). Without -Plan the records are returned in Records and the CLI writes one JSON file per query. With -Plan the CLI writes one file per object and a plan file that references them, which Import-SalesforceTreeData -Plan reads; Files and PlanFile hold their paths. The CLI creates -OutputDirectory if it does not exist.

Parameters

-Query String[], required
One or more SOQL queries whose records, with the related records they select, are exported. Each query is passed as its own --query. A query with a parent-to-child subquery exports the children too. Required.
-Plan switch
Generate multiple sObject tree files and a plan definition file for aggregated import. Adds --plan.
-Prefix String
Prefix of generated files. Passed to sf as --prefix.
-OutputDirectory String
Directory in which to generate the JSON files; default is current directory. Passed to sf as --output-dir.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data export tree

Examples

PS> Export-SalesforceTreeData -Query "SELECT Id, Name, (SELECT Id, LastName FROM Contacts) FROM Account WHERE Name LIKE 'Acme%'" -Plan -OutputDirectory .\data -TargetOrg source
PS> Import-SalesforceTreeData -Plan .\data\Account-Contact-plan.json -TargetOrg scratch

Remarks

  • To see the examples, type: "Get-Help Export-SalesforceTreeData -Examples"
  • For more information, type: "Get-Help Export-SalesforceTreeData -Detailed"
  • For technical information, type: "Get-Help Export-SalesforceTreeData -Full"
  • For online help, type: "Get-Help Export-SalesforceTreeData -Online"

Related Links

Import-SalesforceTreeData

Synopsis

Imports records and their related child records from JSON files into an org (sf data import tree).

Syntax

Import-SalesforceTreeData -Plan <String> [-TargetOrg <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Import-SalesforceTreeData -File <String[]> [-TargetOrg <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

Give either -Plan (a plan file from Export-SalesforceTreeData -Plan) or -File (one or more tree JSON files), not both. Asks for confirmation only when $ConfirmPreference is Medium or lower, and -WhatIf makes no CLI call. Returns one object per record created: RefId, Type and Id. If Salesforce rejects records, nothing is returned and the cmdlet throws PsfdxTreeImportFailed, whose TargetObject lists each failed reference with its StatusCode, Message and Fields. The Tree API imports at most 200 records per call.

Parameters

-Plan String, required
Plan definition file to insert multiple data files. Passed to sf as --plan. Required in the Plan parameter set.
-File String[], required
Comma-separated and in-order JSON files that contain the records, in sObject tree format, that you want to insert. Passed to sf as --files. Required in the Files parameter set.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data import tree

Examples

PS> Import-SalesforceTreeData -Plan .\data\Account-Contact-plan.json -TargetOrg scratch

Remarks

  • To see the examples, type: "Get-Help Import-SalesforceTreeData -Examples"
  • For more information, type: "Get-Help Import-SalesforceTreeData -Detailed"
  • For technical information, type: "Get-Help Import-SalesforceTreeData -Full"
  • For online help, type: "Get-Help Import-SalesforceTreeData -Online"

Related Links

Records and queries

Get-SalesforceObjectRecordCount

Synopsis

Shows how many records objects have in an org.

Syntax

Get-SalesforceObjectRecordCount [[-SObject] <String[]>] [[-TargetOrg] <String>] [<CommonParameters>]

Description

Returns approximate counts from the org's stored totals, which can differ from the results of a SOQL COUNT() query. By default it includes every standard and custom object that supports this operation. Use -SObject to request counts for specific objects.

Parameters

-SObject String[]
API names of the objects to count, for example Account, Contact or Invoice__c. Each name is passed as its own --sobject. Names may contain only letters, digits and underscores.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf org list sobject record-counts

Examples

PS> Get-SalesforceObjectRecordCount -SObject Account, Contact -TargetOrg dev1

Record counts of Account and Contact.

Remarks

  • To see the examples, type: "Get-Help Get-SalesforceObjectRecordCount -Examples"
  • For more information, type: "Get-Help Get-SalesforceObjectRecordCount -Detailed"
  • For technical information, type: "Get-Help Get-SalesforceObjectRecordCount -Full"
  • For online help, type: "Get-Help Get-SalesforceObjectRecordCount -Online"

Related Links

Get-SalesforceRecord

Synopsis

Gets one record, by ID or by field values (sf data get record).

Syntax

Get-SalesforceRecord -Type <String> -Id <String> [-UseToolingApi] [-TargetOrg <String>] [<CommonParameters>]
Get-SalesforceRecord -Type <String> -Where <IDictionary> [-UseToolingApi] [-TargetOrg <String>] [<CommonParameters>]

Description

Select the record with -Id, or with -Where, a hashtable of field values that identify exactly one record (the CLI reports an error for none or for several). They are alternatives: the CLI accepts only one. The record is returned as an object of its fields, without the internal attributes property. A value in -Where is passed to the CLI as Field='value'; because the CLI has no way to escape a quote inside a value, a value that contains a single quote, a double quote or a line break is refused. For anything more complex use Select-SalesforceRecords. A record that does not exist makes the cmdlet throw the CLI's message.

Parameters

-Type String, required
API name of the Salesforce or Tooling API object that you're retrieving a record from. Passed to sf as --sobject. Required.
-Id String, required
ID of the record you're retrieving. Passed to sf as --record-id. Required in the ById parameter set. Alias: RecordId. Accepts input from the pipeline by property name.
-Where IDictionary, required
List of <fieldName>=<value> pairs that identify the record you want to display. Passed to sf as --where. Required in the ByFields parameter set.
-UseToolingApi switch
Use Tooling API so you can retrieve a record from a Tooling API object. Adds --use-tooling-api.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data get record

Examples

PS> Get-SalesforceRecord -Type Account -Id 001xx000003DGb2AAG -TargetOrg myorg

Remarks

  • To see the examples, type: "Get-Help Get-SalesforceRecord -Examples"
  • For more information, type: "Get-Help Get-SalesforceRecord -Detailed"
  • For technical information, type: "Get-Help Get-SalesforceRecord -Full"
  • For online help, type: "Get-Help Get-SalesforceRecord -Online"

Related Links

Get-SalesforceRecordType

Synopsis

Lists record types, optionally for one object.

Syntax

Get-SalesforceRecordType [-ObjectType] <String> [[-TargetOrg] <String>] [<CommonParameters>]

Description

Queries the RecordType object (Id, SobjectType, Name, DeveloperName, IsActive) through Select-SalesforceRecords. The object name is escaped as a SOQL literal.

Parameters

-ObjectType String, required
API name of the object whose record types you want, for example Account. Without it, record types of every object are returned. Required.
-TargetOrg String
Username or alias of the org to query. If omitted, the Salesforce CLI uses the default target org.

Salesforce CLI

No direct Salesforce CLI command.

Examples

PS> Get-SalesforceRecordType -ObjectType Account -TargetOrg dev1

Record types of Account.

Remarks

  • To see the examples, type: "Get-Help Get-SalesforceRecordType -Examples"
  • For more information, type: "Get-Help Get-SalesforceRecordType -Detailed"
  • For technical information, type: "Get-Help Get-SalesforceRecordType -Full"
  • For online help, type: "Get-Help Get-SalesforceRecordType -Online"

Related Links

New-SalesforceFile

Synopsis

Uploads a local file to an org as a Salesforce File.

Syntax

New-SalesforceFile [-File] <String> [[-ParentId] <String>] [[-Title] <String>] [[-TargetOrg] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

Runs sf data create file. The file becomes a ContentVersion, so it shows under Files in the org. Give -ParentId to attach it to a record, for example an account. Supports -WhatIf and -Confirm; it does not prompt by default. The file is read by the CLI; psfdx only checks that it exists.

Parameters

-File String, required
Path of the local file to upload. Passed to sf as --file. It must exist. Required.
-ParentId String
ID of the record to attach the file to (a 15 or 18 character ID). Passed to sf as --parent-id.
-Title String
Title of the file in Salesforce. By default the CLI uses the file name. Passed to sf as --title.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data create file

Examples

PS> New-SalesforceFile -File '.\Q4 report.pdf' -ParentId 001xx000003DGb2AAG -Title 'Q4 report' -TargetOrg myorg

Upload the PDF and attach it to the account.

Remarks

  • To see the examples, type: "Get-Help New-SalesforceFile -Examples"
  • For more information, type: "Get-Help New-SalesforceFile -Detailed"
  • For technical information, type: "Get-Help New-SalesforceFile -Full"
  • For online help, type: "Get-Help New-SalesforceFile -Online"

Related Links

New-SalesforceRecord

Synopsis

Creates one record (sf data create record).

Syntax

New-SalesforceRecord [-Type] <String> [-FieldUpdates] <String> [[-TargetOrg] <String>] [-UseToolingApi] [-SkipAssignmentRules] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

-FieldUpdates is the CLI's values string, for example "Name='Acme' Industry='Energy'". Supports -WhatIf and -Confirm; it does not prompt by default.

Parameters

-Type String, required
API name of the Salesforce or Tooling API object that you're inserting a record into. Passed to sf as --sobject. Required.
-FieldUpdates String, required
Values for the flags in the form <fieldName>=<value>, separate multiple pairs with spaces. Passed to sf as --values. Required.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-UseToolingApi switch
Use Tooling API so you can insert a record in a Tooling API object. Adds --use-tooling-api.
-SkipAssignmentRules switch
Do not run the assignment rules when the record is created. This matters for a Case or Lead, which are assigned by rule otherwise. Adds --skip-assignment-rules.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data create record

Examples

PS> New-SalesforceRecord -Type Account -FieldUpdates "Name='Acme'" -WhatIf

Remarks

  • To see the examples, type: "Get-Help New-SalesforceRecord -Examples"
  • For more information, type: "Get-Help New-SalesforceRecord -Detailed"
  • For technical information, type: "Get-Help New-SalesforceRecord -Full"
  • For online help, type: "Get-Help New-SalesforceRecord -Online"

Related Links

Remove-SalesforceRecord

Synopsis

Deletes one record, by ID or by field values (sf data delete record).

Syntax

Remove-SalesforceRecord -Type <String> -Id <String> [-UseToolingApi] [-TargetOrg <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-SalesforceRecord -Type <String> -Where <IDictionary> [-UseToolingApi] [-TargetOrg <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

Select the record as for Get-SalesforceRecord: -Id, or -Where (field values that identify exactly one record). Asks for confirmation by default, naming the object, the record and the org; -WhatIf makes no CLI call. Returns the CLI's result (the deleted record's Id). A record that does not exist, or a -Where that matches several, makes the cmdlet throw the CLI's message, so nothing is hidden. Scripts that run unattended need -Confirm:$false.

Parameters

-Type String, required
API name of the Salesforce or Tooling API object that you're deleting a record from. Passed to sf as --sobject. Required.
-Id String, required
ID of the record you're deleting. Passed to sf as --record-id. Required in the ById parameter set. Alias: RecordId. Accepts input from the pipeline by property name.
-Where IDictionary, required
List of <fieldName>=<value> pairs that identify the record you want to delete. Passed to sf as --where. Required in the ByFields parameter set.
-UseToolingApi switch
Use Tooling API so you can delete a record from a Tooling API object. Adds --use-tooling-api.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data delete record

Examples

PS> Remove-SalesforceRecord -Type Account -Id 001xx000003DGb2AAG -TargetOrg myorg -WhatIf

Remarks

  • To see the examples, type: "Get-Help Remove-SalesforceRecord -Examples"
  • For more information, type: "Get-Help Remove-SalesforceRecord -Detailed"
  • For technical information, type: "Get-Help Remove-SalesforceRecord -Full"
  • For online help, type: "Get-Help Remove-SalesforceRecord -Online"

Related Links

Search-SalesforceRecords

Synopsis

Runs a SOSL text search and returns the matching records as objects.

Syntax

Search-SalesforceRecords -Query <String> [-ResultFormat <String>] [-TargetOrg <String>] [<CommonParameters>]
Search-SalesforceRecords -File <String> [-ResultFormat <String>] [-TargetOrg <String>] [<CommonParameters>]

Description

Runs sf data search with --query or --file. SOSL searches the text fields of several objects at once, for example FIND {Acme} IN ALL FIELDS RETURNING Account(Id, Name), Contact(Id, Name). With the default -ResultFormat json the records are returned as objects without their attributes property, each with an SObject property that holds the object it came from; no match returns nothing (wrap the call in @() for an empty array). With human or csv the CLI text is returned as it is. A bad search throws the CLI message. The query is passed as one argument, so braces and quotes need no escaping; on Windows the CLI shim rejects a double quote or a line break in an argument, so put such a query in a file and use -File.

Parameters

-Query String, required
SOSL query to execute. Passed to sf as --query. Give -Query or -File.
-File String, required
File that contains the SOSL query. Passed to sf as --file. It must exist. Give -Query or -File.
-ResultFormat String
Format to display the results. Default: json. Valid values: human, csv, json. Passed to sf as --result-format for human and csv; json is read through --json.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf data search

Examples

PS> Search-SalesforceRecords -Query 'FIND {Acme} IN NAME FIELDS RETURNING Account(Id, Name), Contact(Id, Name)' -TargetOrg dev1

Accounts and contacts whose name matches Acme.

Remarks

  • To see the examples, type: "Get-Help Search-SalesforceRecords -Examples"
  • For more information, type: "Get-Help Search-SalesforceRecords -Detailed"
  • For technical information, type: "Get-Help Search-SalesforceRecords -Full"
  • For online help, type: "Get-Help Search-SalesforceRecords -Online"

Related Links

Select-SalesforceRecords

Synopsis

Runs a SOQL query and returns the records as objects.

Syntax

Select-SalesforceRecords [[-Query] <String>] [[-File] <String>] [[-TargetOrg] <String>] [-UseToolingApi] [-IncludeDeletedRows] [[-ResultFormat] <String>] [[-OutputFile] <String>] [<CommonParameters>]

Description

Runs sf data query with --query or --file. With the default -ResultFormat json the records are returned as objects without their attributes property; an empty result returns nothing (wrap the call in @() for an empty array). With human or csv the CLI text is returned as it is. A failing query throws the CLI message. The query text is passed as one argument, so quotes and special characters need no escaping.

Parameters

-Query String
SOQL query to execute. Passed to sf as --query.
-File String
File that contains the SOQL query. Passed to sf as --file.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-UseToolingApi switch
Use Tooling API so you can run queries on Tooling API objects. Adds --use-tooling-api.
-IncludeDeletedRows switch
Include deleted records. By default, deleted records are not returned. Adds --all-rows.
-ResultFormat String
Format to display the results; the --json flag overrides this flag. Default: json. Valid values: human, json, csv.
-OutputFile String
File where records are written; only CSV and JSON output formats are supported. Passed to sf as --output-file.

Salesforce CLI

sf data query

Examples

PS> Select-SalesforceRecords -Query 'SELECT Id, Name FROM Account LIMIT 5' -TargetOrg dev1

Five accounts as objects.

Remarks

  • To see the examples, type: "Get-Help Select-SalesforceRecords -Examples"
  • For more information, type: "Get-Help Select-SalesforceRecords -Detailed"
  • For technical information, type: "Get-Help Select-SalesforceRecords -Full"
  • For online help, type: "Get-Help Select-SalesforceRecords -Online"

Related Links

Set-SalesforceRecord

Synopsis

Updates one record by ID (sf data update record).

Syntax

Set-SalesforceRecord -Id <String> -Type <String> -FieldUpdates <String> [-TargetOrg <String>] [-UseToolingApi] [-SkipAssignmentRules] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-SalesforceRecord -Where <IDictionary> -Type <String> -FieldUpdates <String> [-TargetOrg <String>] [-UseToolingApi] [-SkipAssignmentRules] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

Select the record by -Id (which can come from the pipeline, as an Id or RecordId property), or by -Where, field values that identify exactly one record, as for Get-SalesforceRecord. -FieldUpdates is the CLI's values string, for example "Name='Acme' Active__c=true". Supports -WhatIf and -Confirm; it does not prompt by default. A -Where that matches no record, or several, makes the cmdlet throw the CLI's message.

Parameters

-Id String, required
ID of the record you're updating. Passed to sf as --record-id. Required in the ById parameter set. Alias: RecordId. Accepts input from the pipeline by property name.
-Where IDictionary, required
List of <fieldName>=<value> pairs that identify the record you want to update, for example @{ Name = 'Acme' }. Passed to sf as --where. Required in the ByFields parameter set. Values may not contain quotes or control characters.
-Type String, required
API name of the Salesforce or Tooling API object that contains the record you're updating. Passed to sf as --sobject. Required.
-FieldUpdates String, required
Fields that you're updating, in the format of <fieldName>=<value> pairs. Passed to sf as --values. Required.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.
-UseToolingApi switch
Use Tooling API so you can update a record in a Tooling API object. Adds --use-tooling-api.
-SkipAssignmentRules switch
Do not run the assignment rules when the record is updated. This matters for a Case or Lead. Adds --skip-assignment-rules.
-WhatIf switch
-Confirm switch

Salesforce CLI

sf data update record

Examples

PS> Select-SalesforceRecords -Query "SELECT Id FROM Account WHERE Name = 'Old'" | Set-SalesforceRecord -Type Account -FieldUpdates "Name='New'" -WhatIf

Remarks

  • To see the examples, type: "Get-Help Set-SalesforceRecord -Examples"
  • For more information, type: "Get-Help Set-SalesforceRecord -Detailed"
  • For technical information, type: "Get-Help Set-SalesforceRecord -Full"
  • For online help, type: "Get-Help Set-SalesforceRecord -Online"

Related Links

Upsert-SalesforceRecord

Synopsis

Creates or updates one record, matched by an external ID.

Syntax

Upsert-SalesforceRecord [-Type] <String> [-ExternalIdField] <String> [-ExternalId] <String> [-Fields] <IDictionary> [[-ApiVersion] <String>] [[-TargetOrg] <String>] [<CommonParameters>]

Description

Matches an existing record by its external ID and updates it, or creates a record if no match exists. The result reports Created or Updated and includes the record Id when the API returns it.

Parameters

-Type String, required
API name of the object, for example Account. Required.
-ExternalIdField String, required
API name of the external ID field used to find the record. Required.
-ExternalId String, required
Value of the external ID. It is URL-escaped in the request path. Required.
-Fields IDictionary, required
Hashtable of field API names and values to set, for example @{ Name = 'Acme' }. It must not be empty. Required.
-ApiVersion String
REST API version to use, for example v62.0 or 62.0. If omitted, the latest version the org supports is used.
-TargetOrg String
Username or alias of the target org. Not required if the `target-org` configuration variable is already set. Passed to sf as --target-org.

Salesforce CLI

sf api request rest

Examples

PS> Upsert-SalesforceRecord -Type Account -ExternalIdField Ext_Id__c -ExternalId A-100 -Fields @{ Name = 'Acme' } -TargetOrg dev1

Create or update the account whose Ext_Id__c is A-100.

Remarks

  • To see the examples, type: "Get-Help Upsert-SalesforceRecord -Examples"
  • For more information, type: "Get-Help Upsert-SalesforceRecord -Detailed"
  • For technical information, type: "Get-Help Upsert-SalesforceRecord -Full"
  • For online help, type: "Get-Help Upsert-SalesforceRecord -Online"

Related Links

Further reference: repository command catalogue · Salesforce CLI parity report.

← All modules