• ravindra singh 17
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Could someone please explain how the .split method works in a String?

I am facing this line in a code:
String domain = myContact.Email.split('@').get(1);
I believe it is trying to capture the domain of an email address (and assign it to the variable domain), so if the email address is, for example: firstName.LastName@salesforce.com, the above line of code is probably capturing the domain 'salesforce.com' and assigns it to the variable.

But how does it do it? How does this .split method works= I do not understand this bit: .split('@').get(1);

When looking at Salesforce String methods here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm , and searching by .split, I find the following method/description:

User-added image
so, even if I do not understand how could this method possibly return a "list", I sort of guess that it returns a substring that is terminated by a regular expression that, in my line of code would be '@' ? But, this does not make sense in my line of code as the substring in it that terminates with '@' would in fact be firstName.LastName (not salesforce.com). 

Also, what is the .get(1) doing in this line of code?

Thank you very much.
Edge browser issue in drag drop functionality.
It is failling only one scenario which is given below.

FileReaderOnload function is giving "SecurityError" exception in edge browser. This we are getting only when we trying to read files before inserting the attachment from hidden lightning component. 

 
var objFileReader = new FileReader();
// set onload function of FileReader object   
objFileReader.addEventListener("load",function(loadevent){
var fileContents = loadevent.target.result;
var base64 = 'base64,';
var dataStart = fileContents.indexOf(base64) + base64.length;
fileContents = fileContents.substring(dataStart);
// call the uploadProcess method 
self.uploadProcess(component,event,helper,file, fileContents, accountId,TypeOfFile);
                });
objFileReader.onerror = function (e) {
console.log('objFileReader error::::',e.target.error);
};
objFileReader.readAsDataURL(file);
 



 
Could someone please explain how the .split method works in a String?

I am facing this line in a code:
String domain = myContact.Email.split('@').get(1);
I believe it is trying to capture the domain of an email address (and assign it to the variable domain), so if the email address is, for example: firstName.LastName@salesforce.com, the above line of code is probably capturing the domain 'salesforce.com' and assigns it to the variable.

But how does it do it? How does this .split method works= I do not understand this bit: .split('@').get(1);

When looking at Salesforce String methods here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm , and searching by .split, I find the following method/description:

User-added image
so, even if I do not understand how could this method possibly return a "list", I sort of guess that it returns a substring that is terminated by a regular expression that, in my line of code would be '@' ? But, this does not make sense in my line of code as the substring in it that terminates with '@' would in fact be firstName.LastName (not salesforce.com). 

Also, what is the .get(1) doing in this line of code?

Thank you very much.