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 (2)

2
votes
1answer
22 views

Not enough coverage for Apex utility Class, although COLLECTIVELY my unit tests cover everything

I've moved a lot of my trigger code over into class methods so I can control what order the logic happens in. Each object has one Trigger like this, and each Trigger may might call up to a dozen ...
-3
votes
1answer
48 views

System.NullPointerException: Argument cannot be null. in Test Class

At this line I am getting an errror, while running a Test Class, Please suggest solution - public PageReference Save(){ -------code ------ Object__c obj = new Object__c(); ...
0
votes
1answer
30 views

batch class execute() method not covered by test class

Need to raise the covered line on this apex code could you kindly point out the missing piece of code for my test class. It does not covered the code in bold face (global void ...
-1
votes
0answers
43 views

How to achieve ~100% code coverage? [on hold]

public class Controller{ public List contacts{get;set;} public List models{get;set;} public ModelClass model{get;set;} public Controller(){ contacts = new ...
0
votes
2answers
38 views

I need help writing a test class

I have written the below trigger and helper class. I am a newbie and pieced the trigger and class together with help from various forms. It works fine in sandbox but I have no idea how to write the ...
0
votes
1answer
42 views

visualforce Page reference custom controller test class

I have visualforce page that using custom controller. page have section to save record to my custom object. <!-- ...
1
vote
1answer
44 views

Test Apex Class Error: Error: Compile Error: Expression cannot be assigned at line -1 column -1

I am playing around SFDC and wrote a trigger to count the total Contacts in the system. I wrote the test class and when I am trying to save the class I get the following error: Error: Compile ...
1
vote
0answers
51 views

error from test method - “apex job is already scheduled for execution”

I have a batch apex which starts itself after x mins. this is done in finish() method using , system.scheduleBatch() method. below is how the batch looks like, global class my_ProcessPurge_Batch ...
0
votes
1answer
32 views

Test class coverage for Exception

I have below code to coverage : public static list<Contact> getContactsByAccountId(Id accountId, Id contactId){ try{ return [SELECT Id, firstName, LastName, Email, Phone ...
1
vote
1answer
45 views

Linking a contact to user

I am trying to link a contact to a user object in test case. However, it seems that user.contact = contact doesn't work and user.contactId = contact.id will cause an error saying contactId field is ...
1
vote
1answer
27 views

Missing FolderId in Chatter Trigger Test Class

We created a trigger and test class: when a new record under Keyword object is created, we want an email notification sends out automatically to record owner and confirm we receive his keyword ...
0
votes
1answer
16 views

How to create OpportunityPartner object to test OpportunityPartner functionality?

I want to write some tests to check a logic, related to OpportunityPartner object. The logic reads OpportunityPartner for Account, then reads it's Contacts. partners = [ SELECT OpportunityId, ...
0
votes
2answers
38 views

Test class for new case controller

I've recently been writing a few basic controllers for some visual force pages, and of course now need to test them. Problem is I don't really know how. Normally you know you'd instantiate the class, ...
5
votes
2answers
60 views

Relationship returning null in unit test

In a unit test, I'm having a problem where values spanning relationships are blank. I have a custom field, Quote.My_Formula_Field__c, which is defined as Opportunity.Lookup__r.Name, which is used in a ...
3
votes
0answers
19 views

Confirmation that certificates can't be created in unit tests?

I have some Apex code that uses: Crypto.signWithCertificate('RSA-SHA256', Blob.valueOf(token), 'CertificateName') and ideally would like to be able to create a named certificate in the unit test. ...
0
votes
3answers
72 views

Issue with Code coverage during deployment

Hello I am trying to deploy a Trigger and a Class from my Sandbox to production environment. I am running into Code coverage error. The code coverage when i look in the developer console says is 75% ...
-1
votes
0answers
27 views

Creating a unit test for a trigger

This is my first stab at creating unit tests so I am learning a lot as I go. The first block of code below is the piece that I have been focusing on creating test coverage for and below it is the ...
0
votes
0answers
11 views

Writing test cases for Salesforce sdk hybrid_local applications

I want to write test cases for my salesforce sdk hybrid_local applications. I use angular js. After some reading figured out that Jasmine, Karma(unit tests) and Protractor (end to end tests) are the ...
0
votes
3answers
44 views

Unit testing a trigger - expecting right curly bracket, found 'insert'

I am creating unit tests to test a trigger that makes a calculation with particular variables depending on the value of a different. I believe the code below is correct, however I cannot figure out ...
0
votes
1answer
38 views

Deployment error while deploying

Apex class: public void post(){ HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); req.setMethod('POST' ); ...
1
vote
1answer
32 views

Unit Testing a Trigger

Here is the piece of code for a trigger that I need to break into unit tests. I was thinking that I could begin by testing the most further in if statements as one unit test and make an additional ...
4
votes
3answers
107 views

Test Apex Code: How to emulate a SOQL call that has a related object?

For Apex testing, I'm trying to create an object that is the same as the one created with a SOQL statement (see following method). The method retrieves the Quote_To_Lease__c object from Salesforce ...
0
votes
2answers
94 views

Help me out with Apex Test class for the Apex trigger

Can any one help me out with this Test class written for this trigger is right or wrong.The Test class get saved but unable to see the code coverage. Here is the Code for the TRIGGER : trigger ...
3
votes
1answer
34 views

Programmatically Create Record Type

Is it possible to programmatically create a record type in Apex to be used in a test?
0
votes
1answer
25 views

Test Class to verify fields updated the same as the expected output

I'm creating my first test class got stuck with this one could you help me verify and correct the line of code for me. //Create a new record for Address Object with Local record type ...
-1
votes
0answers
12 views

How to write apex tests for custom settings? [duplicate]

I want to write a test class for a trigger which contain a custom setting. trigger UpdateState on account (before insert,before update) { map<String, CityStateSettings__c> CityMap = ...
0
votes
1answer
24 views

variable doesn't exist

I was getting too many soql queries, so decide to split the unit test. Now i am getting the error variable doesn't exist:rtmap @isTest(SEEALLDATA=true) public class test_createCaseFromOppt { ...
2
votes
2answers
228 views

Compile Error: Method does not exist or incorrect signature: Test.startTest()

I am experiencing something weird on the Sandbox with all the test classes. whenever I run a test class I get the error: Method does not exist or incorrect signature: Test.startTest(). I am ...
2
votes
0answers
22 views

Async Callout Test Failing in Production

Situation I have implemented an API to communicate with the external system. After 18th of August test that i have on production have started failing showing the infamous: ...
11
votes
1answer
67 views

Is it possible to simulate record locks in test methods?

I would like my test cases to also test exception handling. In theory an easy way to cause an exception on DML is to lock a record that it'll update so that the update will fail. But I'm having ...
4
votes
2answers
74 views

System.QueryException: No Such Column - Strange RunAs Behavior with Summer '14?

Question Is there any known reason a SOQL Query would return a runtime System.QueryException on a custom field in test methods, in particular one one via a parent lookup in a test? I would have ...
1
vote
3answers
73 views

Is it possible to get 100% Apex code coverage all the time?

Is it possible to get 100% code coverage all the time by considering all cases such as positive/negative, bulk/single etc. Are there any cases which can't be covered by test classes? I often hear that ...
0
votes
0answers
26 views

Suggested Unit Testing Approach When Checking for XML Child Nodes

Unit testing is currently at 60% code coverage on a specific class. Many of the lines of code that aren't covered by tests look like the following: global class IFXIndividuals { global ...
5
votes
5answers
301 views

Why isn't a SOQL query of mine populating a list in an Apex test class?

Why does my taskOpp query below not return any records when I run this test? The query works fine in Workbench and my taskRT query works fine in both my code and in Workbench. public class ...
1
vote
1answer
33 views

Advice on writing basic Apex Unit Test

The purpose of the controller below is to return the value of the one__c field on the Acc_Plan__c object, and then pass it into the getIsOneTrue() method. The controller works fine, but I have to ...
1
vote
0answers
35 views

Calling a webservice method from apex test class

I have a simple webservice method that updates Account Status from a custom Button in the Opportunity page: Global class Backoffice { WebService static Integer GenerateBackofficeTask(id opId) { ...
-1
votes
0answers
21 views

Test class doesn't cover Trigger [duplicate]

Can anyone give me the test code for my apex trigger: trigger Test_Share on Test__c (after insert) { Id UserId=UserInfo.getUserId(); Boolean bln=false; List<Id> ParentUserId = new ...
0
votes
1answer
33 views

Inserting Test.loadData in into Salesforce DB for tests

I am able to load the static resource but I am unable to insert the loaded accounts into salesforce. I want to do this to be able to test various methods that depend on first selecting a particular ...
1
vote
3answers
154 views

Invalid Cross Reference Key : Record Type ID value isn't valid for User: 012v00000008f4nuBB

I am having some issues. The below is a code snipet of my test class. The class complies and produces 96% of coverage with no errors. When deploying in production it throws the above error. ...
4
votes
2answers
50 views

System.VisualforceException: Invalid value for property label: null

Sigh. So I am required to cover my Apex code with tests. I'm testing a piece of code that dynamically builds a tree of controls with a PageBlock as the root object. This code works fine when NOT ...
2
votes
1answer
30 views

Speedup Testing with Force.com IDE using slim Logs - but how to set the log-level?

A lot has been written here about slow development in general and slow testing in particular e. g.: Slow development Faster unit tests? For my use case I found one reason for slow testing while ...
-1
votes
1answer
32 views

Apex Testing - Best Practices [closed]

A general question asked from time to time on stack exchange is how to implement tests. There are some general questions to ask: What are your testing best practices? Thanks for sharing your ...
1
vote
1answer
14 views

Production Test Execution “Could not run tests on class …”

While running my test cases within my prod environment, I noticed quite a few messages as the title describes, and I don't understand why. Do you have any insight on why this is happening? It seems to ...
1
vote
1answer
113 views

Can some help me get coverage for the below trigger?

Trigger: Trigger copyEquipmentonsite on Unit_Placements_Sales__c(after insert, after update) { List<Services__c> sub=new List<Services__c>(); for(Unit_Placements_Sales__c u : ...
1
vote
1answer
51 views

Unit Tests max number of test methods in a class?

I have many unit test methods (30+) in a test class that cover my class well - setting up data, setting the page and controller, calling methods and setting properties, doing asserts. But when I look ...
1
vote
1answer
47 views

Test for sendEmail() error

Hi I have built a class and a test and I am getting close to getting the test to work. I am trying to send an email using a template. But I am getting an error on the last line of code. Save ...
0
votes
2answers
80 views

How to call action function method in the test class

How do I call a method in my test class which is basically been called from the action function on the vf page? VF page: <button type="button" onclick="myJSMethod();">my button</button> ...
0
votes
1answer
25 views

Performing an Upsert in PageReferenceSave - Not updating Item.ID for Use In UnitTest

I have a test that creates a new record in our custom table - Service Offered. Whe I call my controller and save - It creates/updates the record correctly, and in my class the Debug.Assert gives me ...
3
votes
1answer
77 views

How to mock a SOQL query in Apex

Our Apex unit (true integration) test run takes about an hour to complete (260+ individual unit tests) and this really slows down our dev process as we are trying to adhere to Continuous ...
0
votes
0answers
50 views

Insert contact statement in test class is causing 0% code coverage

I've written a simple trigger to prevent duplication of a lead based on existing leads and contacts. My test has 90% code coverage based on the tests that I've written to prevent lead duplication. ...