Update data export/import scripts to use latest Salesforce CLI commands

- Updated sf-data-export to use 'sf data export bulk' instead of deprecated 'sf data export'
- Updated sf-data-export.ps1 to use 'sf data export bulk' command structure
- Updated sf-data-import to use 'sf data import bulk' for better compatibility
- All scripts now comply with the latest Salesforce CLI command structure
- Fixes compatibility issues with newer SF CLI versions
This commit is contained in:
reynold
2025-08-28 18:22:43 +08:00
parent 3e24d62fb2
commit 4bae7d48fa
3 changed files with 56 additions and 51 deletions

View File

@@ -229,11 +229,26 @@ if ! validate_query "$FINAL_QUERY"; then
exit 1
fi
# Build the sf command
SF_ARGS=("data" "export")
# Add the query
# Build the sf command based on bulk vs regular query
if [[ "$USE_BULK" == true ]]; then
# Use Bulk API 2.0 for large datasets
SF_ARGS=("data" "export" "bulk")
SF_ARGS+=("--query" "$FINAL_QUERY")
SF_ARGS+=("--output-file" "$OUTPUT_FILE")
SF_ARGS+=("--result-format" "$FORMAT")
if [[ "$WAIT_TIME" != "10" ]]; then
SF_ARGS+=("--wait" "$WAIT_TIME")
fi
echo -e "${YELLOW}Using Bulk API 2.0${NC}"
else
# Use regular data query for smaller datasets
SF_ARGS=("data" "query")
SF_ARGS+=("--query" "$FINAL_QUERY")
SF_ARGS+=("--output-file" "$OUTPUT_FILE")
SF_ARGS+=("--result-format" "$FORMAT")
fi
# Add optional parameters
if [[ -n "$TARGET_ORG" ]]; then
@@ -241,26 +256,6 @@ if [[ -n "$TARGET_ORG" ]]; then
echo -e "${CYAN}Target org: $TARGET_ORG${NC}"
fi
if [[ "$USE_BULK" == true ]]; then
SF_ARGS+=("--bulk")
echo -e "${YELLOW}Using Bulk API${NC}"
fi
if [[ "$WAIT_TIME" != "10" ]]; then
SF_ARGS+=("--wait" "$WAIT_TIME")
fi
# Set output file and format
case "$FORMAT" in
"csv")
SF_ARGS+=("--output-file" "$OUTPUT_FILE")
;;
"json")
SF_ARGS+=("--output-file" "$OUTPUT_FILE")
SF_ARGS+=("--json")
;;
esac
echo -e "${CYAN}Output format: $FORMAT${NC}"
echo -e "${CYAN}Output file: $OUTPUT_FILE${NC}"

View File

@@ -208,32 +208,27 @@ if (-not (Test-SOQLQuery $finalQuery)) {
exit 1
}
# Build the sf command
$sfArgs = @("data", "export", "--query", $finalQuery)
# Add optional parameters
if ($TargetOrg) {
$sfArgs += "--target-org"
$sfArgs += $TargetOrg
Write-Host "Target org: $TargetOrg" -ForegroundColor Cyan
}
# Build the sf command based on bulk vs regular query
if ($Bulk) {
$sfArgs += "--bulk"
Write-Host "Using Bulk API" -ForegroundColor Yellow
}
# Use Bulk API 2.0 for large datasets
$sfArgs = @("data", "export", "bulk", "--query", $finalQuery, "--output-file", $Output, "--result-format", $Format)
if ($Wait -ne 10) {
$sfArgs += "--wait"
$sfArgs += $Wait.ToString()
}
# Set output file and format
$sfArgs += "--output-file"
$sfArgs += $Output
Write-Host "Using Bulk API 2.0" -ForegroundColor Yellow
} else {
# Use regular data query for smaller datasets
$sfArgs = @("data", "query", "--query", $finalQuery, "--output-file", $Output, "--result-format", $Format)
}
if ($Format -eq "json") {
$sfArgs += "--json"
# Add optional parameters
if ($TargetOrg) {
$sfArgs += "--target-org"
$sfArgs += $TargetOrg
Write-Host "Target org: $TargetOrg" -ForegroundColor Cyan
}
Write-Host "Output format: $Format" -ForegroundColor Cyan

View File

@@ -289,12 +289,27 @@ if [[ "$VERBOSE" == true ]]; then
show_file_preview "$FILE" "$FILE_FORMAT"
fi
# Build the sf command
SF_ARGS=("data" "$OPERATION")
# Add the file and sobject
# Build the sf command - SF CLI now uses specific commands for different operations
case "$OPERATION" in
"insert")
# For insert operations, use bulk import (works for all data types)
SF_ARGS=("data" "import" "bulk")
SF_ARGS+=("--file" "$FILE")
SF_ARGS+=("--sobject" "$SOBJECT")
;;
"update")
# For update operations, use bulk update
SF_ARGS=("data" "update" "bulk")
SF_ARGS+=("--file" "$FILE")
SF_ARGS+=("--sobject" "$SOBJECT")
;;
"upsert")
# For upsert operations, use bulk upsert
SF_ARGS=("data" "upsert" "bulk")
SF_ARGS+=("--file" "$FILE")
SF_ARGS+=("--sobject" "$SOBJECT")
;;
esac
# Add optional parameters
if [[ -n "$TARGET_ORG" ]]; then