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);
}
}
}