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
sldringsldring 

Unable to set HasOptedOutOfEmail property of Lead object

While creating a Lead using the WSDL generated from salesforce.com for my developer account, if I specify Lead.HasOptedOutOfEmail property to true (boolean value), then it doesn't reflect this true value in the Lead created while viewing the lead at salesforce.com!!!

Any suggestions???

DevAngelDevAngel

Hi sldring,

.Net requires that when you want to set a boolean property in the generated proxy class that you set a sister property <field>Specified.  This sister property is not in the wsdl and was added by .Net when the proxy was generated.  So in your code you need 2 lines to set the HasOptedOutOfEmail property.

Lead.HasOptedOutOfEmail = true;

Lead.HasOptedOutOfEmailSpecified = true;

Why?  Although I don't have the official word from Microsoft, I believe this is due to certain types in .Net not actually being objects.  A string type is an object that can be null.  A boolean type is not an object and if not explicitly initialized contains the value false. 

When serializing the lead class for example, .Net does not include any properties that are null in the soap message.  This means that when a lead is instantiated, some properties are not null and were not set by you.  This holds for several types, boolean and dateTime come immediately to mind.  So to determine if you set a boolean property, .Net includes an additional property, <property>Specified property.  Setting this to true lets .Net know that you did set that property and that you want it included in the soap request.

Our API allows you to set fields to null by using the fieldsToNull parameter.  If you want to set a field to null you include it in a string array on the SObject class call fieldsToNull.  Any field names in this array for each object will be set to null in the database if the field is nillable.

Cheers