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.

Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

RecordTypeId in Where Clause

Id recordTypeId = Schema.SObjectType.Lead.getRecordTypeInfosByDeveloperName().get('ZS_Lead').getRecordTypeId(); System.debug('The FS Lead record Type Id is ' +recordTypeId ); // 011kjhjkhjkhkh List&...
1
vote
0answers
24 views

Trying to String.split on new line after matched substring [duplicate]

I have a script that is hitting a System.LimitException: Regex too complicated Error and so to combat this I've come up with a solution to chunk up the string and then do the regex to the chunks so ...
6
votes
4answers
13k views

How to split a string by the newline character in Apex?

I wonder if it's possible to use the apex public String[] split(String regExp) method to split a string by the newline characters. The string being a csv file created on the Windows platform. I ...
1
vote
1answer
54 views

System.JSONException: Unexpected character ('i' (code 105)): was expecting comma to separate OBJECT entries at [line:1, column:18]

I'm trying to escape a string but I had no success so far. This is the response body: {"text":"this \"is something\" I wrote"} Please note that there are 2 backslashes ...
0
votes
1answer
62 views

System.SObjectException: Illegal assignment from String to Date

I am trying to create an sObject from a Json string but get the error: System.SObjectException: Illegal assignment from String to Date This happens in line: newSobject.put(sObjectFieldsMap.get(key), ...
0
votes
1answer
25 views

Apex-List of string divide into lists of n size

I have a list of string something like below String roleId=105775004,105789004,105809004,105816004,105826004,105844004,105850004,105852004,105863004,105939004,105944004,105953004,105960004,105975004,...
0
votes
1answer
18 views

Salesforce updating String field value with null when forced with an empty String

I noticed when you force an existing text field value with an empty String, instead of it's becoming an empty string it's becoming a null value. For example, try below in Execute Anonymous. Savepoint ...
0
votes
1answer
37 views

Replace string in JSON [closed]

I have a below JSON { "query": "select Owner.Name, Owner.Id from custom_table where CreatedDate >= '2020-01-01'" } How can I replace '2020-01-01' with the values stored in ...
0
votes
2answers
150 views

Json Unexpected character (':' (code 58)): was expecting comma to separate ARRAY entries at [line:1, column:83]

I have a Json string to do some testing on nested Json but get te error:Unexpected character (':' (code 58)): was expecting comma to separate ARRAY entries at [line:1, column:83] I can seem to figure ...
0
votes
1answer
56 views

how to concatenate lookup fields given certain circumstances

I finished up this batch but came across an unforeseen scenario and can't seem to figure out how to code in the case it occurs. Here is my current code: global class Batch implements Database....
9
votes
4answers
42k views

How to truncate a string to a specific length if it is longer?

How can I make it that I can reduce the length of a String? Like for example the string.Length() = 300. My goal is to make it to 120 characters, retaining the left side (e.g. NameOfThePerson to ...
-2
votes
1answer
70 views

how to compare two string values in apex

I have to compare two string values in apex to determine whether they contain the same semicolon separated values or not (in any order). Could anyone please help me. String str1 = 'Pay TV;AVOD;Basic ...
1
vote
1answer
46 views

how to use rtrim in Apex?

I need to remove the trailing spaces from a String. However, when I try that in Execute Anonymous window with the below test apex code, I am getting the below error message. String testString = '...
0
votes
1answer
27 views

question about .Contains()

I have a quick question in regards to using .Contains(). I'm writing an if statement and need to update a text field if it contains "VA". However, if it contains "IVA" it shouldn't ...
0
votes
1answer
88 views

How can i match second-last char of a string with RegEx

Angular app! I need to hide the 2 second-last char of a string and replace them with "XX". what i got: +391234567890 what i need +39123456XX90 How can i match this with a RegEx? I want to ...
0
votes
0answers
39 views

Help with changing a line on a list class in apex code

I am pretty new to coding and just need help on adding/changing the following line in my apex code so it queries the RecordTypeId as well as the OpportunityId from the record that my lightning ...
3
votes
2answers
21k views

How to check empty value in a string?

I have array with list of class. public class filterField { public String label {get;set;} public String searchFieldName {get;set;} public String searchValue {get;set;} public ...
0
votes
1answer
40 views

Empty String check not working

I am developing an Apex class which is making a webservice callout by supplying Account number as the request payload. If the Account is not found in the external system, the webservice is returning a ...
1
vote
3answers
1k views

Is there any way to convert a PDF blob value to string in Apex / Javascript lightning controller

I am in need of a way to get a PDF to a readable string format so I can search for specific values in the PDF. But from what i've found so far Apex is unable to get the blob value converted into a ...
1
vote
2answers
798 views

Generate random string using Crypto.generateAesKey?

I need to generate an unique alphanumeric string of length of 30 characters which will be used very similar to the record id. Is it okay to use Crypto.generateAesKey() method to generate this 30 ...
0
votes
3answers
81 views

LWC: directive for comparison

Is it possible to compare a value with a string in LWC template tag? <template if:true={v.value === 'String'}></template> If not, how can I do this???
1
vote
3answers
200 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 ...
7
votes
2answers
477 views

Is this expected behavior for String.containsOnly()?

Here is some code to illustrate the problem. String str1 = ''; System.debug(str1.containsOnly('W')); I would expect false as the result but surprisingly the result was true. I don't understand why ...
3
votes
2answers
10k views

isNotBlank(inputString) vs isNotEmpty(inputString)

For string in Apex code, I can see two functions to check if string has any value or not: isNotBlank(inputString) and isNotEmpty(inputString). I have following questions regarding two similar looking ...
0
votes
1answer
24 views

How can I get a (String) value from flow in Apex controller?

I have a flow: There is a String value in one of fields in my flow and I have to take this value and do some computations with that value and return some records based on that String in a "second ...
0
votes
1answer
13 views

How can I concatenate different fields type in a String field

I have to add some fields values in a string. The fields are Id, date, string and integer. The point is I can do this in that way: String s; s= record.Id + record.Name + record.Date__c + record....
1
vote
2answers
326 views

Replace character in string in specific position (ie not first, not all)

I would like to replace one character in a string with an uppercase of the same character. Is there an elegant way to do this? Eg I have 'Donald Mcdonald' and I would like to uppercase the first 'd' ...
3
votes
1answer
183 views

How to serialize a string into a Blob value without backslashes?

I have a Map<string, String> that is populated using the following code below. When I attempt to convert this into a serialized string so that it can be passed into Blob.valueOf, the \" (...
11
votes
3answers
8k views

How do I do a case-insensitive replace all for a string?

I've got a project where I'd like to replicate some of the internal merge field functionality so users can build a link and it'd be really helpful if I could do a case-insensitive string replaceAll. ...
0
votes
1answer
41 views

Handling the String with <> characters

I am trying to convert the Long Area Text in to the RTF Field, the long text area sometime has the the <> in between the texts which is treated as a markup. I tried below to escape the ...
2
votes
1answer
113 views

Converting String value to Decimal

So I'm trying to convert Ethereum Wei to Eth. The described method of doing this is to divide by 10^18. However my attempt to do this is not producing the right values. private static Decimal toEth(...
0
votes
3answers
100 views

How to find all records where a textfield contains “04/06/2020” twice? [duplicate]

this is a bit of an odd one. Say I need to find all Accounts where the textarea field "Notes__c" contains the text 04/06/2020 twice, how would I go about that? Ideally using Apex or Reports. ...
41
votes
5answers
93k 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 == ...
0
votes
1answer
186 views

Need to mask the account number with '*' using formula field

I want to mask the account number field with '*' and want to show only the last 4 digits. ex. Acoount number - 12456665 Masked number - ****6665 The length of account number is not fixed. is it ...
0
votes
0answers
37 views

Replacing HTML Code in a String [duplicate]

We're being passed a field in a data string with the HTML code '&dollar;'. We're wanting to change that to '$', since when we send emails it still shows as '&dollar;' and not '$' on a web page....
11
votes
4answers
33k 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 ...
1
vote
2answers
575 views

How to pass a list of string values to a picklist in a flow

I currently pass a list of strings from my apex class to a flow. The list of strings {!cancellationReasonsList} I pass to a choice recource. The choice recource I pass to a picklist. Instead of ending ...
2
votes
1answer
380 views

Blob is not a Valid UTF-8 String - Only after “–” [duplicate]

I created a CSV parser that parses CSV's from static resources. I am returned with a Blob is not a Valid UTF-8 String error when parsing the character: "–" different from "-". The "–" is apparently ...
0
votes
2answers
37 views

Error in Ternary Operator

This is my code snippet , string.isBlank(distributorId) ? gen.writeNullField(DISTRIBUTORID):gen.writeStringField(DISTRIBUTORID,distributorId); why it is throwing me error Expression cannot be a ...
0
votes
0answers
370 views

Error escaping double quotes in large JSON string in Apex

I have large JSON response that I am trying to escape all instances of strings that are problematic for deserialization but am having some issues. Using .replaceAll works but that throws a "Regex too ...
1
vote
2answers
68 views

Extra Comma at the end of the string

I want to generate the string as number1, number2, number3 with the following code. String accountNumbers = ''; for(Account Acc: solvAccounts){ accountNumbers = accountNumbers + '' + ...
0
votes
0answers
29 views

How to handle both a single item and an array for the same property [duplicate]

I have an incoming JSON payload that with the parameter device_config. This parameter might be, at times, sent as an array of strings or a string. How would I handle this parameter when its being sent ...
1
vote
1answer
85 views

Invalid conversion from String to List<Any> then invalid conversion from List<Any> to String with same string

I am trying get the device_config field from a deserialized JSON packet and cast it as a List<Object> I keep getting the following error Invalid conversion from runtime type String to List<...
0
votes
1answer
232 views

DateTime Format Outputting Wrong Time

I am currently building an external web application using MVC. I need to format the DateTime to match Salesforce's format so I can push it up via API endpoints. The DateTime picker in my View works ...
1
vote
1answer
74 views

How to get id from concatenation of string in loop

I am looping trough some records and want to get the related id. This works fine as invoice.BillingAccount__r.BillToId__c. In my case BillToId__c is a field that I get from a custom metadata setting. ...
0
votes
1answer
311 views

Remove time stamp from personalization strings

I looking for a way to remove the time stamp of a date field when using personalization strings. I got this format when using PS: 3/1/2020 12:00:00 AM. I want to remove that part "12:00:00 AM". Here ...
7
votes
2answers
12k views

Is there a simple way to convert any value direct to String in production code?

When I do a System.debug(whatever), SFDC doesn't care whether whatever is a String, a Date, a Datetime, a Boolean, etc... it just makes a string of it and dumps it in the log. But in the following ...
0
votes
2answers
129 views

Checking if sequence of CHAR are in String

I am struggling with the below example. So basically I want to see if a contact is the Chief Operations Officer. Many of these individuals have the title "COO". So I am running into the following ...
0
votes
1answer
29 views

How to generate a stringset of s stringset with unique values

I have a string Set with a set of strings which is a combination of timestamp a recordid. How do I create a new string Set in a neat way with only the records with the latest timestamps Example: ...
1
vote
1answer
55 views

Convert object as string to json

I have an object which is converted to string in a text field. How can I convert this to a JSON string. String of object: Profile:[UID=, crmId=0000o00002XXXXxXXX, email=top@top.com, firstname=null, ...

1
2 3 4 5
9