David Reed
Moderator
  • Member for 4 years, 7 months
  • Last seen this week
When do we really need try/catch?
41 votes

What the main point of try/catch? To catch and handle an exception. The handling is the key. What it means to handle an exception is to take an exceptional situation - something bad and out of the ...

View answer
How to retrieve the file content for a ContentDocument object?
Accepted answer
29 votes

The Content tables are considerably more complex than Attachments. The file content is held in the ContentVersion object; one ContentDocument has one or many versions, as well as an arbitrary number ...

View answer
How do I increase my code coverage, or why can't I cover these lines?
Accepted answer
28 votes

Code coverage is a measurement of how many unique lines of your code are executed while the automated tests are running. Code coverage percentage is the number of covered lines divided by the sum of ...

View answer
Breaking a flow into 2 different transactions
Accepted answer
25 votes

Using a Wait (now called Pause) element does preserve the Flow's state, including all of its variables and the field values of queried sObjects, across the boundary into a new transaction. As expected,...

View answer
How do I get started working with JSON in Apex?
Accepted answer
22 votes

Apex provides multiple routes to achieving JSON serialization and deserialization of data structures. This answer summarizes use cases and capabilities of untyped deserialization, typed (de)...

View answer
How do I write an Apex unit test?
Accepted answer
21 votes

This answer is not intended to teach you everything about writing unit tests, nor to specifically answer every question, but to provide a quick summary and links to the resources that will help you ...

View answer
Unfamiliar Syntax
Accepted answer
21 votes

This is called a type cast. Apex has what is called a strict, static typing discipline, which means that all variables and values have a type, and that type is declared for variables at the time of ...

View answer
Can you query a Platform event?
Accepted answer
20 votes

Other answers have shown that it's not supported to query events using SOQL, but I want to clarify that it's not only not supported, it is not meaningful. Platform events form an ordered time stream. ...

View answer
Dynamically create a lightning component and put it into a custom lightning component
Accepted answer
19 votes

A Lightning attribute like v.body, which is typed as Aura.Component[], is called a facet. It's perfectly legal to have multiple facets in your component. You'd have to do something more like this, if ...

View answer
When passing in a collection of sObjects to a Queueable what values are used?
Accepted answer
18 votes

sObjects (and other objects, for that matter) that are instance variables in Queueables and in Batch Apex classes are serialized and stored, and then deserialized at the time the Asynchronous Apex is ...

View answer
How do I unit test code that includes a callout?
Accepted answer
17 votes

As part of the isolation of the test context, Salesforce does not allow your code to make REST or SOAP callouts during test execution. This includes all code that's executed in test context, even if ...

View answer
Custom Metadata vs. Custom Objects in Managed Package
16 votes

A reason I haven't seen articulated yet applies specifically to the managed package context: Packaged, protected Custom Metadata Types are an ideal solution for secret storage in a managed package ...

View answer
Is Apex Sometimes Case Sensitive?
Accepted answer
16 votes

Yes. Collection membership is case sensitive. This applies to Sets: If the set contains String elements, the elements are case-sensitive. Two set elements that differ only by case are considered ...

View answer
System.TypeException: Invalid date/time: 2019-01-03T00:26:01.711-02:00
15 votes

To parse DateTimes in this ISO format, you need to use JSON deserialization. String data = '2019-01-03T00:26:01.711-02:00'; Datetime dt = (DateTime)JSON.deserialize('"' + data + '"', DateTime.class); ...

View answer
Usage of independant blocks inside of a method
Accepted answer
13 votes

In Apex and in many other C- and Java-family languages, curly braces define scopes: the boundaries within which variable bindings exist. "Bare" curly braces, without a keyword like if or ...

View answer
How do I test asynchronous Apex?
Accepted answer
13 votes

Asynchronous Apex includes all of the methods for executing code on the Salesforce platform outside a synchronous transaction, including: @future methods. Batch Apex Queueable Apex Schedulable Apex ...

View answer
Schedule and Run a Report as an specific User from Apex
Accepted answer
13 votes

I want to sketch out a possible design, as this is a question I've been turning over myself. For the record, I have not had time to build this out myself, even as a proof of concept, but I think ...

View answer
Parse date time string to Apex DateTime
Accepted answer
13 votes

JSON.deserialize('"2018-10-01T00:00:00Z"', DateTime.class); Note the extra set of double quotes - they allow the JSON parser to interpret that value.

View answer
Restore an expired scratch org
13 votes

Your scratch org is never the source of truth (the home of your current work) in SFDX. Just make sure your local copy is up to date with any changes you might have made in the user interface by doing ...

View answer
What's the difference between Abstract class and Virtual Class
13 votes

The Apex Class Definition resource from the Apex Developer Guide may provide some illumination. In summary, virtual classes permits subclassing and method overriding. However, a virtual class does ...

View answer
Bulk API Error: UNABLE_TO_LOCK_ROW:unable to obtain exclusive access to this record or 124 records
Accepted answer
12 votes

A great resource for understanding row locking situations is the Record Locking Cheat Sheet (PDF link). Note at the top of page 2 that insert, update, and delete of Opportunities locks the parent ...

View answer
@AuraEnabled Method will execute in synchronous or asynchronous?
Accepted answer
12 votes

Is it required to call @Future(callout=true) from @auraEnabled Method if I want to make a asynchronous callout? If you want to make an asynchronous callout (you do not wait for the result and don't ...

View answer
Can we Have two Http Mock Callouts in a single test class method
Accepted answer
11 votes

Yes, you can, using either of two techniques. Your HttpCalloutMock's respond() method can inspect its inbound HttpRequest, and construct a different response based on which endpoint is being called, ...

View answer
ContentVersion FileExtension
Accepted answer
11 votes

It's determined by the PathOnClient field as populated when you create the ContentVersion. As an example, in one of my orgs I uploaded a file called App.logo.png through the API, populating its file ...

View answer
How to query ContentDocument and Custom object's fields at once?
Accepted answer
11 votes

You can do it in one query if you start from the Custom Object and utilize the ContentDocumentLinks relationship in a subquery. Here's an example with Account as the main object: SELECT Name, ...

View answer
Is my org's data accessible to Salesforce?
11 votes

The data you store in any cloud service is, ultimately, accessible to that cloud service, saving only the circumstance that the data is encrypted on your local machine prior to transmission to the ...

View answer
Complicated SOQL SELECT
Accepted answer
11 votes

SOQL parent-child queries only support one level of relationship descent: In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if ...

View answer
Catching an UnexpectedException?
11 votes

System.UnexpectedException gets thrown a lot with Note inserts if you do not prepare the content exactly right, and they cannot be caught or handled in any way. I wrote an open source package a while ...

View answer
Quick way to find out when a scratch org expires?
Accepted answer
11 votes

The sfdx force:org:display command can also show the expiration date: david$ sfdx force:org:display -u test-<snipped>@example.com === Org Description KEY VALUE ─────────────── ───...

View answer
How to add fields to "New Event" under "Activity" tab in Lightning?
Accepted answer
10 votes

You can't edit the Activity Publisher component, but you can change the set of tabs that appear therein. They're Quick Actions. You can control which Quick Actions appear in the Activity Publisher by ...

View answer
1
2 3 4 5
91