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
psrpsr 

can we instert null values in mapkey value

sfdcfoxsfdcfox

Yes, null is always a valid map key for any type of map key (including primitives, sobjects, and user-defined objects).

Sean TanSean Tan

Do you mean doing something like this?

 

Map<String, String> myMap = new Map<String, String>{};
myMap.put('key1', null);

 If so, then yes you can do that.

psrpsr

map <srtring, string > map1 = new map <string,string> ();

map1.put <null,keypair1>

 

is it  possible?

Sean TanSean Tan

Yea, though just like any other key you can only have one "value" associated with it.

Bhawani SharmaBhawani Sharma
Map<string,string> map1 = new Map<String,String>();
map1.put(null, 'Salesforce');
System.debug(map1);
Bhawani SharmaBhawani Sharma
Yes, this is valid
Map<string,string> map1 = new Map<String,String>();
map1.put(null, 'Salesforce');
System.debug(map1);