certinia / apex-mdapi

Apex Wrapper for the Salesforce Metadata API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IO exception error when setting field security settings

RandyTrigg opened this issue · comments

Hi there,

I'm a total newbie to the MetadataService class, and excited by its possibilities. After downloading the class from github into a sandbox, I wrote a method to make fields editable following the advice in https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AVifIAG

I get this error: System.CalloutException: IO Exception: Read timed out

I'm betting there's some bit of setup that I haven't done. Here's my code. Anyone see anything obviously wrong (I've tried changing the p.custom setting to true and leaving it out altogether to no avail)?

public static void makeFieldsEditable (String[] profileNames, String[] fieldNames) {
    MetadataService.MetadataPort service = createService();
    List<MetadataService.Profile> profiles = new List<MetadataService.Profile>();
    for (String pName : profileNames) {
        MetadataService.Profile p = new MetadataService.Profile();
        p.fullName = pName;
        p.custom = false;
        p.fieldPermissions = new List<MetadataService.ProfileFieldLevelSecurity>();
        for (String fName : fieldNames) {
            MetadataService.ProfileFieldLevelSecurity fSec = new MetadataService.ProfileFieldLevelSecurity();
            fSec.field = fName;
            fSec.editable = true;
            p.fieldPermissions.add(fSec);
        }
        profiles.add(p);
    }
    List<MetadataService.SaveResult> results = service.updateMetadata(profiles);
    handleSaveResults(results[0]);
}

Thanks!

  • Randy Trigg

Oops - I should have researched that error before submitting an issue. I see now that I needed to increase the timeout value for the webservices callout that MetadataService makes to compute results. And it's easy to do that using the handy timeout__x field of the MetadataPort class. I modified createService like so, and all is well:

    public static MetadataService.MetadataPort createService()
    { 
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        service.timeout_x = 40000;
        return service;     
    }    

Awesome work, i've referenced this as a known issue and resolution in the readme!

Thanks so much @RandyTrigg This was all I needed to past the blocker