Questions tagged [adderror]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
91 views

Apex trigger addError() always shows error-msg

Good day, everyone. I have started learning Apex. And need help with triggers. The problem is: I have custom object Gift Card, which is not related to any other objects. On Opportunity I have custom ...
user avatar
0 votes
1 answer
612 views

Create a custom error message with apex

I am trying to create an error message with apex when saving a quote. I already have the logic done but I would like to know if I can create this type of error messages as shown in the image. I don't ...
user avatar
0 votes
0 answers
19 views

adding an existing user to my sales app

scenerio: .......both user A and B are on salesforce...... user A runs a little Ad agency, user B requires the help of User A, as a mentor. My Question: why can't it be possible for user B to invite ...
user avatar
0 votes
1 answer
149 views

Handling errors with future callouts from Trigger

My design is that whenever an account is created, It calls an 'after insert' trigger that makes a future callout to an external system and sends the account details. If there's an error in the future ...
user avatar
0 votes
2 answers
259 views

Query child records when relationship is with same object

I have a lookup field on case which points to case object. (Field: Parent__c). I want to query child case records from a parent case using an aggregate query. Below is the query I have used- [SELECT ...
user avatar
  • 50
1 vote
1 answer
235 views

multiple addError() behaviour in apex

We have a trigger on the Account and Contact objects. The job of these triggers is to prevent the deletion of Account and Contact objects depending on the criteria. Account should be deleted if no ...
user avatar
  • 1,313
-1 votes
1 answer
36 views

Display a proper error to user [closed]

may I know how to make the system show error to users in a proper way? Because I try to use adderror(), but still not working. it keeps showing the below error if the user does not fills in these ...
user avatar
0 votes
2 answers
3k views

AddError on Before Update

I am trying to display an error message if a field on Quote is updated to a certain value. I am doing it on before update but I am encountering an error Here is a sample code block I am trying on my ...
user avatar
  • 37
-1 votes
1 answer
54 views

Can anyone explain logic inside trigger exception

trigger accountDeletion on Account (before delete) { // Prevent the deletion of accounts if they have related opportunities. for (Account a : [SELECT Id FROM Account WHERE ...
user avatar
0 votes
2 answers
60 views

How To Prevent creating Accounts In a specific month

I want to avoid Creation or Deletion of Accounts in a specific month(for eg December). How can I achieve this. Because the createdDate is null in before Insert and addError does not run in after ...
user avatar
4 votes
1 answer
489 views

How to display a error message with hyperlink on standard detail page through trigger

I'm trying to add the record link inside the "addError" on the trigger for(Account account : (List<Account>) triggerParams.triggerNew) { String url = URL.getOrgDomainUrl()+'/'+...
user avatar
  • 41
2 votes
0 answers
65 views

How to check for/retrieve record-specific error message, e.g. by errors added through sObject.addError or validation rule?

I'm wondering about the documentation for the sObject class (API 50). It clearly states this for hasErrors(): Returns true if an SObject instance has associated errors. The error message can be ...
user avatar
  • 942
0 votes
1 answer
454 views

Execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors ()

I have created a trigger on the Opportunity object for before insert and before update, through which I am sending the Trigger.newMap variable as an argument to my apex class where I am checking the ...
user avatar
1 vote
0 answers
2k views

Apex Trigger to stop record from being saved in Salesforce

I have a requirement to stop the record from being saved when a checkbox is set to true in that record. This record is saved from Lightning component and on click of Save button from the component, ...
user avatar
  • 73
0 votes
1 answer
116 views

addError message is firing in one sandbox but not firing in other sandbox

I have a requirement that users should not be able to remove document from the closed cases. I have achieved this by writing a trigger on before delete on contentdocumentlink. My old code was like as ...
user avatar
0 votes
1 answer
145 views

AddError Not working on before update Trigger

I have a newbie issue.... hahaah This is my code where I Need to avoid an update and show an error messaje if a lookup field has the status "Cerrado" but whith this code, the objects are ...
user avatar
0 votes
0 answers
153 views

addError() method behavior on FeedItem trigger

I've written a basic trigger on FeedItem, which restricts users not to delete their chatter posts (simplified to clarify my question). trigger beforeDeleteFeed on FeedItem (before delete) { ...
user avatar
0 votes
1 answer
116 views

Test Class Opportunity Line Item, add error

I wrote a trigger to count the number of values in a multi-select picklist (custom_coins__c), if more than 10, error (too many coins selected). I'm new at writing code and can't figure out the test ...
user avatar
  • 1
0 votes
1 answer
284 views

Raising friendly user error from trigger context

I have after update trigger on contact. I am trying to write a friendly error to screen whenever x is happening.(in apex code) I followed this explanation: Difference between the multiple messaging ...
user avatar
1 vote
1 answer
260 views

Lead Trigger and lead.addError()

I have this problem with triggers: We have integration with our backoffice to receive leads. Unfortunately, we can't change this integration. It sends the leads when when it shouldn't. On insert if ...
user avatar
0 votes
3 answers
2k views

Error Handling in REST Webservice

I have exposed this Apex class as a webservice. So far so good, as I get the response when this Webservice is called from ARC or POstman. @RestResource(urlMapping='/ProcessAccount/*') global with ...
user avatar
1 vote
1 answer
256 views

Apex debug logs change trigger execution, makes addError(String) either throw or not throw exception

I have a fresh case of strange Apex behavior that is throwing me for an absolute loop. I have a trigger on after insert and after update that needs to cycle through some records. It will update ...
user avatar
0 votes
1 answer
454 views

addError() in TriggerHandler

i'm receiving lead records via API REST from an external service. If the record doesn't accomplish with the condition, i'm adding an addError() to the lead record. The problem is that i can't control ...
user avatar
0 votes
1 answer
356 views

Alternatives to add error

I've been using addError() to prevent dml insertions of records that don't accomplish with the validation rule. The problem is that using that, if i insert a list of 100 records and one fails, the ...
user avatar
1 vote
1 answer
355 views

Trigger addError('blah') -> Lightning Components JS alert('contense of addError('blah')')

I am sure my Title does not help much, but not sure how to shorten this question concisely. I have a Lightning Component that has the ability to update a case record. I have an APEX Trigger that ...
user avatar
6 votes
2 answers
4k views

Does addError() work outside of triggers?

I moved a method that sets addError() from a trigger into a Helper class. As I started writing test code for it it seems like the addError() is not actually preventing DML operations for the records ...
user avatar
  • 4,441
0 votes
1 answer
396 views

Error in trigger "Variable does not exist"

trigger preventDuplicateAcc on Account (Before insert , Before update) { for (Account acc : Trigger.new) { List<Account> a = [Select id,Name from Account where Name=:acc.Name]; ...
user avatar
  • 37
1 vote
2 answers
728 views

Display child trigger error in friendly way on parent record page

Example When updating an Account record, it fires an Account before update trigger which changes a child Contact record, which fires a Contact before update trigger, which validates the change and ...
user avatar
  • 8,262
1 vote
2 answers
351 views

Unit testing addError without doing DML

We're big fans of doing unit tests using as little DML as possible, mocking SObjects using various techniques Here's a simple example public class FoosService { public void doBar(Set<Id> ids)...
user avatar
  • 62.3k
0 votes
1 answer
1k views

Trouble with AddError method

Sales Invoices are a custom child object of Opportunity. I'm trying to write a class that throws an error if the total of all sales invoices for a given opp goes above the opp's amount. Currently it ...
user avatar
1 vote
1 answer
1k views

Exception in Database.save result in trigger context

1) In my opportunityLineitemtrigger, I have a method which updates the opportunity. system.debug('######'); database.saveresult [] rst = database.update(oppList,true); system.debug('######'+rst); ...
user avatar
  • 165
1 vote
0 answers
294 views

addError is not showing anything on Lightning task page?

We have code that adds error messages to objects, and the point is to do so regardless of being in classic or lightning, so addError was used. All we are doing is this: if(validationMessage!=''){ ...
user avatar
  • 2,339
3 votes
1 answer
165 views

How to enforce CRUD and FLS in bulk trigger?

How to enforce CRUD and FLS in following situation (bulk trigger). Better idea is simply throw an exception or addError(errMsg) ? trigger CaseCommentTrigger on CaseComment (after insert) { List<...
user avatar
  • 645
0 votes
1 answer
1k views

Bulk Update Accounts - trigger to throw error

I have a requirement that only if the accounts list has one record, the inspectionsToUpdate is updated. If there is more than one record in the accounts list, for example, because someone is trying to ...
user avatar
3 votes
1 answer
345 views

Sobject Row does not allow Errors on Cross Object Error Trigger

System.FinalException: SObject row does not allow errors When I attempt to test my error code. Other documentation I've read states that this would only occur if the error is not set to the record ...
user avatar
  • 47
1 vote
1 answer
2k views

Before Delete addError() message not user friendly

I have a before delete trigger on Topic Assignment that I'm using to block a User from deleting a Topic from a Question in a lightning community. The trigger works fine and blocks the DML, however the ...
user avatar
  • 11
1 vote
4 answers
2k views

Parent case cannot closed if any child case is opened using trigger not working

Parent case has multiple child cases when i am trying to closed parent case it closed now but according to requirment if any child case has status open or anything except Closed then parent case ...
user avatar
  • 1,298
0 votes
2 answers
96 views

addError is not working and allowed to store more than 3 child for corresponding parent

Requirement : not allowed to save more than 3 child for a parent here is trigger code trigger counterCh on Contact(before insert,before update){ if(Trigger.isInsert || Trigger.isUpdate){ ...
user avatar
  • 1,298
7 votes
1 answer
2k views

How to rethrow DmlExceptions as AuraHandledExceptions right

Exception handling in Lightning is a pain. Instead of Lightning showing regular exceptions one has to catch them in code and rethrow them as AuraHandledExceptions as shown below: try { .... ...
user avatar
6 votes
1 answer
334 views

Preventing duplicates with addError

So basically was trying to prevent duplicates in my Lead Trigger by checking the lead's email and crossing it with the Contact object in order to verify that no contact with the same email exists. ...
user avatar
5 votes
2 answers
1k views

Determine if an SObject has an error

Is there a way to calculate if an SObject in a trigger context has had an error added to it (either with addError or through a validation rule)? I have some trigger processes I don't want to run if ...
user avatar
0 votes
1 answer
2k views

How can I add custom error message and remove the error message thrown by Site.login in visualforce page?

How can I add custom error message and remove the error message thrown by Site.login in visualforce page? Im having trouble removing the error message thrown by Site.login that says "Error: Your ...
user avatar
  • 3
2 votes
0 answers
30 views

Is it possible not to display INSERT FAILED Error in page, when our custom validation error is triggered

We have a visualforce page (Manage Packaged) that saves a record. We added a custom validation using trigger (addError method) to prevent it to save when a certain criteria is met. But when this is ...
user avatar
  • 273
2 votes
3 answers
3k views

addError for multiple validation messages on the same record before insert trigger

In before insert trigger I need to verify couple of validations for which I have written 2 methods - Method1(casesList) and Method2(casesList). Both methods operate on the same list of cases in before ...
user avatar
0 votes
2 answers
2k views

when to use validation rule & trigger's add error method

what is the difference between validation rule & triggers add error method? mens when I can use validation rule & when use adderror method?
user avatar
2 votes
2 answers
3k views

Difference between addError(errorMsg) and addError(exceptionError)

Wondering if anyone can explain the difference between errors and exception errors, or, more specifically, when one should use addError(errorMsg) instead of addError(exceptionError)? The ...
user avatar
0 votes
1 answer
36 views

Public Write Access allows for mass edits, how to throttle editable batch size for certain users for specific field?

I need to conditionally restrict the number of records that apex allows to be edited, based on user profile, number of records in the save transaction, and an oldmap newmap field compare. See attempt/...
user avatar
  • 1,080
0 votes
3 answers
830 views

Do apex methods invoke at the same time in a trigger?

Just want a sanity check.. I have two methods on the same Trigger (both are isBefore execution). Does it matter which order I execute them in the trigger? Or do they both execute at the same time? ...
user avatar
  • 890
1 vote
2 answers
338 views

Why am I getting duplicate ApexMessages when concatenating string in a try/catch

I have two different approaches for adding an error to my visualforce page. The first approach I am concatenating a string at the end of exception. The second approach I am simply returning the ...
user avatar
  • 889
2 votes
2 answers
422 views

The code block containing 'addError' is being executed but no error thrown during record save

The code block containing 'addError' is being executed but no error thrown during record save.
user avatar
  • 35