0

Hello I am trying to retrieve a record type to update its picklist values but whenever i try to do this it returns a weird object which has most of its values as null and I tried to use a name of a record that does not exist and it returned the same result so I think it cannot find the record type that I specifying for some reason . Here is the code that I am using

MetadataService.MetadataPort service = new MetadataService.MetadataPort();             
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.Metadata[] mdRecordType = service.readMetadata(
        'RecordType', new String[]{'test_2'}
                ).getRecords();
System.debug(mdRecordType);

and here is the debug output

12:12:38.1 (565683411)|USER_DEBUG|[22]|DEBUG|(RecordType:[Metadata.fullName=null, active=null, active_type_info=(active, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), businessProcess=null, businessProcess_type_info=(businessProcess, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), compactLayoutAssignment=null, compactLayoutAssignment_type_info=(compactLayoutAssignment, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, active, businessProcess, compactLayoutAssignment, description, label, picklistValues), fullName=null, fullName_type_info=(fullName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), label=null, label_type_info=(label, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), picklistValues=null, picklistValues_type_info=(picklistValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), type=RecordType, type_att_info=(xsi:type)])

2
  • 1
    Since RecordType's are part of an object, wouldn't you need to specify the sobject name in the RecordType name, e.g. Account.test_2 instead of just test_2? Commented Sep 28, 2022 at 13:15
  • 1
    @PhilHawthorn yes thank you that worked Commented Sep 29, 2022 at 7:41

1 Answer 1

0

RecordType's are part of an SObject (custom or standard) and cannot be retrieved without fully qualifying the RecordType with the SObject name as well. So, your code needs to specify the SObject to which the RecordType belongs to, for example:

MetadataService.MetadataPort service = new MetadataService.MetadataPort();             
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.Metadata[] mdRecordType = service.readMetadata(
        'RecordType', new String[]{'Account.test_2'}
                ).getRecords();
System.debug(mdRecordType);

Where Account is the SObject and test_2 is the RecordType.

You must log in to answer this question.

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