Hot answers tagged

7

' is escaped HTML Entity, just like (, &, and so on. To unescape most of them in Apex use String.unescapeHtml4() method which Unescapes the characters in a String using HTML 4.0 entities. For instance: String unescapedString = 'Abc's Place & Xyz's Place'.unescapeHtml4(); // "Abc's Place & Xyz's Place&...


5

I compared both of those methods to another method you may have overlooked: getChars. I got the following times in MS for each (lower is better): Method Time charAt 2512 substring 3338 getChars 744 I tested each against a String consisting of 100,000 characters for dramatic effect (and to get more accurate measurements). All three methods were called in ...


5

Using a map like that obfuscates the parameters, making it so developers have to read the method to know what parameters to use. Worse, these kinds of maps are case sensitive. I would strongly recommend you don't do this. If you have enough parameters that you'd want to do this, make a wrapper or Data Transfer Object.


5

Instead of for (List<AggregateResult> agg: query) you should have for (List<AggregateResult> agg: Database.query(query)). You can find additional detail regarding Dynamic SOQL here. Best regards!


4

First, check if it is present, second, remove found element, third, put replacement: Set<String> mySet = new Set<String>(); mySet.add('this'); mySet.add('is'); mySet.add('the'); mySet.add('example'); String toReplace = 'the'; String repalceWith = 'an'; if(mySet.contains(toReplace)){ mySet.remove(toReplace); mySet.add(repalceWith); } ...


4

That's how the split() method works. You give it a delimiter, and it creates a new item in the resulting list after every instance of the delimiter that it encounters. The delimiter is supposed to be something that separates entries but does not appear within entries. If you have control over this string value that you're working with, the easiest fix here (...


3

That's expected. Since future methods are in a separate transaction, whatever value was stored before won't exist, because static variables aren't preserved across transactions. You need to simply pass in the value as a parameter: @future(callout=true) public static void calloutCurrency(String requestDate) { ... System.debug(requestDate); } @...


3

This took a while to figure out. Here's what I did: I copy-pasted the actual CSV row header FirstName and the expected CSV row header FirstName into two cells in Excel and then wrote a formula to see if they were equal. They were not! But why? I then copy-pasted the actual CSV row header FirstName into a hex editor. My, my, what did I see but these hex ...


3

Your missing the colon : when referencing the variable in your query. That line should read Where RecordTypeId = :recordTypeId AND CreatedDate = Today]; See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm


2

