9

This is a simple "regular expression" situation. You can use the following code as a starting point: Pattern p = Pattern.compile('\\{!.+?\\}'); string templateContent = 'hello adrian , this is for {!Contact.Name} to be delivered to {!Account.ShippingAddress}'; Matcher m = p.matcher(templateContent); while(m.find()) { System.debug(m.group(0)); } Where \\...


6

The abbreviate method is a good choice: CusObj2.ProdName__c = CusObj2.Name__c.abbrevate(99); as it: Returns an abbreviated version of the String, of the specified length and with ellipses appended if the current String is longer than the specified length; otherwise, returns the original String without ellipses. where ellipses means three dots. ...


5

substring takes a length argument as the third option, and using the index value from the space gives 1 more length than the first name. Either skip adding 1 to the @WhiteSpacePos value, or use @WhiteSpacePos-1 as the length to substring.


5

Instead of tuncating your self why not let salesforce truncate it for you using dml options? string getBodyString = response.getBody(); logRecord.Status_Code__c = response.getStatusCode(); logRecord.Status__c = response.getStatus(); logRecord.Message__c = getBodyString; Database.DMLOptions dmo = new Database.DMLOptions(); dmo....


5

You can use the replaceAll() method from the String class. String testString = 'Hello;; my name is SF support.'; testString = testString.replaceAll(';;', ','); System.debug(testString); Result: Hello, my name is SF support.


4

First thing that comes to my mind is to use the String substringBefore(separator) method. String s1 = 'abuse@localhost'; String s2 = s1.substringBefore('@'); // s2 will contain 'abuse' From there, you can use the set contains() method to see if the first part of your email matches any of your targets. You would need to adjust your emails set to leave off ...


4

This is a classic bounds-overflow bug. Before you take a fixed-length substring or request a specific string index, you must check whether the string contains enough characters to respond to the request. In this case, you can either use the one-argument version of String.substring(), which starts at the specified index and goes to the end of the string, or ...


4

