New answers tagged

0

Test.invokeContinuationMethod looks for a callback method with the signature public Object callback1Response( ) that does not exist in your controller. As you are using @RemoteAction addnotation and your callback must be public static I would use a static Object variable in your controller and set it with a state object it in your constructCallout method. ...


2

Pretty much the same way you set a variable for any other class. Dot notation. IntegrationController myController = new IntegrationController(); // If the property is public or has a public setter, you can use dot notation // like normal myController.dt = Date.today(); Test.startTest(); myController.getData(); Test.stopTest();


1

Sometimes, the code coverage will get out of sync. To get proper coverage to show up in Developer Console, follow these steps: Click Test > Clear Test Data Click Test > Run All Tests As the tests finish, the coverage will be calculated. Once you do this, you should be good to go for a while. I typically do this once every few days to make sure my ...


1

There are several different ways you can approach this. Here are a couple of them: Split the DML into a separate virtual method and override this method in the one test that needs to simulate a DML error, using a test-specific class that extends the DeactivateUser_Restful_Ctl class that throws an error from the DML method. If you need to return "...


0

I've experienced something very similar to what you've described; here's what I've learned: The developer console seems to retain its code coverage for a given file until one of two things happens: The file is re-saved The test is re-run A different test is run, which touches the file So for me, typically there is a very short window of time where I can ...


0

Actually the developer console log is the easiest way to check code coverage and execution errors as well, were you checking as well the Overall Code Coverage Tab in the bottom right of the window! and in the Tests tab, does the folder of your execution has a green mark in its left, that would mean that the test is successful, and that would be the first ...


1

You need to requery the account to get the updated fields from the account trigger call. The reference to the account in your test class does not get any updates from the trigger. @istest public class TestAccountAddressTrigger { @istest public static void testAccountTrigger(){ List<Account> listAccount = new List<Account>(); ...


4

One way to increase coverage, assuming you want to use that method, is to take out all of the if statements. We do this by using the OR operator and returning the result: public Static Boolean isSandbox(){ String host = URL.getSalesforceBaseUrl().getHost(); String server = host.substring.split('\\.',2)[0]; Boolean isSandbox = false; ...


3

Test methods do not have access to the data in your org. Therefore your query is not returning any records which results in an empty list. You will need to first create the data in your test method. I recommend you review the documentation for Apex testing. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing.htm https://...


1

The only clear explanation that I see is that the name of the metadata component your unit test is trying to retrieve is incorrect. The behavior of that API is to return an empty list if no components are found matching the given list of names. This unit test succeeds in my dev org, showing that metadata retrieves are quite legal in a unit test: @isTest ...


9

Unit tests do not use the Search Index. This is because search indexes are not updated in real-time, so your search would fail anyways. Instead, you have to specify the results that should be returned: Contact testContact = new Contact(FirstName='First Name', LastName='Last Name', Email = 'email@email.com', Contact_Level__c = 'Primary'); upsert testContact; ...


1

In Salesforce you can't achieve this as of now. In the list of 'Overall Code Coverage' it shows all the Apex classes available excluding your test classes. Normally you are writing a test class for particular Apex class simply because to test your own code. https://developer.salesforce.com/forums/?id=9060G000000XfhgQAC From the test class you are running, ...


1

In general, you need to create a set of test cases that cover every code branch. For your code as it currently exists, you should test the following Cases: insert a new Case within hours insert a new Case outside hours update a new Case within hours update a new Case outside hours update a new Case that comes from the future The first four should set an ...


0

a unit test for this class would be to test that you can create an instance of this class. Then you can assert that the variables are what they should be. Your instance variables will be covered. @isTest static void testQuoteLineModel() { Test.startTest(); QuoteLineModel inst = new QuoteLineModel(); Test.stopTest(); // you can do similar ...


Top 50 recent answers are included