I am developing an app and this app is authenticated using OAuth2. Where do you I store the OAuth access and refresh tokens in Salesforce? Is Custom Setting the best approach ? Also, how do i store tokens of multiple users.


Yes custom setting will be best option here.

Hierarchy__c CS = Hierarchy__c.getInstance(userinfo.getuserId());
System.Assert(CS.Accesstoken__c== '******');

You can create a Hierarchical type custom setting and based on user can create data there. Because query on custom setting does not count against SOQL governor limit so it will help you in limits as well.

  • What about using a list custom setting? Are there disadvantages to that? – akcorp2003 Nov 2 '16 at 16:27
  • @akcorp2003 there is no disadvantage but normally in this scenario we use Hierarchical CS because here you can create record for user basis and easily get them using the code I have posted. – Tushar Sharma Nov 3 '16 at 5:08
  • So is this the only way or are there better ways ? – Ranga Nov 3 '16 at 9:02
  • @Ranga I think in your use case its best way but not the only way. You can still use list CS or Object. – Tushar Sharma Nov 3 '16 at 9:07

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.