How to add profile2 field data to a programatically created user I create a user from a form (that part works fine) but no profile2 information seems to be created....

profile2_load_by_user returns an empty array which results in the below error.  Do I need to some other step to first associate an "ae_sa" profile with the newly created user?


  Recoverable fatal error: Argument 1 passed to profile2_save() must be an instance of Profile, instance of stdClass given, called in D:\FULLREPO\trunk\sites\all\modules\sps_users\sps_users.module on line 115 and defined in profile2_save() (line 291 of D:\FULLREPO\trunk\sites\all\modules\profile2\profile2.module).


...
$account = user_save(null, $new_user);
$obj_user = user_load($account-&gt;uid) ;
$profile2 = profile2_load_by_user($obj_user) ;
$profile2["ae_sa"]-&gt;field_full_name[LANGUAGE_NONE][0]["value"] = $fullname;
$profile2["ae_sa"]-&gt;field_title_role[LANGUAGE_NONE][0]["value"] = $titlerole;
$profile2["ae_sa"]-&gt;field_company[LANGUAGE_NONE][0]["value"] = $ucompany;
$profile2["ae_sa"]-&gt;field_bio[LANGUAGE_NONE][0]["value"] = $bio;
profile2_save($profile2["ae_sa"]) ;
You need to create the new user's profile:

$profile = profile2_load_by_user($user-&gt;uid, 'ae_sa');
if(empty($profile)) {
  $profile = profile2_create(array(
    'type' =&gt; 'ae_sa',
    'uid' =&gt; $user-&gt;uid,
  ));
}

// Fill fields
$profile-&gt;field_full_name[LANGUAGE_NONE][0]["value"] = $fullname;
$profile-&gt;field_title_role[LANGUAGE_NONE][0]["value"] = $titlerole;
$profile-&gt;field_company[LANGUAGE_NONE][0]["value"] = $ucompany;
$profile-&gt;field_bio[LANGUAGE_NONE][0]["value"] = $bio;

// Save the newly created OR updated profile
profile2_save($profile);