Questions tagged [string]
In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. In Apex it is considered as any set of characters surrounded by single quotes.
36
questions
9
votes
1
answer
8k
views
Catch Regex too complicated when splitting a string in salesforce
I have created a function wherein I split a string from the csv filecsvAsString.split('\n')
. It is working when the string is not so big. But when I try to split a very large string, an error will ...
8
votes
3
answers
55k
views
JSON and escaped double quote
I'm currently making a callout to a 3rd party vendor and I'm getting a huge response. What is currently messing me up is this section:
"MessageSeq":13,"Description":"config ...
6
votes
1
answer
2k
views
Regex: Make Dot Match Newline?
I use Rubular to test my regular expressions, when I need them. I am having a bit of trouble crafting an expression that will work for me. For reference, I am trying to match multiple substrings in ...
18
votes
3
answers
8k
views
Eliminating Unicode accents in Apex
Is there a published way to take text that may have accent marks and remove the accent marks?
For example:
System.assertEquals('Hello', transform('Ḧéļḻṏ'));
I believe there is an equivalent method ...
50
votes
5
answers
178k
views
How to check in Apex if a Text field is blank
I'm unsure what's the shortest and most robust way to check whether a Text field is blank / empty?
/*1*/ Boolean isBlank = record.txt_Field__c == '';
/*2*/ Boolean isBlank = record.txt_Field__c == ...
8
votes
2
answers
10k
views
Regex Help- Escaping Characters And Matcher Method
I have a string:
allPunctuation = '~!@#$%^*()_+|}{":?><`=;/.,][-\'\\';
This string contains APEX's way of escaping characters so I can include the ' and the \ characters.
When I pass this ...
4
votes
1
answer
3k
views
Using single quote by curly braces in String.format in Dynamic SOQL
I'm struggling to use String.format to replace a token with a value when the token is within single quotes:
Example:
String query = String.format('SELECT Id FROM Availability WHERE Person__c = \'{0}\...
4
votes
3
answers
7k
views
Formatting Negative Numbers with Parentheses
Formatting numbers on a VF page, but I do a bunch of processing the Apex Class, so I would rather return the formatted String value from the controller.
I am doing something like this, but I just ...
3
votes
1
answer
2k
views
Strings concatenation and one character size
Short prestory. Typical problem: you have a lot of small string and you want to concatenate them all in one big string. The code like
for(Integer i = 0; i < smallStringsSize; i++){
bigString += ...
1
vote
1
answer
3k
views
Escape backslash
I'm trying to define a string with the following value
string s = 'Something\Something';
but I got Illegal character sequence '\S' in string literal.
I tried escaping the backlash with another ...
0
votes
1
answer
735
views
Translate spanish characters to english for field values
I have a requirement to translate few predetermined spanish characters to english in field values of different custom objects. I have tried to create a generic code. can someone please let me know ...
20
votes
1
answer
34k
views
String length exceeds maximum: 6000000
Are there any work arounds for this issue?
I'm trying to upload a file(attachment) to an 3rd party REST API Service. It works fine until my file sizes get about ~5 mb. Then I start getting the ...
15
votes
1
answer
28k
views
RestRequest RequestBody instead of Params
I am leveraging a webhook from a third party API (Mandrill) that sends me JSON, and have set up a Force.com public site with a RestResource to handle the incoming request. I've been noticing that if ...
14
votes
4
answers
64k
views
How to convert a number into a formatted string?
Note: there is an extensive discussion on converting a string into a decimal. This question asks how to convert a number into a formatted string.
Given a decimal variable, how can I convert that ...
8
votes
1
answer
15k
views
How can I call a method from visualforce?
You would think this would be more obvious, but "how can I call a method from a visualforce page?"
Say I have something like this:
<apex:page controller="PreChatController ">
<script>
...
7
votes
2
answers
27k
views
Remove whitespace before and after the string dynamically?
I am trying to remove whitespace (dynamically) from an input string:
Input: ' inputString '
Output: 'inputString'
Input: ' Ravi kumar '
Output: 'Ravi kumar'
I want to remove the space before or ...
7
votes
5
answers
11k
views
Is Apex Sometimes Case Sensitive?
I have a string set of field names populated as below:
Set<String> setAllCustomSettingFields = new Set<String>();
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
...
6
votes
5
answers
14k
views
Get Visualforce page Name in Apex controller
I want get current page name of visulforce page. I have tried this and it works for the page having no query parameters in the URL but it fails in the pages having one or more parameters.
Any ...
5
votes
3
answers
4k
views
Email Parsing with apex class
Anybody having knowledge regarding the Email Parsing??
I have a requirement that i receive data from email and i need to split it.
for ex: *Category : (Some Data)
*Type : (Some Data)
I need to ...
4
votes
2
answers
2k
views
Passing Strings by value causes memory problem
I have some functionality where I have to pass Strings between functions.
The problem is these Strings can get quite big and Strings are passed by value not by reference. If you have a big String, the ...
4
votes
1
answer
661
views
How can I dynamically transverse SObject fields in Apex?
I am trying to dynamically create a CSV file from Case records. The fields for the CSV file will be determined in custom settings (and therefore shouldn't be hardcoded). Moreover, the fields may ...
3
votes
1
answer
6k
views
String to ASCII
How can i convert (in APEX) a String to an Integer, which corresponds to its ASCII.
What I have:
String Name = 'A';
What I want:
Integer Number = 65;
Thanks all!
2
votes
3
answers
5k
views
Question About Static Methods
I'm new to Apex and development in general...
So, I'm playing around coding and doing some badges in Trailhead.
I created a small piece of code, as below, and have no actual use:
public class ...
2
votes
1
answer
4k
views
JSONGenerator writeObjectField() remove backslashes
I'm trying to create an Invocable Method which allows an input of a JSON-formatted string from Process Builder as a variable. However, when I try to add the inputted JSON string using JSONGenerator....
2
votes
1
answer
14k
views
Replace double quotes with single quote in a JSON string
We have JSON sent to us by webservice which has double quotes in value part (Key => Value)in the JSON String. Below is how the JSON looks like
[{
"dp_id": "SDN071076",
"list1": "...
2
votes
1
answer
5k
views
Trying to parse large CSV, can't split and can't find second newline
I have a csv with about 24,000 lines that I need to parse in apex. I tried splitting the string by newline ('\n'), but got a limit error:
System.LimitException: Regex too complicated
I tried ...
2
votes
4
answers
4k
views
REGEX in Salesforce Flow to retrieve a substring
I need to retrieve a substring from a text field in a flow. is it possible by using regex instead of apex ? If i try this regex i receive false as result ( boolean ), i should get true and then i ...
2
votes
3
answers
302
views
Length of a delimited string with nulls ( not blanks ) in it
I was trying to do some operations on a delimited string. I chanced upon a case where I got to check the length of a delimited string with nulls in it.
For Example :
String str = null+', '+null
...
2
votes
1
answer
4k
views
Datetime format ignores am/pm?
Hi I am new to apex coding and am trying to parse a datetime and then later on in my program I am trying to convert it back into a string to query items.
For converting a string into a datetime I am ...
1
vote
1
answer
9k
views
How to use Split() function inside an Expression in lightning component
I would like to use Split function inside my expression in salesforce lightning.
I'm passing a map from my class and receiving the same in js controller and then converting it to List attribute for ...
1
vote
1
answer
7k
views
Need AMPScript function to convert string to decimal
In an email I have a variable coming in that is in string format (it's a price). I need to multiply that by another number, which means I need to convert the string to a number in the xx.xx format.
...
1
vote
1
answer
3k
views
SOQL query to find a row with the longest string in a column
I was trying trying to figure out if there is a way in SOQL to select/sort rows in a table with the longest Strings in a selected column.
Something similar to:
SELECT Id, Name FROM User ORDER BY ...
0
votes
1
answer
2k
views
Check For Special Characters in Emails
I'm having a business requirement of searching special characters in Email Field(before @domain.com)in a trigger.
For Ex: if a email is like this (t#@[email protected]).it should be able to identify the'#...
0
votes
1
answer
479
views
Trigger to Auto Assign Field value to Object Record
How do I create a trigger and trigger handler to auto assign a name for custom field on a custom object when a new record is created? The auto-assigned name should be randomly selected from a list of ...
0
votes
2
answers
1k
views
Query exception - Unexpected token '{'
I have below query string in an apex batch class that throw error. Can some one please help?
Error
Unexpected token '{'
Query String
String query = 'SELECT Call_Duration_Required_abv__c,Id FROM ...
0
votes
1
answer
4k
views
Escaping reserved characters from a string stored in custom setting
I want to get mykey stored in custom setting and escape the reserved characteres.
originalstring = 'abc123def'pqr456\eryt' ;
// escaping the reserved charatcters
String ...