{"action":"opened","issue":{"url":"https://api.github.com/repos/financialforcedev/apex-mdapi/issues/76","labels_url":"https://api.github.com/repos/financialforcedev/apex-mdapi/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/financialforcedev/apex-mdapi/issues/76/comments","events_url":"https://api.github.com/repos/financialforcedev/apex-mdapi/issues/76/events","html_url":"https://github.com/financialforcedev/apex-mdapi/issues/76","id":59301178,"number":76,"title":"Can't update field-level security within a for loop","user":{"login":"david-berman","id":6333771,"avatar_url":"https://avatars.githubusercontent.com/u/6333771?v=3","gravatar_id":"","url":"https://api.github.com/users/david-berman","html_url":"https://github.com/david-berman","followers_url":"https://api.github.com/users/david-berman/followers","following_url":"https://api.github.com/users/david-berman/following{/other_user}","gists_url":"https://api.github.com/users/david-berman/gists{/gist_id}","starred_url":"https://api.github.com/users/david-berman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/david-berman/subscriptions","organizations_url":"https://api.github.com/users/david-berman/orgs","repos_url":"https://api.github.com/users/david-berman/repos","events_url":"https://api.github.com/users/david-berman/events{/privacy}","received_events_url":"https://api.github.com/users/david-berman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-27T22:04:52Z","updated_at":"2015-02-27T22:04:52Z","closed_at":null,"body":"Hi,\r\n\r\nI can update the FLS for one field at a time using:\r\nMetadataServiceExamples.updateFieldLevelSecurity( 'Admin', 'Test_Object__c',\r\n'Test_Field__c');\r\n\r\nI created version of the original class to which I can pass the object name and field name.\r\n\r\nI use a loop to create a bunch of fields that I'm reading from another object (with field label, field api name, field type, length, etc) and as part of that loop I want to update the FLS.  The problem arises in the if(bContinue == true) block below.  There is no error message, but no updates occur (the fields are added correctly though).  \r\n\r\nI hope you can help.  Thank you!\r\n-David\r\n\r\nString sObjectAPIName = 'Test_Object__c';\r\n\r\nList<Object_Configuration__c> configs = new List<Object_Configuration__c>\r\n([Select Object_Name__c, Field_Label__c, Field_API_Name__c, Field_Type__c, Field_Length__c, Field_Precision__c, Field_Help_Text__c from Object_Configuration__c\r\nwhere Object_Name__c =: sObjectAPIName\r\n]);\r\n\r\nMap<ID, Object_Configuration__c> configMap = new Map<ID, Object_Configuration__c>\r\n([Select Object_Name__c, Field_Label__c, Field_API_Name__c, Field_Type__c, Field_Length__c, Field_Precision__c, Field_Help_Text__c\r\nfrom Object_Configuration__c]);\r\n\r\nfor(Object_Configuration__c ocs : configs)\r\n{\r\ntry\r\n{\r\nBoolean bContinue = false;\r\n\r\nif(configMap.get(ocs.Id).Field_Type__c == 'Boolean')\r\n{\r\nMetadataServiceExamples.createFieldTypeBoolean( configMap.get(ocs.Id).Object_Name__c,\r\nconfigMap.get(ocs.Id).Field_Label__c,\r\nconfigMap.get(ocs.Id).Field_API_Name__c,\r\nconfigMap.get(ocs.Id).Field_Help_Text__c);\r\nbContinue = true;\r\n}\r\n[...]\r\nelse{}\r\n\r\nif(bContinue == true)\r\n{\r\nMetadataServiceExamples.updateFieldLevelSecurity( 'Admin', configMap.get(ocs.Id).Object_Name__c,\r\nconfigMap.get(ocs.Id).Field_API_Name__c);\r\n    \r\n}\r\n}\r\ncatch(Exception e)\r\n{\r\nif(e.getMessage().contains('DUPLICATE_DEVELOPER_NAME')) continue;\r\nelse system.debug('+++++++ OTHER ERROR: ' + e.getMessage());\r\n}\r\n}"}}