function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kminevkminev 

Handle exceptions in Apex

Hi,

 

I have a function where if certain conditions are met I need to display an error message to the end user in red text. Kind of like the standard error message by salesforce, but instead I get the very verbose one.

 

Any ideas how I can throw error messsage on the user's screen?

 

Here is my code snippet:

 

 

public static void checkChangeAssetSubscribers(Change_Asset__c[] chgAssets) {

for (Change_Asset__c cass:chgAssets) {

if(isAssetsDup(cass, chgAssets)){
System.debug('Duplicate Assets detected!');
cass.Assets__c.addError('This Asset is already associated with the Change.');
//throw new CustomException('You cant do that!!!');
//return;
}

.
.
.
.
.

 

 

 

 

Thank you

Message Edited by kminev on 10-23-2009 08:03 AM
JohannesBorrmanJohannesBorrman

<apex:outputText id="errDbg" value="{!error}" style="font-weight:bold;color:red;" ></apex:outputText> public string error {get;set;}

 

use error = 'your text'; everywhere you need it?