But the problem is that for each field it is taking 4 to 5 seconds to update the FLS. Is there any way that we can have all the changes in the list and update the FLS in bulk.
Because you are adding the FLS within the iteration and that for every iteration, you are making an API call to update the FLS on the profile.
In order to what you are trying to do, I would try something as below.
- Declare an array of
ProfileFieldLevelSecurity []
outside the loop - Add the respective
ProfileFieldLevelSecurity
within the loop into that array - Set the array on the profile outside the loop
- Invoke the API just once, outside the loop
int index = 0;
// declare an array of ProfileFieldLevelSecurity outside the loop
ProfileFieldLevelSecurity [] fieldArray = new ProfileFieldLevelSecurity [updateReadList.length]; // or size() depending if updateReadList is an array or list
for(String field:updateReadList) {
ProfileFieldLevelSecurity fieldSec = new ProfileFieldLevelSecurity();
fieldSec.setField(field);
fieldSec.setReadable(true);
fieldSec.setEditable(false);
fieldArray[index++] = fieldSec; // add all the FLS attributes to an array
}
admin.setFieldPermissions(fieldArray); // set all field permissions added in the array out of the loop
api.updateMetadata(new Metadata[] {admin}); // call the update in bulk - just one single call