Hi all.
I've been racking my brain on this one now, I tried $bean->updateCalculatedFields(); but it's not working. Currently I am filling in missing records, so I am creating: Lead -> Contact/Account -> Opportunity -> Meeting, they all have a "unique" ID between them that is generated. On all modules apart from the Lead it is a calculated field. But when adding the links between the modules and doing a $bean->save() it's not actually adding the calculated fields in.
I tried another save after the fact as well but had no luck. Here's an example of the creation:
//Create Account
$account = BeanFactory::newBean('Accounts');
$account->customer_salutation_c = $title;
$account->customer_first_name_c = $firstName;
$account->customer_last_name_c = $lastName;
$account->first_name_c = $firstName;
$account->last_name_c = $lastName;
$account->name = "$firstName $lastName ($firstName $lastName)"; //This matches formula on leads
$account->gender_c = $gender;
$account->date_of_birth_c = $dateOfBirth;
$account->age_c = $age;
$account->billing_address_street = $street;
$account->billing_address_city = $town;
$account->billing_address_state = $county;
$account->billing_address_postalcode = $postCode;
$account->phone_home_c = $phone;
$account->phone_mobile_c = $mobile;
$account->email1 = $email;
//$account->a_branch_accounts_name = $branch; //Should link branches automatically
$account->created_by = 1;
$account->save();
//Create Contact
$contact = BeanFactory::newBean('Contacts');
$contact->salutation = $title;
$contact->first_name = $firstName;
$contact->last_name = $lastName;
$contact->name = "$firstName $lastName"; //This matches formula on leads
$contact->gender_c = $gender;
$contact->date_of_birth_c = $dateOfBirth;
$contact->age_c = $age;
$contact->primary_address_street = $street;
$contact->primary_address_city = $town;
$contact->primary_address_state = $county;
$contact->primary_address_postalcode = $postCode;
$contact->phone_home = $phone;
$contact->phone_mobile = $mobile;
$contact->email1 = $email;
$contact->created_by = 1;
$contact->save();
//Create Opp
$opp = BeanFactory::newBean('Opportunities');
$opp->customer_salutation_c = $title;
$opp->customer_first_name_c = $firstName;
$opp->customer_last_name_c = $lastName;
$opp->name = "$firstName $lastName"; //This matches formula on leads
$opp->customer_full_name_c = "$firstName $lastName"; //This matches formula on leads
$opp->gender_c = $gender;
$opp->date_of_birth_c = $dateOfBirth;
$opp->age_c = $age;
$opp->primary_address_street_c = $street;
$opp->primary_address_city_c = $town;
$opp->primary_address_state_c = $county;
$opp->primary_address_postalcode_c = $postCode;
$opp->phone_home_c = $phone;
$opp->phone_mobile_c = $mobile;
$opp->email1 = $email;
$opp->created_by = 1;
$opp->save();
//Create Lead
$lead = BeanFactory::newBean('Leads');
$lead->customer_salutation_c = $title;
$lead->customer_first_name_c = $firstName;
$lead->customer_last_name_c = $lastName;
$lead->first_name = $firstName;
$lead->last_name = $lastName;
$lead->name = "$firstName $lastName"; //This matches formula on leads
$lead->gender_c = $gender;
$lead->date_of_birth_c = $dateOfBirth;
$lead->age_c = $age;
$lead->primary_address_street = $street;
$lead->primary_address_city = $town;
$lead->primary_address_state = $county;
$lead->primary_address_postalcode = $postCode;
$lead->phone_home = $phone;
$lead->phone_mobile = $mobile;
$lead->email1 = $email;
//Non fields
$lead->status = 'Converted';
$lead->converted = 1;
$lead->contact_id = $contact->id;
$lead->account_id = $account->id;
$lead->team_id = 1;
$lead->team_set_id = 1;
$lead->created_by = 1;
$lead->save();
//Process relationships
$contact->load_relationship('leads');
$contact->leads->add($lead->id);
$account->load_relationship('contacts');
$account->contacts->add($contact->id);
$opp->load_relationship('accounts');
$opp->accounts->add($account->id);
$contact->save();
$account->save();
$opp->save();
Thanks!