What happened is you tried to get CLDate from the targetFields map, which was null, so no conversion from String to Date occurred (you basically went down a default when else path, since the described type was null). You need to change: switch on targetFields.get(key)?.getDescribe().getType() { To: switch on targetFields.get(sObjectFieldsMap.get(key))?....


2

for this kind of task regex is the best instrument to use. Here is a link to test regex for your needs. You can also read an explanation for regex: "(!Contract.)(.*)(?=})" 1st Capturing Group (!Contract.) !Contract matches the characters !Contract literally (case sensitive) . matches any character (except for line terminators) ...


2

Unfortunately, since the second string is looking for a partial text match, I don't see a way to avoid looping over each element to compare them. If you had a full text element match, the inner loop could be removed in favor of a Set contains() method. You should be careful of this "loop within a loop" approach. Unless you have tight control of ...


2

The error you're seeing is actually just how the platform likes to encode some characters as part of an error response, and has nothing to do with your problem. The error is telling you, quite misleadingly, that you've done something fundamentally wrong with your code. If Field__c is not a multi-select picklist, you can't use includes/excludes, and can cause ...


2

Just some general notes: sfdcfox's answer is, as always, brilliant. Using a map like that isn't a great idea, and I'd go so far as to say it's a bad idea. I like your desire to let other developers know what the parameters are, but I think the right way to solve this is with proper documentation. Apex-recipes (https://github.com/trailheadapps/apex-recipes) ...


2

RFC 4180 specifies how (most) CSVs are encoded. In the file, a cell with ", ,, \r, or \n must be quoted. In other words, "foo, bar, fizz, buzz" should be the correct escape sequence. Make sure that the editor you're using is showing all the characters in the file. I suspect that your actual CSV reads like: """foo, bar, fizz, ...


1

Your redirectToPage method does nothing, as it doesn't return the PageReference back to the client. Further, you can't both throw an exception and return a value. In addition, you should be throwing an AuraHandledException if that's your intent; ApplicationException isn't a standard Exception for Lightning components. Can I add breaklines to the ...


1

Don't JSON-encode your strings; the platform does this for you automatically. methodName({strLst: strLstLWC}); By double-encoding, you're making more work for yourself when you later have to double-decode it on the server side (one of these is done automatically for you). Note that if you're passing in a list of strings, just say so in your apex: @...


1

If you find it difficult to can always use .tsv file (tab delimitated file)


1

Your syntax is quite incorrect. Assuming this is just a snippet I am ignoring those. You can go for a Map<String, String> solution here, as you just need one parameter to pass: Original Method: public List<Product2> getPhone(String color, String brand, String model){ return [SELECT Id, Name FROM Product2 WHERE Color__c = :color AND Brand__c = ...


1

This is much easier and less code to implement by means of regex. You did a good attempt. A couple of minor changes are required. Take a look at the working online example https://regex101.com/r/FBhTZp/1 it also contains an explanation to it. (?i)(test) - any part of the expression to the right of (?i) is a case insensitive. #$0# - $0 matches the found ...


1

If I understood you properly, you want to split string by semi-colon and store in variable split parts, if they are not in the parts list which should be skipped. You can use split method from String apex class. Set<String> partsToSkip = new Set<String> {"Skip"}; String str = ' "Some" ; "Simple" ; "Skip" ; &...


1

Parsing a CSV correctly and efficiently requires a finite-state automaton (FSA), or more simply, a state machine. It's not simply enough to count quotes or split by commas, etc. The implementation should follow RFC 4180, which is pretty easy to implement as an FSA. With an FSA, you create a "machine" that has various states, such as "start of ...


1

To add to @Derek F's answer here is a bit of code I use to bypass the System.debug() character limit when needed. This question has been asked before and you can find more answers here. public void debugUntruncated(String msg) { for (Integer i = 0; i < msg.length(); i=i+300) { Integer effectiveEnd = (i+300 > (msg.length()) ? msg.length()-1 : i+...


1

Your string is not actually truncated. What you're seeing is simply an artifact of using system.debug();. A similar thing happens when you debug lists and maps. If you open the raw log in the developer console (logs tab, right click the target log, select "open raw log"), you'll see the entire string. On a secondary note, the method you're using to ...


1

You are missing the semicolon in the SOQL, just keep it like your code but the soql like this: List<Object__c> recordList = [SELECT ID FROM Object__c WHERE Field__c includes (:str) LIMIT 50000];


1

Unfortunately, I don't think, that you will be able easily to read and edit a word file (.docx my assumption) by means of the native apex. It definitely contains some workarounds. The reason for that is .docx is not just a plain text file, actually, it is an archive file with folders, subfolders, and mainly .xml files. Just try to open .docx file by means ...


1

Try the replace function. String removetag = '<p>Salesforce Technoligy</p><br><p><b>Releases:</b></p>ul><li><b style="font-weight: 32px;">Please stay tuned</b></li></ul><ul>li><b style="font-size: 12px;font-weight: 22px;">Click here</b></li&...


1

It seems that encrypted value might be exceeding the field length. This can happen if you are using deterministic encryption mechanism. It also depends on character set used. You would have to implement validations so that the length of the value in these fields does not exceed certain length. Check out the following: https://help.salesforce.com/articleView?...


1

So, your problem is that if you fail to insert records, there aren't any ids to work with try{insert exportRecords;} catch(Exception e){ new ApexDebugLog().createLog( new ApexDebugLog.Error( 'KlitaSyncBatchClass', 'execute - insert to Misrad_Haklita_Export__c', convertToIds(exportRecords), // ...


1

The easiest approach would be to split the string then build sub-arrays and join the values back up, something like: List<String> roleIds = roleIdString.split(','); while (!roleIds.isEmpty()) { List<String> roleIdSubset = new List<String>(); for (Integer i = 0; !roleIds.isEmpty() && i < 20; i++) { roleIdSubset....


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