81 votes
Accepted

LWC navigation error: "this[f.NavigationMixin.Navigate] is not a function"

Apply the NavigationMixin function to your component’s base class: export default class MyLwcComponent extends NavigationMixin(LightningElement) { Hopefully this saves 3 mins of searching for those ...
Brent Bowers's user avatar
  • 3,074
46 votes

When do we really need try/catch?

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 ...
David Reed's user avatar
  • 92.1k
18 votes

When do we really need try/catch?

always in DML operations That's a common misconception. If you're using partial saves (e.g. Database.insert(records, false);), there's never a time where you need try-catch, as any exception is ...
sfdcfox's user avatar
  • 481k
12 votes
Accepted

Best practice for catching and displaying action errors in Lightning components

What I use is a component which handles those calls and turns errors into toasts: ToastErrorHandler.cmp: <aura:component > <aura:method name="handleResponse" action="{!c.handleResponse}"...
Aidan's user avatar
  • 13.5k
11 votes
Accepted

NUMBER_OUTSIDE_VALID_RANGE: value outside of valid range on numeric field: 100.0

Precision is the total number of digits allowed both left and right of the decimal, and scale is the number of digits to the right of the decimal. The number of digits just to the left of the decimal ...
sfdcfox's user avatar
  • 481k
10 votes
Accepted

error handling batch Apex

Yes, you can certainly send an email to the user; in fact, this is my preferred method to avoid spamming users. You can do this by way of the Database.Stateful. public class MyBatchable implements ...
sfdcfox's user avatar
  • 481k
10 votes
Accepted

Data Loader Error no viable alternative at character

You are only allowed to use single quotes in your query. Replace all of your double quote characters (") with single quote characters (').
Adrian Larson's user avatar
  • 149k
10 votes
Accepted

Is it a good practice to set debug points in possible failure points in our Apex code?

Setting just system.debug won't help you much since in orgs where your package is installed might have lot of other codes that might lead to logs truncation and your debug statements getting lost. ...
Mohith Shrivastava's user avatar
10 votes
Accepted

Do 2GP Managed Packages send email notifications on unhandled Apex errors?

Yes, unhandled exception emails do work with 2GP. I confirmed this by creating a managed 2GP with a Visualforce Controller that tries to divide by zero if a certain custom metadata record is set to ...
Vivek M. Chawla's user avatar
9 votes
Accepted

lightning:input Clear validation error messages

we had a similar requirement and the way we fixed it was to put the entire form inside an aura:if and changed the Boolean condition. this essentially meant the dom got re-created again but we were ...
RedDevil's user avatar
  • 7,765
9 votes
Accepted

LWC: How to get access to proper Error message when statically calling an Apex method from LWC?

You don't have to throw AuraException, instead, you have to throw AuraHandledException (for Aura components only) AuraHandledException (for LWC components) @AuraEnabled public static string ...
Pranay Jaiswal's user avatar
8 votes

How to resolve an "Unknown user permission: SendExternalEmailAvailable" deployment error

This relates to the "Send through External Email Services" setting in Setup. Go to Setup > Email Administration > Send through External Email Services to see the setting. According to the description ...
abd3721's user avatar
  • 2,132
8 votes

How to resolve an "Unknown user permission: SendExternalEmailAvailable" deployment error

Set Email Deliverability to 'All Email': For unknown reason Salesforce automatically creates and removes this permission completely behind the scenes on all profiles based on the value of this ...
sskular's user avatar
  • 573
7 votes
Accepted

Add Line Break In Error Message

Salesforce by default escapes any html in the addError String. To work around this, use the addError method with additional 'escape' parameter at the end: oppsByOppId.get(mrf.Opportunity__c).addError(...
Guy Clairbois's user avatar
7 votes
Accepted

Difference between ApexPages.Severity FATAL and ERROR

The Fatal level is intended to materialize errors that occur at the platform level, while the Error level is intended for errors that are not strictly fatal, which accounts for pretty much every error ...
sfdcfox's user avatar
  • 481k
7 votes
Accepted

UNABLE_TO_LOCK_ROW error

Even though you have a record ID, if you try an update, a lock must be acquired first. Using FOR UPDATE forces the system to wait while it can acquire a lock on the record. It is recommended that you ...
sfdcfox's user avatar
  • 481k
7 votes
Accepted

Unexpected token `<`. in Apex trigger

The problem is with how you are looking to reference the trigger.new context. The binding expression : must be used as follows. trigger AccountAddressTrigger on Account (after insert, after update) {...
TSmith's user avatar
  • 4,932
7 votes
Accepted

AddError on an object in a trigger is only displaying one of the errors in object list view

It's a limitation of the addError interface. You are allowed at most one record-level error and one field level error per field. Adding a subsequent error will replace the original. This is also not a ...
sfdcfox's user avatar
  • 481k
7 votes
Accepted

Triggered Send Error Code: 138 - Exceeded Expiration Policy

This occurs when the subscriber was in the triggeredsend queue for more than 3 days. The triggeredsend can queue do the following reasons: TS erred causing the job to be stopped and the subscribers ...
EazyE's user avatar
  • 8,295
6 votes
Accepted

Error Message in Visualforce page

You can overwrite the standard salesforce error message css classes. In my example i have a simple error message with only short summary and a custom icon. So i took all error css classes and changed ...
Tushar Sharma's user avatar
6 votes
Accepted

Error Handling in apex class method.

To display a message on your page you can add <apex:messages/> as suggested in the comments. And to stop execution you need to put the code that you don't want to execute if Account was not ...
Oles Malkov's user avatar
  • 2,161
6 votes
Accepted

Can we display warning message from Trigger

From trigger, you can not show the warning message. If you want to show the warning on the detail page of the record , just create a VF page and add it on the top of the detail page layout as inline ...
NEHA GUPTA's user avatar
6 votes

Complete list of Standard Field Validation Error Messages

The strings are version and language dependent. However, there is a way to find which codes are valid for a particular release: go into Setup > Develop > API, generate the Enterprise WSDL, and find ...
sfdcfox's user avatar
  • 481k
6 votes
Accepted

Display Apex Exception message nicely in Lightning toast

Adding ugly wrapping code to all my @AuraEnabled methods seemed not to be an acceptable clean solution to me... @AuraEnabled public static Id myAction() { try { // regular action code } ...
Robert Sösemann's user avatar
6 votes
Accepted

Displaying an error message on a visualforce page

You need to rerender pageMessages section by commandButton's attribute <apex:pageBlock> <apex:pageMessages id="msgId"/> <apex:commandButton name="Submit" action="{!exchangeInv}...
Santanu Boral's user avatar
6 votes
Accepted

RaiseError not logging Error message into DE

AMPScript does not have any named parameters, so all parameters must be passed by position. In this case, the RaiseError function has 5 parameters and you are trying to specify the 5th without ...
ncv's user avatar
  • 418
6 votes
Accepted

Issue when using JSENCODE

accRegNumber is a JavaScript variable. The Salesforce formula expression {!JSENCODE(accRegNumber)} is processed by the server long before the content reaches the JavaScript parser, and the server ...
David Reed's user avatar
  • 92.1k
6 votes

How do I do a universal SOQL?

You can make use of dynamic SOQL: String type = 'Abc__c'; Map<Id, SObject> m = new Map<Id, SObject>(Database.query('SELECT Id FROM ' + type)); Also see the SObject documentation for ...
Keith C's user avatar
  • 135k
6 votes
Accepted

How do I do a universal SOQL?

It is possible to get the object's type from the ID then use this in the dynamic SOQL. For example: Id id = Id.valueOf(tool.cId__c); String objectAPIName = id.getSobjectType().getDescribe().name; ...
Phil W's user avatar
  • 34.1k
6 votes

When do we really need try/catch?

It seems you have some misconceptions about exceptions. I don't know if I'd say that all DML operations should be inside of a try block Exceptions can contain useful information for debugging, but if ...
Derek F's user avatar
  • 59.3k

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