Build SOQL query with Like operator and how to use in flow action.
						
					
					
				
			
		
	
			
	
	
	
	
	
Options
			
				
					
	
			
		
	- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2023 07:01 AM
Hi Everyone,
I am trying to fetch the active customer details by using Like operator from Salesforce. but i am getting errors in pre processing step in flow action. This is query used in flow action
var query ="?q=Select Name,Id,DTN_Text__c from+Account+where+Name +like+ '%' + name + '%'" ;
actual SOQL query: select Name, Id where Name like '%test%' and status_c='Active'
Please, can any one help on this.
Thanks in Advance.
		1 REPLY 1
	
		
		
			
			
			
					
	
			Options
			
				
					
	
			
		
	- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 07:11 AM
Running
;
(function () {
	const QUOTED_STRING_ESCAPE_SEQ = {
		'\r': '\\R',
		'\n': '\\N',
		'\t': '\\T',
		'\x07': '\\B',
		'\f': '\\F',
		':': '\\"',
		'\'': '\\\'',
	};
	const QUOTED_LIKE_ESCAPE_SEQ = Object.extend(QUOTED_STRING_ESCAPE_SEQ, {
		'_': '\\_',
		'%': '\\%',
	});
	var name = '100%_ACME Inc.',
		queryTemplate = "?q=SELECT name, id, dtn_text__c FROM Account WHERE name LIKE '%{0}%' AND status_c = 'Active'",
		query = formatString(queryTemplate, [escapeStringForLikeQueryOperand(name)]);
	gs.debug(query);
	function escapeStringForLikeQueryOperand (string) {
		return String(string)
			.replace(/[\\]/g, '\\\\')
			.replace(/([\r\n\t\x07\f"'_%])/g, getByMemberReplacer(QUOTED_LIKE_ESCAPE_SEQ));
	}
	function formatString (template, replacers) {
		return String(template).replace(/\{\s*(\d+)\s*\}/g, getByIndexReplacer(replacers));
	}
	function getByIndexReplacer (replacers) {
		return function replace (fullMatch, captureGroup_1) {
			return replacers[+captureGroup_1] == null ? fullMatch : replacers[+captureGroup_1];
		};
	}
	function getByMemberReplacer (replacers) {
		return function replace (fullMatch, captureGroup_1) {
			return replacers[captureGroup_1] == null ? fullMatch : replacers[captureGroup_1];
		};
	}
})();
in Scripts - Background prints:
*** Script: [DEBUG] ?q=SELECT name, id, dtn_text__c FROM Account WHERE name LIKE '%100\%\_ACME Inc.%' AND status_c = 'Active'
