74 votes
Accepted

How to debug the mysterious "duplicate value found: <unknown> duplicates value on record with id: <unknown>" error

My condolences if you're reading this, because it means that you're being tortured by an extremely useless and vague error message. Let's see if we can get through this without tearing out too much ...
user avatar
70 votes
Accepted

LWC Navigation: "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 ...
user avatar
42 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 ...
user avatar
  • 87.4k
16 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 ...
user avatar
  • 440k
12 votes
Accepted

Apex Trigger giving "cannot specify Id in an insert call: [Id]" error

You have your DML statement inside of the for loop. So it is trying to insert the list each time through the loop. This will work fine for a single transaction, but the minute you do this with more ...
user avatar
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}"...
user avatar
  • 12.9k
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 ...
user avatar
  • 440k
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 ...
user avatar
  • 440k
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 (').
user avatar
  • 144k
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. ...
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 ...
user avatar
  • 7,605
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 ...
user avatar
8 votes
Accepted

Winter 15 preview new error messages: valueOf() function

There has been a change to the way that integer.valueof() handles NULL values. This line: decimal.valueOf(integer.valueof(mod.get('Average_Ratings__c'))) no longer works but this: decimal.valueOf(...
user avatar
  • 1,015
7 votes
Accepted

What controls the 'severity' of ApexPages.addMessages(exception)?

Try catching errors as below : catch(Exception e) { String error = e.getMessage(); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,error)); }...
user avatar
  • 16.6k
7 votes
Accepted

Can you make trigger exceptions pretty in standard page layouts?

Have you considered adding try/catch logic around any code that might cause an exception and then using the addError() method to display a more friendly error message to the user?
user avatar
  • 403
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(...
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 ...
user avatar
  • 440k
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) {...
user avatar
  • 4,769
6 votes

How do I query for the Product Object?

The product object is actually called 'Product2'. From the documentation Products are represented by Product2 objects. The Product object is no longer available. Try changing your SOQL to ...
user avatar
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 ...
user avatar
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 ...
user avatar
6 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 ...
user avatar
  • 2,022
6 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 ...
user avatar
  • 543
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 } ...
user avatar
6 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 ...
user avatar
  • 440k
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}...
user avatar
6 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 ...
user avatar
  • 440k
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 ...
user avatar
  • 87.4k
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 ...
user avatar
  • 131k
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; ...
user avatar
  • 28.2k

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