65

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 hair. :-) Deployment Error or DML Error? If you Google "duplicate value found: <unknown>...", the results you get will cover a wide variety of ...


52

Salesforce platform has a feature ROW LEVEL Security. This feature ensures that sharing and visibility set by salesforce administrators for the records have to be maintained. As a part of this feature, there are sharing calculations that the platform has to perform when the record ownership is changed or child records are created/modified. Assume that a ...


47

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 who (like me) only skimmed the documentation before diving in :)


43

The error happens when you're trying to insert/update the record which can't be logically inserted/updated. So basically make sure that: you don't insert/update a record that does not exist, you don't update object field that is build-in/read-only, you perform the action using the user who has not the right access to modify the object More detailed ...


40

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 ordinary happened - and allow the application to safely move back into an anticipated pathway of operation, preserving The integrity of the data involved. The ...


16

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 gracefully transformed into something your code can handle (except LimitException, which would kill the transaction uncontrollably anyways). You should catch ...


12

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 than 1 transaction, it will fail. In the case of multiple transactions, the first time through the loop, it will work fine, as there is only 1 opp in it. ...


12

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}"> <aura:attribute name="response" type="Object" /> <aura:attribute name="successHandler" type="Object" /> <aura:...


10

You are only allowed to use single quotes in your query. Replace all of your double quote characters (") with single quote characters (').


10

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. The better solutions are: Use a custom object to log all these errors that you can query and report on . If you are worried about storage limits then prefer ...


10

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 is precision-scale, or in other words, 2 significant digits. As configured, the field's maximum value is 99.99999999. You'd want to edit the field to allow 3 ...


9

First please take a look at this answer for a partial solution / approach, Can I prevent an insert to be rolled back even if my class (later) runs into an exception?. Basically as per the Apex Developers guide the final commit transaction management is baked into Apex, meaning it will always rollback if you let the platform handle your exceptions, if you ...


9

If you use the label attributed on your selectRadio, that value would be displayed instead of the j-id0..... <apex:page standardController="Account" extensions="EventController"> <apex:form > <apex:pageMessages></apex:pageMessages> <apex:pageBlock > <p> Please select </p> <apex:selectRadio value="{!...


9

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 able to reset 4 to 5 fields in one condition. <aura:component > <aura:attribute name="truthy" default="true" type="boolean"/> <lightning:...


9

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 insertAccount(){ try{ // a required field is missing insert new Account(); } catch(Exception e){ ...


8

@Shebin answered your specific question, but there are a few issue with your trigger, the most important being that it is not bulkified. you always want to avoid SOQL inside loops. Something like below is a bit safer to use trigger AccountDuplicateTrigger on Account (before insert,before update) { //You may need to filter this a bit more if you have ...


8

As a follow up to this thread and to answer this question should anyone happen up this, here is what I discovered: The Auth.RegistrationHandler interface at the heart of this question has two main methods, as Andy noted, createUser() and updateUser(). The former returns a user and the latter is a void method. I tried Andy's suggestion and pattern of try/...


8

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(0) is a good work around if mod.get('Average_Ratings__c') = NULL


8

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 Database.Batchable<SObject>, Database.Stateful { Exception[] errors = new Exception[0]; public Iterable<SObject> start(...) { ... }...


7

Try catching errors as below : catch(Exception e) { String error = e.getMessage(); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,error)); } Instead of just doing ApexPages.addMessages(e); Using this in conjunction with Apexpages.hasMessages() if(some_condition){ ...


7

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?


7

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(' No Budget record was found for MRF record(s) with ' + errorMessage + '<br/>' + ' [WE_MRFv3]',false); The above should at least put [WE_MRFv3] on a new ...


7

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 that we developers have control over. For example, a Fatal error might be when SOSL fails to run because the search sub-system is down, while a normal Error ...


7

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) { List<Account> accs = [ SELECT ShippingPostalCode, BillingPostalCode FROM Account WHERE Id IN :Trigger.New ]; }


6

You can display error messages using the addError method on sobject or its fields. Salesforce docs on the sobject instance addError method: https://developer.salesforce.com/docs/atlas.en-us.198.0.apexcode.meta/apexcode/apex_methods_system_sobject.htm#apex_System_SObject_addError More info on exception handling: http://wiki.developerforce.com/page/...


6

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 the icon. Then i have wrapped my message in a outputPanel and edited the message class (but only for this output panel): removed background and border. You can ...


6

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 found inside your if(lstAccount.size() > 0){ ... } block. You can also add a return statement like that: if(lstAccount.size() > 0){ AccName = lstAccount[...


6

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 page. Whenever your condition meets, that page will display the warning message


6

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 of that setting, "Allow users to send emails through Gmail/Office 365 when composing emails in Lightning Experience. The Send Email through External Email ...


6

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 setting. This will fail deployments that contain profiles from orgs where this setting is set to 'All Emails' where the target org has this setting set to 'No Access' ...


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