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

Splitting text into multiple fields



On our webform we are capturing a lot of data that we want to try and make use off in Salesforce. The forms are comming from our marketing system (Eloqua). 


An example of what we get: 


a0TD0000008NSnbMAG|To purchase products or services^\a0TD0000008NSmnMAG|Fixed Stock^\a0TD0000008NSnCMAW|USD $0-5m^\a0TD0000008NSnHMAW|Consultants ^\a0TD0000008NSnMMAW|Not applicable^


the record ID is the “question” – held on a custom object of us called Project Profiling

then there is a pipe

then the answers (either single or multi select)

^ separates the multi select answers

^\ separates the next question


Basically I want to be able to see on a project attendance:


Q1: Question (text)  - answer/s

Q2: Question (text) – answer/s



Any Ideas on if this can be achieved? 








You can use the split function to break up the data you are receiving from Eloqua.  Here's a simple test class I wrote to guide you in your effort.  The split function takes a regex, so if you are escaping characters, you have to escape the escape(!) to ensure the regex gets the correct string passed into it.

private class GenericTest {
	static final Integer QUESTION = 0;
	static final Integer ANSWERS = 1;
	static testMethod void myTest() {
		String sampleText = 'a0TD0000008NSnbMAG|To purchase products or services^\\a0TD0000008NSmnMAG|Fixed Stock^\\a0TD0000008NSnCMAW|USD $0-5m^\\a0TD0000008NSnHMAW|Consultants ^\\a0TD0000008NSnMMAW|Not applicable^';
		System.debug('sampleText: ' + sampleText);
		String[] questions = sampleText.split('\\^\\\\');
		System.debug('questions: ' + questions);
		for (String q : questions) {
			System.debug('q: ' + q);
			String[] questionParts = q.split('[|]');
			System.debug('Question: ' + questionParts[QUESTION]);
			System.debug('Answers: ' + questionParts[ANSWERS]);