I have a Python script where I run SFDX commands using subprocess module, here is part of my code:

query = run(f'sfdx force:data:soql:query -u myOrg -q "SELECT Id FROM CronTrigger"', shell=True, universal_newlines=True, stdout=PIPE, stderr=STDOUT).stdout print(query)

Here is how I validate an update:

update = run(f'sfdx force:data:record:update -u MyOrg -s User -w Email='abc@abc.com' -v Email='xyz@xyz.com', shell=True, universal_newlines=True, stdout=PIPE, stderr=STDOUT).stdout if 'Succesfully' in update: print('Success')

The thing is, the only way I can work with the result of any SFDX command is to read the output of stdout, which is a string, and then I have to parse it to find the substring that I need.

Also, to validate the success or failure of an Update, I find a 'Successfully' substring within the output. Is there a way I can get a return code from Salesforce, or perhaps an output in json format or dictionary type so I can refer to the records and values instead of reading the output?


The standard CLI commands accept a --json flag which returns JSON (and seems to include a status code).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.