0

I'm trying to access LeadConvertSettings via MetadataService class but it's not working properly.

List<MetadataService.LeadConvertSettings> result;
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.IReadResult readResult = service.readMetadata('LeadConvertSettings', new List<String>{'Lead'});
result = (List<MetadataService.LeadConvertSettings>) readResult.getRecords(); 
System.debug('** ' + JSON.serialize(result));

If I put a null or empty list as second parameter for readMetadata it gives me an error. With the previous piece of code it's giving me the following:

[{"fullName_type_info":["fullName","http://www.w3.org/2001/XMLSchema","string","0","1","false"],"fullName":null,"field_order_type_info":["fullName"],"apex_schema_type_info":["http://soap.sforce.com/2006/04/metadata","true","false"],"type_att_info":["xsi:type"],"type":"LeadConvertSettings","opportunityCreationOptions_type_info":["opportunityCreationOptions","http://soap.sforce.com/2006/04/metadata",null,"0","1","false"],"opportunityCreationOptions":null,"objectMapping_type_info":["objectMapping","http://soap.sforce.com/2006/04/metadata",null,"0","-1","false"],"objectMapping":null,"fullName_type_info":["fullName","http://soap.sforce.com/2006/04/metadata",null,"0","1","false"],"fullName":null,"field_order_type_info":["fullName","allowOwnerChange","objectMapping","opportunityCreationOptions"],"apex_schema_type_info":["http://soap.sforce.com/2006/04/metadata","true","false"],"allowOwnerChange_type_info":["allowOwnerChange","http://soap.sforce.com/2006/04/metadata",null,"0","1","false"],"allowOwnerChange":null}]

Is there anything I'm doing wrong? Or is this even achievable?

Regards,

0

You need to pass it's fullName in the second parameter which is LeadConvertSettings. So if you update the line like below it will return the Lead Convert Settings correctly.

MetadataService.IReadResult readResult = service.readMetadata('LeadConvertSettings', new List<String>{'LeadConvertSettings'});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.