function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raorao 

Named Credentials and External credentials Winter'23

Getting error below error while accessign AWS S3 using Named Credentials and External credentials feature in Winter'23

System.CalloutException: We couldn't access the credential(s). You might not have the required permissions, or the external credential "AWS_Test" might not exist.

In the below code AWS_Test_Named  is the name of Named Credentials and this named credentials in linked with External credential.(AWS_Test)  As its by default Named principal identity type for AWS, I haven't added this to any permission set.  I tried adding it to permission set, still the same error.


String attachmentBody = EncodingUtil.base64Encode(lstAttachment[0].body);
                String formattedDateString = Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z');
                String filename = lstAttachment[0].name;
                //Update the content-type based on the file type being attached
                string contentType= lstAttachment[0].contentType;
                system.debug('contentType:'+contentType);
                String url = 'callout:AWS_Test_Named';
                
                 
                HttpRequest req  = new HttpRequest();
                HttpResponse res  = new HttpResponse();
                req.setMethod('PUT');
                req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
                req.setHeader('Content-Encoding', 'UTF-8');
                req.setHeader('Content-type', contentType);
                req.setHeader('Connection', 'keep-alive');
                req.setHeader('Date', formattedDateString);
                req.setHeader('ACL', 'public-read');
                req.setEndpoint(url + '/'+ filename);
                req.setBodyAsBlob(EncodingUtil.base64Decode(attachmentBody));
                
                Http http = new Http();
                res = http.send(req);
SwethaSwetha (Salesforce Developers) 
HI Rao,
Named credential name is case-sensitive while using it in the Apex Code. Can you recheck if it is accurate? Also if this part of a managed package,
you will need to prefix the named credential with __ (two underscores) to indicate that you are using a named credential from the local namespace.

If this information helps, please mark the answer as best. Thank you