You need to sign in to do that
Don't have an account?
Parse string in custom object fields
string input = 'Lead Informations Program1: Installation Lead #: 7894512 Name: Salesforce Dev Email: test@gmail.com Phone: (000) 123-7897'; //Marker for final ring duraion Integer intIndex = input.lastindexOf('Lead Information'); system.debug('### intIndex'+intIndex); //Remove all characters before intIndex String newString = input.right(input.length()-intIndex); system.debug('### newString'+newString); system.debug('### newString ENd'); // split whole input into lines string[] lines = newString.split('[\n]+'); string regex = '([^:]+):([^:]+)'; Pattern MyPattern = Pattern.compile(regex); // Apply regex to every line for(string inputLine : lines){ matcher myMatcher = myPattern.matcher(inputLine.trim()); if(myMatcher.matches() && myMatcher.hitEnd() && myMatcher.groupCount() == 2){ system.debug('**** Match :'+myMatcher.group(1).trim() + '=>'+myMatcher.group(2).trim()); } else{ system.debug('No match: line :'+ inputLine); } }
String can be like this:
Example 1:
Lead Informations
Program1: Installation
Lead #: 7894512
Name: Salesforce Dev
Email: test@gmail.com
Phone: (000) 123-7897
Example 2:
Lead Informations
Program1:
Installation
Lead #:
7894512
Name:
Salesforce Dev
Email:
test@gmail.com
Phone: (000) 123-7897
Example 3:
Lead Informations
Program1:
Installation
Lead #:
7894512
Name:
Salesforce Dev
Email:
test@gmail.com
Phone: (000) 123-7897
I want to store all Lead #, Name, Email and Phone values to object fields But got stuck how to parse these strings mention above. above code is working for single line break but it does work for multiple line breaks.
Hi, David
Thank for help. I was thinking the same but labels Email, Name and others will not be in the same order. and one more thing I want to point out that we will have this piece of information in a big string
Example :
========================================================================================================
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lead Informations
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lead Informations
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lead Informations
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lead InformationsLorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lead Informations
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lead Informations
Program1: Installation
Lead #: 7894512
Name: Salesforce Dev
Email: test@gmail.com
Phone: (000) 123-7897
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
=============================================================================================================
So I also want to know that is there any way to parse this big string from bottom to top. So it will be easy to find lead information.