• Miles Nash
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi all,

Due to the issue I have described here: https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9060G0000005f11QAA, I have attempted to get a new OAuth access token programmatically using the usage notes for Auth.AuthToken.refreshAccessToken in the documentation here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Auth_AuthToken.htm#apex_class_Auth_AuthToken. For convenience, the usage example is:
 
String accessToken = Auth.AuthToken.getAccessToken('0SOD000000000De', 'Open ID connect');
Map<String, String> responseMap = Auth.AuthToken.refreshAccessToken('0SOD000000000De', 'Open ID connect', accessToken);
I am doing pretty much the same in exec anon:
 
AuthProvider pcs = [SELECT Id FROM AuthProvider WHERE DeveloperName = 'PCS'];
String accessToken = Auth.AuthToken.getAccessToken(pcs.Id, 'Open ID Connect');
Auth.AuthToken.refreshAccessToken(pcs.Id, 'Open ID Connect', accessToken);

The following exception is thrown in that code when I call refreshAccessToken: "System.InvalidParameterValueException: Argument cannot be null or empty".  Debugging "accessToken" reveals that it is null.  However, as far as I am concerned, it shouldn't be as I have passed the correct auth provider id and provider type.

This is my Auth. Provider config:

Auth Provider
This is the named credential that uses it:

Named Credential

I've tried with both Named Prinicipal and Per User.  Can anyone assist me with getting this to work?

Many thanks,

Miles

Hi all,

I have the following Auth Provider:

Auth Provider
I have successfully authenticated with the provider using a named credential:

Named Credential
When I use this named credential in Apex callouts, I worked fine until the access token expires.  At this point, I get 401s repeatedly until I edit and save the named credential again (I have "Start Authentication Flow on Save" ticked).

This is a dealbreaker for the feature I am developing in terms of production use.  Please can anyone advise what I can do?

Many thanks,

Miles

Hi all,

I need a new field on Opportunity to handle an External ID.  Having looked at existing Custom Fields on my Opp, I have found one called Order_ID__c, which doesn't appear to have been used to date and fits my purpose.

I executed the following in the Query Editor in Developer Console for the Live environment:

SELECT Count(Id) FROM Opportunity WHERE Order_ID__c != null
and got the following response:
 
[object Object]: Count(Id) FROM Opportunity WHERE Order_ID__c != null ^ ERROR at Row:1:Column:41 No such column 'Order_ID__c' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

When I execute this in Query Editor in my Sandbox for the same Org, I successfully receive a Query Result (0).  Any idea why this is happening?

Many thanks!
Hi all,

I have the following Auth Provider:

Auth Provider
I have successfully authenticated with the provider using a named credential:

Named Credential
When I use this named credential in Apex callouts, I worked fine until the access token expires.  At this point, I get 401s repeatedly until I edit and save the named credential again (I have "Start Authentication Flow on Save" ticked).

This is a dealbreaker for the feature I am developing in terms of production use.  Please can anyone advise what I can do?

Many thanks,

Miles

Hi all,

I need a new field on Opportunity to handle an External ID.  Having looked at existing Custom Fields on my Opp, I have found one called Order_ID__c, which doesn't appear to have been used to date and fits my purpose.

I executed the following in the Query Editor in Developer Console for the Live environment:

SELECT Count(Id) FROM Opportunity WHERE Order_ID__c != null
and got the following response:
 
[object Object]: Count(Id) FROM Opportunity WHERE Order_ID__c != null ^ ERROR at Row:1:Column:41 No such column 'Order_ID__c' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

When I execute this in Query Editor in my Sandbox for the same Org, I successfully receive a Query Result (0).  Any idea why this is happening?

Many thanks!