Passing $form_state data into \Drupal::entityQuery('user') I have the following D8 form 

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['bulk_perfplans_roles'] = array(
      '#type'          =&gt; 'checkboxes',
      '#title'         =&gt; $this-&gt;t('Generate plans for which roles?'),
      '#options'       =&gt; user_role_names(),
    );
    $form['bulk_add'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Create new Performance Plans'),
    );

    return $form;
  }


I'm trying to pass the information into an entityQuery as follows...

  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    $selectedRole = $form_state-&gt;get('bulk_perfplans_roles');
    $uids = \Drupal::entityQuery('user')
      -&gt;condition('roles', $selectedRole)
      -&gt;sort('created', 'ASC')
      -&gt;execute();


I'm trying to make it so it conditionally alters the query based on the user selected roles from $form_state. It's currently not working, and I'm not sure where to go next. Any thoughts?
Does $selectesRole have the expected value? I'm pretty sure you want to use $form_state-&gt;getValue('bulk_perfplans_roles') instead. Details here. 

Also is it a single value field? You may need to pass an additional IN parameter to your field condition and do some additional prep if the result from getValue is an array. 

Also make sure you're passing the machine name of the role and not the label.