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
renurenu 

Cannot update Multiselect picklist to null

I had a situtation where i need to update the Multi select picklist to null.
 
I am checking the condition where if checkbox.checked = false then update muti select picklist to null and also tried passing the empty string. In Both the conditions the value is not getting updated.
 
If i pass a string value then it is getting updated.
 
Can someone plz throw an idea.
 
Thanks
canonwcanonw
This is how to set a value to null.  And I think this also apply to picklist type value.

1.  Set the value as space character (" ").
2.  Set the related specificed field, if any, to true.

Please let us know if it works.
SuperfellSuperfell
use the fieldsToNull property.
renurenu

Thanks for the quick response. programmed in the following way

I tried the way you responded. That is working. But i want to store null value in that list. What if i need to run a report in the Dashboard and specify the contact.Direct=null .

Thats the reason why i want to store the value as null instead of passing the string with spaces.(Remember this is not picklist this is a MultiSelect Picklist). and there is no cSpecified for this.

string dmail="Select Direct_Mail__c from Contact where id='" + Session["ContactId"].ToString() + "'";

QueryResult qr2 = binding.query(dmail);

sObject[] records2 = qr2.records;

if (records2.Length > 0)

{

for (int i=0; i<records2.Length; i++)

{

Contact ct=(Contact)records2[i];

if (ct.Direct_Mail__c == null)

{

Session["directmail"]=" ".ToString();

}

else

{

Session["directmail"]=ct.Direct_Mail__c.ToString();

}

And in the data grid events,
 

case "Add":

CheckBox ch=(CheckBox)(e.Item.Cells[0].FindControl("directMailcb"));

ch.Checked=true;

Contact ct=new Contact();

ct.Id=Session["ContactId"].ToString();

ct.Direct_Mail__c="Yes";

SaveResult[] saveResults = binding.update(new sForce.sObject[] {ct});

}

break;

case "Remove":

CheckBox ch=(CheckBox)(e.Item.Cells[0].FindControl("directMailcb"));

ch.Checked=true;

Contact ct=new Contact();

ct.Id=Session["ContactId"].ToString();

ct.Direct_Mail__c=null; // i need to store the value as null

SaveResult[] saveResults = binding.update(new sForce.sObject[] {ct});

}

break;

I havent used fieldstoNull property can you throw me an idea on that. Thanks again



Message Edited by renu on 08-06-2008 10:37 AM
SuperfellSuperfell
http://www.salesforce.com/us/developer/docs/api/index_CSH.htm#sforce_api_calls_concepts_core_data_objects.htm#i1421095
canonwcanonw
If I read your code correctly, you should place this code in the right place

Code:
ct.fieldToNull( new string[] {"Direct_Mail__c"} );
SaveResult[] saveResults = binding.update(new sForce.sObject[] {ct});

 

renurenu
Hello ,Thanks Again. I change my code above to the following way.
But still i am getting the error msg like "fieldstonull denotes a field where a method was expected"
Can you plz tell me why this is so.
 
I referenced the documentation in the above link. It looks like i am using the same syntax. Where can i get some more info on this topic (fieldstonull)

Contact ct=new Contact();

ct.Id=Session["ContactId"].ToString();

ct.fieldsToNull(new string[] {"Direct_Mail__c"});

SaveResult[] saveResults = binding.update(new sForce.sObject[] {ct});



Message Edited by renu on 08-06-2008 10:43 AM
SuperfellSuperfell
ct.fieldsToNull = new string[] {"Direct_Mail__c"};
renurenu

Thankyou for very quick response. I got the required output.

As this is very urgent requirement which i need to finish up.

And thanks again for all the solutions.



Message Edited by renu on 08-06-2008 12:23 PM
SuperfellSuperfell
remove this line
ct.Direct_Mail__c=" ";
renurenu
yes , yes i had seen that silly mistake . Thanks again!!!!!!
renurenu

 



Message Edited by renu on 08-22-2008 12:45 PM