Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO exception error when setting field security settings #77

Closed
RandyTrigg opened this issue Mar 12, 2015 · 3 comments
Closed

IO exception error when setting field security settings #77

RandyTrigg opened this issue Mar 12, 2015 · 3 comments

Comments

@RandyTrigg
Copy link

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
@RandyTrigg
Copy link
Author

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

@afawcett
Copy link
Contributor

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

@dennomwas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants