Questions tagged [adderror]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
24 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 ...
0
votes
0answers
68 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) { ...
0
votes
1answer
13 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 ...
0
votes
1answer
24 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 ...
0
votes
0answers
183 views

We hit a snag before update trigger

I wanna choose pricebook for opportunity automatically. For this i created some picklist fields for both object, and a trigger that select pricebook based on this fields. The trigger work properly ...
1
vote
1answer
71 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 ...
0
votes
3answers
82 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 ...
1
vote
1answer
90 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 ...
0
votes
1answer
61 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 ...
0
votes
1answer
56 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 ...
1
vote
1answer
82 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 ...
6
votes
2answers
721 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 ...
0
votes
1answer
74 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]; ...
0
votes
2answers
225 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 ...
1
vote
1answer
95 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)...
0
votes
1answer
322 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 ...
1
vote
1answer
509 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); ...
1
vote
0answers
209 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!=''){ ...
3
votes
1answer
140 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<...
0
votes
1answer
736 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 ...
3
votes
1answer
178 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 ...
1
vote
1answer
680 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 ...
1
vote
4answers
1k 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 ...
0
votes
2answers
53 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){ ...
7
votes
1answer
1k 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 { .... ...
6
votes
1answer
261 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. ...
4
votes
1answer
572 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 ...
0
votes
1answer
870 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 ...
2
votes
0answers
26 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 ...
0
votes
2answers
1k 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 ...
0
votes
2answers
873 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?
2
votes
2answers
2k 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 ...
0
votes
1answer
26 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/...
0
votes
3answers
432 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? ...
1
vote
2answers
235 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 ...
2
votes
2answers
321 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.
2
votes
1answer
504 views

Catching the exception “SObject row does not allow errors”

I'm writing a batch class that I'm hoping can utilize some existing trigger code. However, the trigger code uses the addError method, which causes my batch to fail with the message System....
0
votes
1answer
314 views

I am getting error when trying to use addError() on Account Object

I tested this in my dev org for Account object: Class: public class Account { } Trigger: trigger AccountTestTest on Account (before insert) { for(Account c: trigger.new){ c.addError('...
0
votes
0answers
12 views

For all the records on a object how to enforce that there can only be one record where a checkbox field would be checked?

I've a checkbox field on an object. Now, for all the records on this object there can only be one record where this checkbox field would be checked. Need help here as to how do I implement this? Edit:...
1
vote
0answers
23 views

Enforce DML statement to be failed within a batch

I am trying to make a DML statement in a batch to be failed. The reason for this is that I have logic executed in my batch in case the DML failed for some records. I would like to test it and get the ...
0
votes
1answer
201 views

How to add error message to opportunity record page

I have added a custom button on the Opportunity page which invokes an apex code. The invoked apex code is redirecting to the same Opportunity page. ... PageReference pg = new PageReference('/...
1
vote
0answers
49 views

HTML escape not working in Salesforce1

I am adding an error message to a record using the Sobject.addError(errorMsg, escape) method, and I am trying to add a clickable link to my customer service departments phone number. ptCaseObj....
2
votes
3answers
373 views

Disable Email Sent to Administrators from addError()

I created an addError() method in a trigger with a custom error message like so: item.addError('Hey! You aren't authorized to do that!'); I have also received error emails like so: Dear Admin,...
0
votes
1answer
1k views

Error in $A.getCallback() [TypeError: Invalid value used as weak map key] Failing descriptor: {markup://c:Top5Clients}. Please try again

I have two components 1)Top5Clients and 2)MessagesandAlerts which retrieves recodrs from their respective custom objects I want to display the two components side by side so I have included in a ...
0
votes
1answer
5k views

Use AddError() inside an Apex Class

Is there any way that we can use addError() inside an apex class? I know it will work properly inside a trigger. But i would like to have a separate class for all validations instead writing them ...
2
votes
1answer
2k views

Before Insert: Using __r to pull related data in a Trigger.New for loop results in nulls even though lookup relationship has Id

Situation: I am trying to build a custom validation rule via apex that will stop users from saving a charge item to a quote if the charge item exceeds the available product quantity. The charge item ...
1
vote
1answer
891 views

Apex addError() works only for text/number SObject fields, when use inlineEditSupport in pageBlockTable

I have few custom validations, which i use in my controller. And i found that not for all fields it works correctly. I figured out that it shows only message, but doesnt show error near the inputField ...
0
votes
1answer
554 views

Before Trigger Create Record - Error on Original Records

I am using a staging object in Salesforce to receive data from a middleware platform via SOAP API and I wish to then write a before (or after if need be) trigger which does the following: Splits the ...
1
vote
1answer
10k views

Add Line Break In Error Message

The below code builds an error message displaying the values from multiple records (typically 12). Map<String,Budget__c> budgetByIdentifier = new Map<String,Budget__c>([SELECT ...
0
votes
1answer
391 views

how to show error message on vfpage when user enter wrong datatype for field selected

<apex:pageBlock title="Find Duplicates"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> </apex:pageBlockButtons> &...