function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
yogesh goadyogesh goad 

Error: Compile Error: Invalid type: ReadResult at line 5 column 9

i get the following error while saving the below code in a apex class.
Error: Compile Error: Invalid type: ReadResult at line 5 column 9
 
public with sharing class MetadataController {
public void readCustomObjectSync() {
    try {
        ReadResult readResult = metadataConnection
                .readMetadata('CustomObject', new String[] {
                        'MyCustomObject1__c', 'MyCustomObject2__c' });
        Metadata[] mdInfo = readResult.getRecords();
        System.debug('Number of component info returned: '
                + mdInfo.length);
        for (Metadata md : mdInfo) {
            if (md != null) {
                CustomObject obj = (CustomObject) md;
                System.debug('Custom object full name: '
                        + obj.getFullName());
                System.debug('Label: ' + obj.getLabel());
                System.debug('Number of custom fields: '
                        + obj.getFields().length);
                System.debug('Sharing model: '
                        + obj.getSharingModel());
            } else {
                System.debug('Empty metadata.');
            }
        }
    } catch (ConnectionException ce) {
        ce.printStackTrace();
    }
 }
}

 
SonamSonam (Salesforce Developers) 
Which API version are you using?ReadResult is available in API version 30.0 and later.
Kindly confirm if the version is compliant of the above.
yogesh goadyogesh goad

hey sonam,
thanks for the help.
i have already set the API to 32.0 in version setting. 
i also created and saved a class with getDescribe() method (of the schema class) and its using API 32.0.