0

I have a record for External Data Source Named as ED1 which is password protected having below details.

DeveloperName   ED1
Endpoint        abc.com
IsDeleted       FALSE
IsWritable      FALSE
MasterLabel     ED1
PrincipalType   NamedUser
Protocol        Password
Type            OData

I need to write a script which will make Endpoint as null whenever I do a sandbox refresh. How can I achieve it? I tasted with below code and getting Error as ' Unresolved data provider Apex class reference: '

global static void externalDataSource(){
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        
        MetadataService.ExternalDataSource externalDataSource = new MetadataService.ExternalDataSource();
        externalDataSource.fullName = 'ED1';
        externalDataSource.endpoint = null;
        externalDataSource.principalType = 'NamedUser';
        externalDataSource.Protocol = 'Password';
        
        MetadataService.SaveResult[] results = service.updateMetadata(
            new List<MetadataService.Metadata>{ externalDataSource }
        );
        
        for (MetadataService.SaveResult result : results) {
            if (result.success) {
                //Success
                System.debug(result);
            } else {
                //Failed
                System.debug(result.errors[0].message);
            }
        }
    }

1 Answer 1

0

I have added the extra parameters to make it work as below. These are some of the required fields needed in Metadata API as well as in Tooling API.

MetadataService.ExternalDataSource externalDataSource = new MetadataService.ExternalDataSource();
externalDataSource.fullName = 'ED1';
externalDataSource.endpoint = 'dumyURL';
externalDataSource.label = 'ED1';
externalDataSource.principalType = 'NamedUser';
externalDataSource.Protocol = 'Password';
externalDataSource.type_x = 'OData';
externalDataSource.username = 'sfdcodatauser';

You must log in to answer this question.

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