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

Bug with String.join()


A class implementing an override for public String toString() will not have this function honored by String.join(). Instead, it returns the name of the class. Using the normal concatenation operator on the list yields output that is expected.



<apex:page controller="repro">
                <td>new sub1().tostring()</td>
                <td>''+(new sub1[] { new sub1() })</td>
                <td>string.join(new sub1[] { new sub1() }, '')</td>
                <td>new sub2().tostring()</td>
                <td>''+(new sub2[] { new sub2() })</td>
                <td>string.join(new sub2[] { new sub2() }, '')</td>


public with sharing class repro {
    class sub1 {
    class sub2 {
        public override string tostring() {
            return 'Hello. I am sub2.';
    public string getSub1ToString() {
        return new sub1().tostring();
    public string getSub1AsJoin() {
        return string.join(new sub1[] { new sub1() }, '');

    public string getSub1AsList() {
        return ''+(new sub1[] { new sub1() });
    public string getSub2ToString() {
        return new sub2().tostring();
    public string getSub2AsJoin() {
        return string.join(new sub2[] { new sub2() }, '');
    public string getSub2AsList() {
         return ''+(new sub2[] { new sub2() });

 Output from above:


new sub1().tostring()sub1:[]
''+(new sub1[] { new sub1() })(sub1:[])
string.join(new sub1[] { new sub1() }, '')repro$sub1
new sub2().tostring()Hello. I am sub2.
''+(new sub2[] { new sub2() })(Hello. I am sub2.)
string.join(new sub2[] { new sub2() }, '')



As one can see, It's not even trying to join them together, it's just calling some sort of odd "List<Object>.getType()" function that we can't even access.


I've logged a case with support, but since I'm half-expecting them to just close it without even trying to log a bug, I'm also posting this here hoping that some PM or internal developer will see this and have it fixed at some point.



Thank you for bringing this to our notice. From the summary i understand that the toString() override is not working as expected. I will try to reproduce this issue on my end and if required will forward it to the right team within Salesforce.



Satish Kumar

Thanks! You can copy and paste the code above to replicate it directly, so it should be easy to prove.
This is still not addressed, any update Satish?