function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Outcoursing1Outcoursing1 

Setting Email Field in Contact Upsert using PHP

I am having trouble directly setting the Email field in my upsert.  I have custom fields which are also have a type of "email". (np01__home_email__c,  np01__alternateemail__c).   The Email field takes the value of the last custom email field I set in the upsert even if i specifically set Email.  

 

$sObject->fields['npe01__AlternateEmail__c'] = htmlspecialchars(stripslashes(strip_tags($row['email'])));

$sObject->fields['npe01__HomeEmail__c'] = 'test@test.com';

$sObject->fields['Email'] = htmlspecialchars(stripslashes(strip_tags($row['email'])));

$sObject->Email = htmlspecialchars(stripslashes(strip_tags($row['email']))); 

 

 

When i upsert that object, the Email field ends up as 'test@test.com'.   As you can see, I tried to set ->fields['Email'], as well as ->Email to no avail.  

 

Can anyone see anything wrong with what I am doing? 

Best Answer chosen by Admin (Salesforce Developers) 
Park Walker (TAGL)Park Walker (TAGL)

The non-profit template has some customizations that are getting in your way. There is a field 'np01__Preferred_Email__c' that should be set to the value which reflect the np01__x email field that you wish to use as the main email address.

 

If you want np01__home_email__c to be the primary email address, set that field to the email address and set 'np01__Preferred_Email__c' to 'Home'. Do not bother to set Email as it will be overridden when you set the other fields.  

 

Park 

All Answers

Park Walker (TAGL)Park Walker (TAGL)

The non-profit template has some customizations that are getting in your way. There is a field 'np01__Preferred_Email__c' that should be set to the value which reflect the np01__x email field that you wish to use as the main email address.

 

If you want np01__home_email__c to be the primary email address, set that field to the email address and set 'np01__Preferred_Email__c' to 'Home'. Do not bother to set Email as it will be overridden when you set the other fields.  

 

Park 

This was selected as the best answer
Outcoursing1Outcoursing1
Thank you!  This confirms my suspicions.