indexOfChar() needs to operate on an instance of a string (it's not a static method) e.g. String myStr = 'test'; system.debug(myStr.indexOfChar('s')); Trying to get at your value by substrings is a messy way to go about this though. Deserializing the JSON, and then using String.split('/') is probably going to be a lot cleaner/readable/reliable e.g. ...


4

We usually move the reusable piece of code to a common utility method. You can create a private method that will return the sanitized comment back. private static String getSanitizedComment(String input , String commentPart){ Integer commentStartIndex; //I'm trying to find here the first index of commentPart //if this is the beginning of the ...


3

Use left instead: z.Patient_Id_Help__c=z.Patient_Name__c.left(10); It does not throw an exception if there is less than 10 characters. Remember to check for null first, if applicable: if(z.Patient_Name__c != null) { z.Patient_Id_Help__c=z.Patient_Name__c.left(10); }


3

Your String is in fact valid JSON. Therefore, you can parse it into Map and get values by key. Map<String, Object> ans = (Map<String, Object>) JSON.deserializeUntyped(getResult); Integer toStore = (Integer) ans.get('httpStatus');


3

Use String.containsNone() to check whether a string contains any prohibited characters, or String.containsOnly() to check that it only contains a specific set of characters. That said, be aware that email addresses are a good deal more flexible than you might think, and special characters aren't necessarily invalid. Regular expressions are generally not a ...


3

I would use regular expressions for this problem. I know, I know, now you have two problems. Anyway: public static Boolean startsWithAny(String input, Set<String> substrings) { if (input == null) return false; String expression = '^(' + String.join(new List<String>(substrings), '|') + ')'; return Pattern.compile(expression).matcher(...


2

Might this work for you? SELECT Name, Body, BodyLength FROM Attachment WHERE ParentId IN :ids AND (NOT Name LIKE '%log.pdf') I'm assuming ids is a list or a set and not a single id? If it is a single id than it should be SELECT Name, Body, BodyLength FROM Attachment WHERE ParentId = :ids AND (NOT Name LIKE '%log.pdf')


2

You're missing some substring() functions. I'd also recommend using the AttributeValue() function to retrieve the value for ISO_CNTRY_2_CD. %%[ var @isoCntry2Cd set @isoCntry2Cd = AttributeValue("ISO_CNTRY_2_CD") ]%% %%[IF Substring(@isoCntry2Cd,1,2) == "MX" THEN]%% <br><br>Mexico<br><br> %%[ELSEIF Substring(@isoCntry2Cd,1,2) == ...


2

Very easily. YOu get the length of the string and then use substring based on length minues your number: %%[ SET @num = "17,873" SET @length = Length(@num) SET @final = SubString(@num, 1, Subtract(@length, 4)) ]%% That should do it. If you are looking to do it based on variable, you can likely use IndexOf() on the comma (Indexof(@num, ',') and then use ...


2

I see you've used my example to attempt to bulkify the trigger - good work! You have a bug though that you'll need to fix (that will fix your null error and make it all work properly) Change the code just before the loop and including the loop to: public override void beforeUpdate() { i360__Sale__c[] sales = (i360__Sale__c[])Trigger.new; Set<...


2

Most probably, staffMap does not contain a key of a.Referral_Store__c.substringAfter(' ') You're populating staffMap with a key of staffMember.Name. Is that going to have the same value as a.Referral_Store__c.substringAfter(' ')? This is debuggin 101. Do some system.debug statements outputting staffMember.Name and a.Referral_Store__c.substringAfter(' '). ...


2

You cannot reference Long Text Area fields in formulas of any type. You will have to use Apex. For example, if you have a controller already, set a truncatedDescription instead of just Description. public with sharing class MyController { public String description { get; private set; } public String truncatedDescription { get { ...


2

I don't know of anything out-of-the-box Apex that will do that kind of filtering. A sample helper method in Apex would look like this: public Set<String> filterStartsWith(Set<String> fields, String filter) { Set<String> filtered = new Set<String>(); for (String field : fields) if (field.startsWith(filter)) ...


2

Apex doesn't really support that. Strings are as in Java, immutable objects, so you can only create modified copies, but not update the original. It has to do with Java's String Pool. So, replaceFirst is probably appropriate in your case. Notably, the first parameter is actually a regular expression, so you can target exactly what you want to with some ...


2

When you use parentheses in a regex, you create a "capture group". These groups are numbered from 1 to x, where x is the number of capture groups you create this way. Group "0" is a special group that represents the entire match. As such, you normally want to use group "0". string str = 'This is a design number D-123989 and Id ...


1

Those are not method of String object in Javascript. They are mothods of Apex String class. You could use substring and indexOf. const recUrl = 'CF00N4A00000CMi5V=04612373&CF00N4A00000CMi5V_lkid=003D000003s6tsS&'; const guard = 'CF00N4A00000CMi5V_lkid='; let recId = recUrl.substring(recUrl.indexOf(guard) + guard.length); recId = recId.substring(0, ...


1

This is more of a JS question and not specific to LWC. Considering your all other input to the function is correct, you have a case sensitivity issue here on indexOf function as currently written. The current function is indexOf (notice UPPERCASE O). The corrected line should be as below: var questName = questionName.substring(0, questionName.indexOf("-"));...


1

if you always expect that same estructure you can use response.getbody().substringbetween('t/','"'); Either using substringAfterLast('/').substringBefore('"'); would work too. Take a look to the String Class documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm


1

Would something like this suffice? I’ll leave it up to you to define what happens if the part before the @ is 2 or less characters. String valueToMask = original.substring(2, original.indexOf('@')); String mask = 'x'.repeat(valueToMask.length()); String masked = original.replaceFirst(valueToMask, mask);


1

If you're sure the subject will never change except for the amount, you should use the substringBetween(open, close) method of the String class. You can use the ':' character as open tag and 'USD' as close tag. Then, you can use the trim() method of the String class to remove any leading or trailing white space characters. Here's the code: String ...


1

You can do this using the Substring(1,2,3), Length(1) and Subtract(1,2) functions. It is pretty easy and you need to supply the original string, the index you want to start with (1) and the length minus one as maximum length. Example code: %%[ Var @firstString, @newString Set @firstString = "https://example.com/asdf/" Set @newString = ...


1

The outputList that you have is nothing but a string array with index starting from 0. You access it just like you access any other array i.e outputList[index] Update your for loop to this: for(integer i=0; i < base.size(); i++) { List<String> outputList = base[i].split('[|]'); System.debug('1st chunk is '+outputList[0]); System.debug('2nd ...


1

This will split it and remove whitespace: String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant'; String[] results = initialString.trim().split('\\s*\\|\\s*'); system.debug(results); Of course you will want to add in all the usual checks for null, errors, etc. For a single string this will get you the EMP part as requested in your ...


Only top voted, non community-wiki answers of a minimum length are eligible