Jira is not aware of all customfields onStart

Hey guys,

I’m having a bit of trouble with a PluginEnabledEvent listener… My plugin requires to check and install some Custom Fields on install - but - It cannot find the first ones (usually one or two) before creating them.

        List<CustomField> cfields = new LinkedList<CustomField>();
        for (CustomFieldInfo customFieldInfo : customFieldNames) {
            try {
                Collection<CustomField> customFields = customFieldManager.getCustomFieldObjectsByName(customFieldInfo.name);
                if (customFields.isEmpty()){ // I'm getting a true value here for first fields...
                  // creates the custom field... causing duplicates sometimes
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

I’ve implemented the Listener just as suggested by
https://bitbucket.org/cfuller/atlassian-scheduler-jira-example/src/371cbc419c5a4fa3197d4dc28ddeb21105718a43/src/main/java/com/atlassian/jira/plugins/example/scheduler/impl/AwesomeLauncher.java?at=master&fileviewer=file-view-default&_ga=2.200406702.1851830901.1505767147-1136806911.1495460843

Even so, I had to implement a workaround to remove the duplicates afterwards - solution works as intended, but I may be missing something important here on dealing with CustomFieldManager.

Any hints on what I’m missing out?

Thanks in advance