• davidpadbury
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I am reusing the same validation code in several triggers, so instead of duplicating this for each I have refactored it into a class which they all call. When testing this class in isolation the sObject.addError method does not throw a DMLException. This is to be expected as the documentation states that exceptions are only thrown in the context of a trigger.

 

My question is, are there any other ways of testing that the addError method has been called?

 

I've put together an example to demonstrate this issue...

 

 public class ErrorExample {
    
    public static void addAnError(sObject obj) {
        obj.addError('test');
    }
    
    static testmethod void addAnError_alwaysAddsAnError() {
        Boolean hasFailed = false;
        
        Account a = new Account ( Name = 'Test' );
        insert a;
        
        try {
            ErrorExample.addAnError(a);
        } catch (DMLException e) {
            hasFailed = true;
        }
        
        // THIS ASSERT FAILS
        System.assert(hasFailed);
    }
    
}

Hi all

 

Is there anyway of reading a file (using a file upload) or document present in salesforce within apex code? Anything on this would help as there doesn't appear to be any documentation around.

 

Thanks for any help

 

James

Hello,

 

I had a test class "TestRecordTypes" that is part of a managed package. I deleted the class because I wanted to move the test methods inside the controller that was being tested. This didn't work like I thought it would, so I wanted to restore the code from the deleted class, which I had saved locally.

 

There seems to be no way to overwrite or undelete the class. In Eclipse if I create a new class w/ the same nameI get prompted w/ "Duplicate Component Found," and it asks me if I want to overwrite the remote instance. If I choose "OK" I get a local class w/ the deleted code in it. When I save I get errors for the class and it's meta.xml file saying "Save error: Conflict found while preparing to save 'TestRecordTypes.' to server.  Remote instance has been updated since last save or sync.  Use the Synchronize Perspective to resolve the conflict." But the Synchronize with Server tool doesn't let me upload the code to the server. If I try to deploy the newly created class to the server I get an error "Class is deleted". The deleted class still shows up in the SF UI under Develop / Apex Classes but there doesn't appear to be any way to undelete the class.

 

So I appear to be stuck in that Twilight Zone episode where you walk down a street but always end up back where you started. Is this a "feature" or is there a way to restore the class?

 

thanks in advance,

joezaloom