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
SabrentSabrent 

Illegal assignment from LIST<string> to String

Any suggestions,  what I can  do to overcome this error?  thanks.

 

 

for(BulkLoadDataHolder bldhrec : dataHolderList){
                    
                    Student_Tracking__c strec = new Supplier_Tracking__c();
                    strec.Program__c = this.blRec.Program__c;
                    strec.Email_Address__c = bldhrec.Email_Address;
                    string s = bldhrec.Email_Address.split('@',2);    // Illegal assignment from LIST<string> to String
                    strec.D_Name = s;    
                    system.debug('DomainName is' +strec.Domain_Name__c );

......

}

Best Answer chosen by Admin (Salesforce Developers) 
Clap MasterClap Master

The string split() method returns an array of strings, not a single string.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

All Answers

Clap MasterClap Master

The string split() method returns an array of strings, not a single string.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

This was selected as the best answer
BritishBoyinDCBritishBoyinDC

Assuming you are on Winter 13, you can use one of the new nifty string methods  e.g.

 

String s = 'testbfc@test.com';

String s2 = s.substringBefore('@');

system.assertequals('testbfc',s2);

 

SabrentSabrent

Thanks everyone for all the replies.

 

I realized split() returns an array and strings and accordingly rectified my code.

 

we are not yet on Winter 13 so can't use substringBefore.