trailheadapps / apex-recipes

A library of concise, meaningful examples of Apex code for common use cases following best practices.
https://developer.salesforce.com
Creative Commons Zero v1.0 Universal
929 stars 446 forks source link

Connect rest api in Apex does not automatically enabled named credentials when created #568

Open dewuyi opened 3 weeks ago

dewuyi commented 3 weeks ago

Summary

When creating a Named Credential using the Salesforce Connect API via Apex, the "Enabled for Callouts" setting is not automatically toggled on. However, when the same Named Credential is created via Postman using the same Connect API, the "Enabled for Callouts" setting is automatically toggled on.

Salesforce Org Type

Sandbox

Steps To Reproduce

Configuration: Write an Apex class to create a Named Credential using the Connect API. Set up the Named Credential with the required details, including URL, External Credentials, and Callout Options. Deploy the Apex code to the Scratch Org. Run: Execute the Apex code to create the Named Credential.

Current Behavior

The Named Credential is created successfully, but the "Enabled for Callouts" toggle is not automatically enabled, requiring manual intervention to enable it. This behavior is inconsistent with creating Named Credentials via Postman using the same Connect API, where the toggle is automatically enabled.

Expected Behavior

The "Enabled for Callouts" setting should be automatically toggled on when the Named Credential is created using the Connect API via Apex, just as it is when created via Postman.

Relevant Log Output

No response

Code of Conduct

github-actions[bot] commented 3 weeks ago

Thank you for posting this issue. 🙇🏼‍♂️
We will come back to you shortly.

ChiefMahedi commented 6 days ago

I followed the steps you provided, and the Named Credential was created successfully. The 'Enabled for Callouts' option was automatically enabled, and I encountered no issues.