Skip to content

Instantly share code, notes, and snippets.

@leto96
Last active September 28, 2022 09:17
Show Gist options
  • Save leto96/62212e415916fdd29fcbe2cb1a98adbe to your computer and use it in GitHub Desktop.
Save leto96/62212e415916fdd29fcbe2cb1a98adbe to your computer and use it in GitHub Desktop.
SFDX line commands

Logs

Lista todos os logs em JSON

sfdx force:apex:log:list --json

Lista todos os logs e salva em um arquivo (para melhor visualização)

sfdx force:apex:log:list --json > ".sfdx\tools\debug\logs\listLogs.json"

Faz o retrive de um log especifício para uma pasta (especificada com -d)

sfdx force:apex:log:get -d ".sfdx\tools\debug\logs" -i <jobid>

Retrieve Last N Logs

sfdx force:apex:log:get -n number_of_last -d .sfdx/tools/debug/logs


Apex

Create a Apex class

sfdx force:apex:class:create -n MyClass -d ".\force-app\main\default\classes"

Test coverage from vscode

sfdx force:apex:test:run --classnames "class1,class2" -c -r human

Test coverage of method from vscode

sfdx force:apex:test:run -t "myClassTest.myMethodTest" -c -r human -d .sfdx\tools\testresults\apex --json


Login

sfdx auth:web:login -a <alias> -r <https://test.salesforce.com> sfdx auth:web:login -a <orgName>

sfdx force:config:set defaultusername=<orgName>


Deploy

sfdx force:source:deploy -p ".\force-app\main\default\lwc\myComponent"

Delete

sfdx force:org:delete -u MyOrg

Create a LWC

sfdx force:lightning:component:create -n MySection -d ".\force-app\main\default\lwc" --type lwc


Criar debug logs

Sem Traceflag existente:

1) Ache um DebugLevel

sfdx force:data:soql:query -t -q "SELECT ID FROM DEBUGLEVEL WHERE DEVELOPERNAME = '<ApexDebugger|SFDC_DevConsole|Finest>'"

Finest - Mais detalhes SFDC_DevConsole - Padrão VSCode

Salve o Id retornado

2) Resgate o Id do usuário para ter os logs registrados

sfdx force:data:soql:query -q "SELECT id FROM USER where username = '[email protected]'"

3) Crie a TraceFlag

sfdx force:data:record:create -t -s TraceFlag -v "DebugLevelId=<debugLeveId> StartDate=2022-04-08T00:26:04.000-0300 ExpirationDate=2022-04-08T00:26:04.000-0300 LogType=<CLASS_TRACING|DEVELOPER_LOG|USER_DEBUG> TracedEntityId=<userid>"

Com Traceflag existente:

1) Query para TraceFlag existente para usuário

sfdx force:data:soql:query -t -q "select id from TraceFlag where TracedEntityId = '<userID>'"

Ou por username

sfdx force:data:soql:query -t -q "select id from TraceFlag where TracedEntity.username = '<[email protected]>'"

2) Atualize o horário

sfdx force:data:record:update -t -s TraceFlag -i <trace_flag_id> -v "ExpirationDate=2017-12-01T00:58:04.000-0300"


Deploy

sfdx force:mdapi:retrieve -k ./metadata/package.xml -r ./metadata/sourceOrg --unzip -u sourceOrg
mv ./metadata/sourceOrg/unpackaged/unpackaged/* ./metadata/sourceOrg/
rm ./metadata/sourceOrg/unpackaged -R
rm ./metadata/sourceOrg/unpackaged.zip

sfdx force:mdapi:retrieve -k ./metadata/package.xml -r ./metadata/targetOrg --unzip -u targetOrg
mv ./metadata/targetOrg/unpackaged/unpackaged/* ./metadata/targetOrg/
rm ./metadata/targetOrg/unpackaged -R
rm ./metadata/targetOrg/unpackaged.zip

git checkout -b tmp_merge_branch

mkdir mergeFolder
cp ./metadata/targetOrg/* .\mergeFolder\ -r
git add mergeFolder
git commit -m 'retrieved'
cp ./metadata/sourceOrg/* .\mergeFolder\ -r -Force

faça os compares

git commit -m 'merged'

se for fazer dpeloy (<-l RunLocalTests> para teste local)

sfdx force:mdapi:deploy -d .\mergeFolder -u targetOrg <-l RunLocalTests>

git checkout branch_original git branch -D tmp_merge_branch

Ao volta para a branch original, trazer como está na org

sfdx force:source:retrieve -x ./metadata/package.xml -u targetOrg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment