New answers tagged

2 votes
Accepted

concatenate a string and use it as part of the API Name for a field

You use the SObject class put method pa.put(prefix+'mechanical__c',25);
  • 63.7k
0 votes

How to tell if refreshApex has new data?

refreshApex is asynchronous, so you can copy the old value and compare to the new after waiting for new results: async handleClick() { let oldData = JSON.stringify(this.wiredRecord.data); await ...
  • 444k
4 votes

How Apex Clone Works

When using the clone method, you need to pass in four true values to preserve/copy everything. sObject clonedRecord = sourceRecord.clone(true, true, true, true); You can read more in the ...
  • 444k
0 votes

invalid element error in the fill <runtimeNamespace>

That's just a linter error; you can report this to the VS Code Salesforce Extension Pack team if you want to on their GitHub page. It shouldn't stop deployments to your org, however. Note, however, ...
  • 444k
1 vote

LWC: How to make DIV fit with mobile view

I will add important details for the answer provided by @glls. Documentation for layout-item If you specify the small-device-size, medium-device-size, or large-device-size attributes, you must also ...
2 votes
Accepted

SOQL aggregate query issue with number fields

Certain fields are not groupable. For number fields, they are groupable if they are standard and are integer deep at the API level. For all other numbers they are decimals and are not groupable. Can ...
3 votes

LWC: How to make DIV fit with mobile view

from the docs - Create Responsive Layouts you can use the *-device-size property to change the size depending on the viewport. Example: <lightning-card> <lightning-layout multiple-rows&...
  • 19.5k
0 votes
Accepted

Is a private list object being accessed by a public method causing a problem?

It turns out to be this line of code //check to either owner or contact em.ToAddress = recipient; EmailMessage.ToAddress has to be a string. I was sending in an ID. What's bizarre is that if I ran ...
  • 53
6 votes

Pre-install Script for package

You can only run Salesforce components of any type after installation. If you really want this sort of pre-install check, set a password to prohibit installs, and then set up a public site where the ...
  • 444k
1 vote

After PMD Apex code change, getting alot of errors and can not deploy code

The compiler message says: Method does not exist or incorrect signature: void stripInaccessible(System.AccessType, Order) from the type System.Security The second parameter for stripInaccessible() ...
0 votes

I want to display all the active users present on my org in a dropdown menu

In getUserName Controller wiredData method, data which will be returned will be a List. You can directly use map function directly on the list i.e. data.map, instead of using data.values.map. This ...
  • 91
1 vote

Unknown property 'VisualforceArrayList.EHS_Task__c'

public List<EHS_Pre_Job_Brief__c> getEHS{get;set;} This is a list of items. You need to access the zeroth index: <input type="text" name="task" id="task" class=&...
  • 444k
1 vote

Pattern.quote matches substring instead of whole word match

The issue is not Pattern.quote, but rather your use of Matcher.find: Attempts to find the next subsequence of the input sequence that matches the pattern. This method returns true if a subsequence of ...
  • 28.6k
0 votes

How to get start and end date of a specific quarter

There is currently no proper native support for this in Flow, so you will have to revert to APEX to help you. Luckily Carl Vescovi has already done that for you: https://unofficialsf.com/flow-datetime-...
0 votes

I want to add no of count of task on lead

To get the exact count you can try writing a trigger for all the three cases. After insert, after update and after delete. So that if a task is created under a lead or updated/deleted under lead it ...
1 vote

' rendering as \' in VF page rendered as PDF

The JSENCODE is what's causing this. You want to use HTMLENCODE instead. You only use JSENCODE if the value is included directly in a script tag. <script> var x = {!JSENCODE(config)}; </...
  • 444k
1 vote

Get currently installed package version from Apex Class

For 2GMP instead of using System.requestVersion() it is possible to create some custom logic to store the value of Version in PostInstallContext into some protected custom setting. Then, when needed, ...
  • 13.9k
0 votes

How to get installed managed package Name and Version numbers in Apex Class having API Version 29.0

Well, instead of querying Publisher object or using System.requestVersion() it is possible to create some custom logic to store the value of Version in PostInstallContext into some protected custom ...
  • 13.9k
0 votes

System.requestVersion() does not work in Second Generation Packaging

Well, instead of using System.requestVersion() it is possible to create some custom logic to store the value of Version in PostInstallContext into some protected custom setting. Then, when needed, the ...
  • 13.9k
0 votes

Visualforce - Rich text substitute style= "" with style="margin-top: 0pt; margin-bottom: 0pt;"

Copy paste rich text value from sandbox to production does not work properly. I believe this is an API Version issue cause i am copying from sandbox to production where versions are different. And ...
  • 444k
3 votes

I am getting null values for all opportunity fields

Data doesn't appear out of nowhere. Executing Opportunity opp = new Opportunity(Id = nMap.get(newAlloc.Id).npsp__Opportunity__c); doesn't magically get you the other data for the opportunity. You ...
  • 50.5k
0 votes

The formula expression is invalid: Syntax error. Missing ')' in process builder

It appears that you have an extra comma at the end 'British', 'IO', ,'0') ^ Remove the square brackets [] from [Account]. You need to escape the single quote in this line: 'Côte d'Ivoire', 'CI', ...
  • 2,317
0 votes

Aggregate soql query to retrieve all accounts with at least one opportunity and contact

SELECT Id, Name FROM Account WHERE Id IN (Select AccountId from Contact) AND Id IN (Select AccountId from Opportunity)
5 votes
Accepted

Adding spaces to an apex class definition

After re-reading your question, the solution here is indeed either to modify the JSON before you deserialize it, or deserialize untyped. Using JSON.deserailizedUntyped() would look like // Using a Map&...
  • 50.5k
2 votes
Accepted

How to convert a country name to country code in apex?

You can a create custom metadata, which would contain the country codes for corresponding Country names. So when you receive a country name, you can query that specific Country in the custom metadata ...
0 votes
Accepted

How to update field when user has logged in?

You can divide current solution to 2 batches - first for email reminder, second to deactivate users Batch1 code global Database.QueryLocator start(Database.BatchableContext BC) { return Database....
  • 471
1 vote
Accepted

Illegal Assignment error when dealing with custom sort class

Your .get() from the list returns the wrapper itself. You want the record that is inside the wrapper instance. For clarity, I broke it out into two lines. You can recombine the syntax into a single ...
  • 22.4k
1 vote
Accepted

How to handle and get duplicate values after receiving the duplicate value error message

Database.DuplicateError is only for Duplicate Rules. Instead, you can check getStatusCode on the error and compare it with StatusCode.DUPLICATE_VALUE. However, that still won't tell you which record ...
  • 444k
1 vote

Faster way for deleting millions of records

The fastest way would be to use an external API, which you could parallelize quite easily (but be aware of concurrent limits). As far as speeding up the batch, it won't go any faster than asynchronous ...
  • 444k
0 votes

How do I use a merge field in a formula that is rolled up?

The trigger for recalculating a rollup summary field is usually the insert/update/delete of a child record. Since these 2 fields are on a different object, the rollup recalculation does not get ...
0 votes
Accepted

What controls ContentVersion access in non-sharing apex class?

So after a lot of searching, Kris Goncalves was able to lead me in the right direction with his answer ultimately leading me to J. Schreiber answer which includes gives a query by query example You ...
  • 324
1 vote

Unpredictable behavior while escaping special characters in sosl

Indexes don't index punctuation as part of the word, as mentioned in How Search Breaks Up Information: Alphanumeric terms are split at letter-number boundaries. Terms with non-alphanumeric characters,...
  • 444k
1 vote

Clone packaged permission set in Apex

Cloning permission set is not a problem at all. PermissionSet ps = [SELECT Fields(Standard) FROM PermissionSet WHERE Name = 'PermissionName' AND NamespacePrefix = 'Namespace']; ps.clone(false); ps.Id =...
  • 13.9k
0 votes

How to retrieve connected app using metadata API?

If you don't want to use Metadata API library, you could use the following snippet of code private static String getSoapBodyXml(String endpoint, String name) { return '' + '<?xml ...
  • 13.9k
0 votes
Accepted

How can I find a value in all fields using SOSL?

Note that the limitation here applies only to Apex. You can use, for example, the Query tab in Developer Console to find all records this way, or use the API. In theory, you could even set up an ...
  • 444k
0 votes

How to fire pushtopic logic from an Apex class?

Here is the snippet which you can refer to for firing push topics from the Apex class. PushTopic pushTopic = new PushTopic(); pushTopic.Name = 'Account'; pushTopic.Query = 'SELECT Id, Name FROM ...
0 votes

Get ALL queue Users

maybe u can try this List<Group> queues = new List<Group>([ SELECT Id, (SELECT Id FROM GroupMembers) FROM Group WHERE Type='Queue' AND Name IN :groupNames ]); for(Group queue :...
  • 67
1 vote

Where can I find the field names of individual fields in the Address compound field

Address fields have a bunch of different properties, described in Address Compound Fields. They all follow the same format. For Mailing Address, for example, you'll have MailingStreet, MailingCity, ...
  • 444k
1 vote

Create connected app using metadata API

You may have performed callout not to a canonical URL but to Visualforce domain or some other domain. You can actually perform successfully self-callouts without any RemoteSiteSettings, but you need ...
  • 13.9k
0 votes

Can we add the debug statement without a method?

There are two kinds of executable blocks in Apex. There are static blocks and instance blocks. Static blocks can be anonymous blocks and static methods. Instance blocks come in two basic flavors: ...
  • 444k
1 vote

Python: Object of type bytes is not JSON serializable

You should be following the steps found in Inserting a Document with Blob Data. That is, your payload must be a multipart/form-data content, with one element called entity_document with the ...
  • 444k
2 votes

Why does SF retrieves an extra Id column when querying on standard objects?

You might have printed in System.debug and you may be able to see this value. But it is not available for use. If you try to use this in Apex code. You will receive an error Error on line 3, column 1: ...
0 votes

Hi all, I am writing a trigger handler that needs to update the owner of a record to a specific user, but I am getting a DMLexception error

I solved the problem by update the line below: List<Account> accountRecords = [SELECT Id, Name, OwnerId FROM Account WHERE OwnerId = :deactivatedUsersIds LIMIT 1]; //REMOVE LIMIT AFTER TESTING ...
  • 13
0 votes

Hi all, I am writing a trigger handler that needs to update the owner of a record to a specific user, but I am getting a DMLexception error

The issue here is because in the trigger declaration you have used up before update and after update, but when we go down in the trigger, we have not specified when it would run for isBefore or ...
6 votes
Accepted

How to subtract 1 day from DateTime value in apex?

As per the other answer, the various add* methods support negative values for subtractions. However, if you want the time for your StartDateTime field to remain the same, even when subtracting the day ...
  • 28.6k
1 vote
Accepted

Error: No field name specified on column for sobject of type Document__c when deserializing JSON

JSON for List<Document__c> would look like this: [ { "attributes": { "type": "Document__c", "url": "/services/data/v35.0/...
  • 131k
2 votes

How to subtract 1 day from DateTime value in apex?

AddDays() method also supports negative values. If you want to subtract days you can use it as below. Field.addDays(-value)
0 votes

Can we add the debug statement without a method?

You should have at least constructor in your apex class to write the system.debug statement as below. public class sample1234 { integer h=10; public sample1234(){ system.debug(h); } } ...
1 vote

TEST class coverage for boolean method and exception messages

Your testmethod needs to run in the context of a running user // given an active user User testU = [SELECT Id FROM User WHERE Profile.name = 'Partner Sales'and isactive = true LIMIT 1]; System.runAs(...
  • 63.7k
2 votes

Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

A 3xx status code is a redirect. You should be able to immediately try again with the new location: try { Http http = new Http(); HttpResponse res = http.send(req); System.debug(res....
  • 444k

Top 50 recent answers are included