We have automated tests that run on our sandboxes (not scratch org but traditional sandbox) prior to each release to production. This testing framework includes the generation and use of Salesforce Users, and retrieving the security token is a necessary part of this user generation.

As far as I can find, the only way to retrieve a security token for a newly created user is via the Salesforce UI, meaning we need to manually log in for each created test user and generate an email, which is a painfully slow process.

Is there any way to automate the security token reset process?

I saw @sfdcfox comment on a similar post that 'force:user:password:generate' in SFDX should generate the security token email automatically, but that appears to only work with scratch orgs.

  • 7
    why do you need a security token? in order to use it for API calls? in this case, you can use a connected app and JWT flow bearer flow Sep 8 at 14:34
  • 1
    If you know the IPs of the automation suite, temporarily you can add them as 'Trusted IP Ranges'. It will remove the requirement of the security token.
    – Saroj Bera
    Sep 8 at 15:35

If you specify Trusted Networks, or enforce IP Restrictions on a profile, you won't ever need a Security Token from those IP addresses. This can be much easier to handle as long as you have static IP addresses to use for your network (e.g. by way of a VPN or dedicated corporate networks, which rarely, if ever, change IPs, especially if you have a Static IP Address).

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