1

My Requirement is to update Endpoint and give (X) in password after sandbox refresh to avoid PROD reference. I am Okay if only Endpoints can be updated. Tried below Snippets and running this from console/workbench but getting error. Anyone please suggest where and how should I run the update script.

Option 1:

List<NamedCredential>  lstval= [SELECT DeveloperName,Endpoint,Id,MasterLabel,NamespacePrefix FROM NamedCredential order by DeveloperName];
List<NamedCredential> updatelstVal= new List<NamedCredential>();

if(lstval !=null && lstval.size()>0){
  for(NamedCredential val:lstval){
      if(val.Endpoint!=null){
       val.Endpoint=val.Endpoint+'__TEST'; // Changing the EndPoint to avoid PROD calls.
       val.principalType = 'NamedUser';
       val.protocol = 'NoAuthentication';
       updatelstVal.add(val);
     }
  }
 }

 System.debug('%%%'+updateMetadata(credential));

Error Message: COMPILE ERROR: Field is not writeable: NamedCredential.Endpoint LINE: 7 COLUMN: 12


Option 2:

List<MetadataService.NamedCredential>  lstval= [SELECT DeveloperName,Endpoint,Id,MasterLabel,NamespacePrefix FROM MetadataService.NamedCredential order by DeveloperName];
    List<MetadataService.NamedCredential> updatelstVal= new List<MetadataService.NamedCredential>();

    if(lstval !=null && lstval.size()>0){
      for(MetadataService.NamedCredential val:lstval){
          if(val.Endpoint!=null){
           val.Endpoint=val.Endpoint+'__TEST'; // Changing the EndPoint to avoid PROD calls.
           val.principalType = 'NamedUser';
           val.protocol = 'NoAuthentication';
           updatelstVal.add(val);
         }
      }
     }
 System.debug('%%%'+updateMetadata(credential));

Error Message: COMPILE ERROR: Invalid type: MetadataService.NamedCredential LINE: 1 COLUMN: 1

1

1 Answer 1

0

I think NamedCredential can only be read through SOQL and fields are readonly.

So, you can explore protected custom settings to store the end points which you can update from apex.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .