diff --git a/sf-data-export b/sf-data-export index 67babed..13a48ae 100755 --- a/sf-data-export +++ b/sf-data-export @@ -229,11 +229,26 @@ if ! validate_query "$FINAL_QUERY"; then exit 1 fi -# Build the sf command -SF_ARGS=("data" "export") - -# Add the query -SF_ARGS+=("--query" "$FINAL_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}" diff --git a/sf-data-export.ps1 b/sf-data-export.ps1 index ec54058..3d0c077 100644 --- a/sf-data-export.ps1 +++ b/sf-data-export.ps1 @@ -208,8 +208,21 @@ if (-not (Test-SOQLQuery $finalQuery)) { exit 1 } -# Build the sf command -$sfArgs = @("data", "export", "--query", $finalQuery) +# Build the sf command based on bulk vs regular query +if ($Bulk) { + # 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() + } + + 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) +} # Add optional parameters if ($TargetOrg) { @@ -218,24 +231,6 @@ if ($TargetOrg) { Write-Host "Target org: $TargetOrg" -ForegroundColor Cyan } -if ($Bulk) { - $sfArgs += "--bulk" - Write-Host "Using Bulk API" -ForegroundColor Yellow -} - -if ($Wait -ne 10) { - $sfArgs += "--wait" - $sfArgs += $Wait.ToString() -} - -# Set output file and format -$sfArgs += "--output-file" -$sfArgs += $Output - -if ($Format -eq "json") { - $sfArgs += "--json" -} - Write-Host "Output format: $Format" -ForegroundColor Cyan Write-Host "Output file: $Output" -ForegroundColor Cyan diff --git a/sf-data-import b/sf-data-import index 7fd6ba7..e63c134 100755 --- a/sf-data-import +++ b/sf-data-import @@ -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 -SF_ARGS+=("--file" "$FILE") -SF_ARGS+=("--sobject" "$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