A unit test is code that is written and executed to test a specific portion/unit of source code. Unit tests are class methods with the testMethod modifier or @isTest annotation and are usually placed in separate test classes annotated with the @isTest annotation. Code that is executed by unit ...

learn more… | top users | synonyms

3
votes
1answer
30 views

Owner is null after insert - Test class

I have to test the results of a query like this: [SELECT Id, Owner.Name FROM MyObject__c] which is called in the constructor of a visualforce page. The Owner.Name is diplayed in the page. The page ...
0
votes
0answers
26 views

Test Class Code Coverage Issue : System.QueryException

My Apex class is Class1: Public class myclass{ //some code public void save(){ invoice_policy__c inp=[select ...
2
votes
2answers
24 views

Custom Objects Related to Lead associate to Account/Contact/Opp during Lead Conversion

We have several custom objects that can be related to Leads and that should end up related to the resulting Account/Contact/Opp during Lead Conversion. These Objects have multiple Lookup fields on ...
0
votes
1answer
74 views

Test Class for a Wrapper class when Checkbox is true

My Apex Class is Public class Myclass{ public class tempconwrapper{ public boolean selectedcheck; public void setselectedcheck(boolean b){this.selectedcheck = b;} public boolean ...
1
vote
1answer
43 views

Writing trigger test to test if custom object was inserted/updated

I am writing an after insert, after update trigger for a custom object CustomA_c. On changing the status field of this custom object to some value I need to create another custom object CustomB_c and ...
0
votes
3answers
40 views

How to create a custom field in test class

I have a custom setting which holds all the fields of an object. If i created a new custom field on the object it is need to get inserted into custom setting and for this i have written code which is ...
3
votes
3answers
121 views

How to write a unit-test / test class for trigger?

This Question is designated to become a community wiki - please add info, your guides and points, step-by-step procedure, as the subject deserves it. How do I write a unit-test / test class for a ...
-5
votes
0answers
27 views

Need Test class for Trigger Urgent [closed]

I need a test class for below Trigger. Need to move it to production urgently. Any help is much appreciated. trigger AutogenarateUsernamepassword on Account (before insert, before update){ Private ...
7
votes
1answer
84 views

Is a TDD approach feasable on Force.com?

I recently tried to do TDD (test driven development) on Force.com and hit a limit that seems to contradict my understanding of how Salesforce.com wants us as developers to work. What I just did was ...
-1
votes
2answers
68 views

How to move from development to production [duplicate]

Hi We have some development in our org. Now we want to move this development to production. How to do this, i bit confused in this. Can anyone tell how to move from development to production. Thanks, ...
12
votes
3answers
119 views

Cool, we can chain batches now! But we can't test them. Do we?

I just used the new feature that allows me to call a SecondBatchable class from the finish() method of the FirstBatchable class. global with sharing class FirstBatchable implements ...
0
votes
1answer
32 views

Inserting data to audit field like created date for test class [duplicate]

I am creating a test class and the scenario I am testing requires an older date for the created date. I know CreatedDate is an audit field and I can't write to it. Is there a workaround I could use ...
2
votes
4answers
166 views

Triggering a DML Exception for Test Coverage

I have an Apex Class, where 55% of the code is inside a catch, requiring a DML exception to be executed. Since the DML update request is using data from an SOQL request inside this class, I have no ...
6
votes
1answer
58 views

Make packaged test classes which definitely don't fail

I am writing test classes for a managed package which should work in any org. However, for my tests I need to create a test user and I know this can fail in orgs which, for example, have mandatory ...
2
votes
1answer
43 views

Ensuring Test Code Coverage when you have Insufficient Access Rights on an Object

I recently ran into an issue where we installed some Service Cloud pieces in our predominantly Sales Cloud org (including the Public Knowledge Base). This installed a few custom APEX classes and ...
0
votes
1answer
80 views

Need help writing a test class

I'm fairly new at writing classes but I'm getting better. Below is my Class public without sharing class OpportunityClass { private ENUM OPERATION {ISINSERT, ISUPDATE, ISDELETE} private ENUM ...
2
votes
1answer
20 views

Writing Unit Test for OnInstall script

Here is the scenario. I have a custom field on Contact, which gets auto-populated in a trigger before-insert and before-update. All fine, but this is a field in an Managed Package. Where the package ...
5
votes
1answer
48 views

need help writing test for a global controller

I'm trying to adapt a type ahead controller whose code i found on the web. It looks like this: global class autoCompleteController{ @RemoteAction global static SObject[] findSObjects(string ...
4
votes
3answers
67 views

Recommendation on great Code Comparing Tools

I am relatively new to Developer Force, but I see how it is important to have multiple Sandboxes, like any other programming environment. I know there are many Code Comparing tools out there, some are ...
6
votes
2answers
105 views

Force a Unit Test to run immediately inside Salesforce Web UI?

Is there a way to force a unit test to run immediately? You used to be able to go to App Setup > Developer > Apex Classes > [ClassName] > Run Test button. This used to begin processing a unit test ...
3
votes
1answer
42 views

How to view the detailed debug log of the change set validation in production

I pushed a changeset from stage (sandbox) to production. Everything worked fine in stage but in production it didnt. It just says "Test Coverage of Selected Apex Trigger is 0%, at least 1% test ...
2
votes
1answer
102 views

Need Help for Extension Test Class

I have a generic extention class and a visualforce page I need to write test classes against, but I am stumped. I have tried a few of the examples found here on StackExchange, but with no luck. Any ...
1
vote
1answer
66 views

Argument must be an object that implements Database.Batchable

I have wrote a batch class and now i am writing test class for it but i am getting this error. Argument must be an object that implements Database.Batchable Batch class global class ...
3
votes
1answer
157 views

Odd error when inserting Chatter post from Opportunity trigger

I have a trigger on my Opportunity object that executes after insert and simply posts a new FeedItem to a specific group within my instance when the Opportunity record Stage is set to "Signed". Here ...
4
votes
1answer
219 views

NO_MASS_MAIL_PERMISSION Error from Unit Test on SingleMailMessage

I am currently working in a Config-Only sandbox. I have a unit test that is continually failing with the following error message: System.EmailException: SendEmail failed. First exception on row 0; ...
9
votes
3answers
195 views

Test case failures due to VF email template

First, a little background information: I'm working on an end-to-end custom quoting solution that leverages the standard Quote object. We also utilize Sterling CPQ, which serves as the end-state for ...
2
votes
2answers
109 views

TestClass code Coverage

public string main(string url) { Http h= new Http(); HttpRequest req= new HttpRequest(); req.setEndpoint(url); req.setMethod('GET'); ...
2
votes
1answer
42 views

unit testing custom email validations

I have a catch-22 issue that I have been unable to test fully. I am using a W2L form to input lead information remotely and its well documented that using an email field can cause the record to fail ...
4
votes
1answer
52 views

What is the Deployment Testing Scope

I have a question related to Salesforce.com Deployment. When we try to Validate/Deploy a new Change Set, am I right when I say that it will execute every single test affected by the Apex class / ...
4
votes
2answers
176 views

No longer possible to mix testMethods in classes?

All of a sudden I am unable to call methods in any classes which are marked with @IsTest. The only thing I changed was all my *-meta.xml files (blindly) from ApiVersion 25/26 to 27. Until now all my ...
1
vote
1answer
96 views

Test Class for Xml Dom Document & WebServices

My Apex class public with sharing class helpTextClass { public string main(string url) { Http h = new Http(); HttpRequest req = new HttpRequest(); ...
4
votes
1answer
48 views

Is a test method isolated from effects of other test methods

Suppose I have test class TestClassName with two test methods: @isTest private class TestClassName { static testMethod void testMethodName() { // DML to insert data } static ...
3
votes
1answer
107 views

Where can I read the debug output of test classes

Suppose I have a test class TestClassName. @isTest private class TestClassName { static testMethod void testMethodName() { System.debug('My debug statement'); System.assertEquals(1, ...
2
votes
1answer
146 views

No more than one executeBatch can be called from within a testmethod

I am getting following error System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method ...
7
votes
1answer
422 views

How to reduce the test class execution time while deploying?

I have optimized almost all my test classes but the "Run All Tests" execution time is still not reduced. I ran the tests in my full copy sandbox and it took 28 minutes. There are about 464 test ...
-9
votes
1answer
41 views

Please help me testing following batch apex.Thanks [closed]

How to test emails sent to the user when using Batch apex?
-4
votes
1answer
136 views

Testing batch apex [closed]

Help me in writingTest class for Batch apex I created Batch apex to send emails to owners of the lead based on certain conditions. I have to write a test class to test gov limits. Thanks in advance
3
votes
1answer
33 views

Directly attributable code coverage?

Since the last release, when I execute a single unit test (via Develop > Apex Classes > Test Class > Run Test), I get taken to the "Apex Test Execution" screen. This screen shows whether the test ...
4
votes
1answer
143 views

REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]

when i trying to insert opportunity in my testclass i am getting an error Test_opportunityTrigger.Test_opportunityTrigger: line 24, column 1 22:28:17.312 ...
5
votes
2answers
320 views

UNABLE_TO_LOCK_ROW error while running all apex test classes

In spring13, I am getting UNABLE_TO_LOCK_ROW error in my few test classes while running all test classes in new view provided in spring13 release. But in winter12 I don't get any error like this. Do I ...
5
votes
1answer
154 views

Spring 13 Asynchronous Test Execution & Standard Pricebook

I'm facing a very annoying issue with the new Spring 13 release. Now all tests run asynchronously by default. Which would be fine except for the fact that a test locks all records it's using until it ...
2
votes
3answers
36 views

Where is the documentation for the Page keyword?

In the documentation for testing controllers and extensions, there's a statement that references a Page object, but I've been unable to find where this is located elsewhere in the documentation. Where ...
3
votes
1answer
64 views

How can I speed up Developer Console?

Since Salesforce have moved their test execution to be asynchronous in Spring '13 we are forced to use the Developer Console to see Code Coverage for a single test class. My issue with this is that ...
0
votes
2answers
98 views

INVALID_CROSS_REFERENCE_KEY, Can not select a person account: [AccountId]

My test class for inserting contact is static testmethod void invoicetest(){ string strrecord = [select id from RecordType where SobjectType='Account' AND IsPersonType=True limit 1].id; ...
0
votes
1answer
58 views

SOQL query produces different result with same input

In the process of writing a unit test on Opportunities, I'm inserting a custom object Journal_c. This custom object, Journal_c, has an after insert trigger associated with it. When running the test, I ...
0
votes
2answers
51 views

how to cover Id!=null part in test Class

public class democlass{ public string invoiceid{get;set;} PUBLIC DEMOCLASS(apexpages.standardcontroller controller){ invoiceid=apexpages.currentpage().getparameters().get('id'); ...
0
votes
1answer
139 views

How to query CodeCoverage from SOQL? [duplicate]

Possible Duplicate: How can I get code coverage programatically through Apex? How to query CodeCoverage of a class by writing an SOQL inside Apexclass? Is there an sobject which stores the ...
2
votes
2answers
100 views

How to check if any error has been added to a record?

I have created a method which is being called through a trigger. I am adding error to a record if it is a duplicate one using 'addError()' method . Now , I want to cover this method in my test class. ...
5
votes
1answer
237 views

How to identify classes covered in test class in spring 13 release?

Friends, in spring 13 release, Salesforce has removed the test class which shows what are all the classes covered for a test class, if we run that particular test class alone and now everything goes ...
1
vote
1answer
217 views

System.ListException: List index out of bounds: 0 in test Class

My apex class is tempinvoiceid = apexpages.currentpage().getparameters().get('tempinvoiceid'); tempin = [select ...

1 2 3