I was trying to solve a problem with access and refresh tokens across multiple businesses in a single org and thought I would use Custom metadata Types.
The main reason was the field length can be > 255 which I need because the tokens are JWT tokens. The other reason was for the Relationship fields as the business is structured with stores (one or more) with devices (one or more per store).
I have everything working as an admin but where I am failing is:
As a regular non admin user
- Access tokens expired so need to use refresh token
- New access token is obtained
- Unable to update the custom metadata type with the new access token via apex metadata deployment
Deployment fails with "Invalid Cross Reference Id".
Attempted Resolutions
- Assigning a permission set with "Customize Application" does not solve the issue
- Ensured the class that performed the apex metadata deployment was set to without sharing
The only way I was able to get it to work was to assign the sys admin profile to the user
My question is:
- Am I out of luck here since I cannot assign system permissions to users just for this purpose
- Is there any way to update custom metadata types when initiated by code from a user without necessary permissions?
I realize I can use protected custom settings but I would need 5 access and 5 refresh token fields to store the data and since there is no lookup relationship I would need to manage all that via code which was mostly solved by Custom Metadata Types
Named Credentials will not work in this use case either...At least no so far as I can tell as I need to assign users to stores and the JWT auth is for the manager of the store not a single person. I could not see a way to make it work but....
I guess I just need validation there is no other way to do it currently before I go down the route of custom settings.