Questions tagged [try-catch]

try-catch is used to catch the exception.

Filter by
Sorted by
Tagged with
2
votes
1answer
118 views

Rewriting Try + Catch{System.Assert(false, 'blahblah')} for easy toggle-off of catch?

Dear Salesforce StackExchange, An outside partner set a precedent in some of our Apex triggers of doing major operations (such as DML) inside a try/catch block, and having the catch block simply ...
1
vote
2answers
275 views

batch class Run fine with individual record but not working fine with multiple records

I am writing batch class to deactivate users if no dependency and freeze user if any dependency.When i hardcode singal value of userid and run batch it works fine it deactivates user.It is not going ...
0
votes
3answers
2k views

Not able to catch exception using try catch block

I am using try-catch block to catch exceptions.code is executing inside try block.Exceptions happens which i am thinking i am handling in catch block.When i debug whole code after exception code is ...
2
votes
3answers
121 views

Coverage for Catch Block (cant generate exception in try{}) give another solution

NOTE : This question is not duplicate.Please go through code once. Here is the situation - I am calling this method from my test class, and here My_obj__c records are getting created and added in ...
1
vote
0answers
1k views

Unable to cover Clone() method in test class

I'm having a simple code where I'm cloning an opportunity object with the necessary child elements. When I'm writing a test class for it, the clone method is not called and it is going into catch ...
2
votes
1answer
49 views

Can't catch exception from ChatterFeeds

I have this code. It still generates an error despite of my catching statement: (max length=5000) I can't catch this error! This is my method and how to i catch exception from it: void ...
8
votes
1answer
4k views

Catch Regex too complicated when splitting a string in salesforce

I have created a function wherein I split a string from the csv filecsvAsString.split('\n') . It is working when the string is not so big. But when I try to split a very large string, an error will ...
4
votes
1answer
3k views

Custom Exception Handling & Logging

I've set out to build a custom error handling and logging feature for my org wherein all apex exceptions will be logged into a custom sObject for analysis and follow-up. public class TriggerException ...
-2
votes
2answers
2k views

how to cover catch block in this method in test class

public pagereference savePassword() { if((objAccountTemp.Contact_Name_1__c != null && objAccountTemp.Contact_Name_1__c != '' && objAccountTemp.Affiliate_User_Name__c != null &...
1
vote
1answer
114 views

try and catch with a count

If this statement has no records will it return 0 or does the "try" feature cause it to fail and fall thru to the "catch" statement after an if/else statement. The "if" statement checks for the ...
5
votes
1answer
974 views

do javascript remoting calls need a try/catch?

Currently in my javascript remoting calls I check for if (event.status===true) in the callback. I handle any errors in an else. However, it seems it also throws an exception. Example: [Error] ...
10
votes
1answer
4k views

Catch System.AssertException

Is there a way to catch System.AssertException? For example, some class is known to throw assertions in certain cases and it's ok to deal with that on some upper level. But unfortunately ...
14
votes
3answers
6k views

Can I throw an exception in apex and still log the caught exception?

I'm really wrestling with the best error handling strategy. My goal is to handle all exceptions that I can identify, log them to a table in the database, and surface a helpful message about what ...

1
2