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)

9
votes
1answer
57 views

Comparison fails when converting Opportunity from/to JSON

I am facing an issue when converting an Opportunity to and then from JSON. If I put that in a test, the assertion fails when comparing both Opportunities. Here is my code: Test case: static ...
-3
votes
1answer
21 views

unable to increase code coverage for getter and setter methods in test class

I am unable to increase code coverage for getter and setter methods in test class. Please some one suggest how to increase code coverage for it. I am having code: get{ lstAcct = ...
2
votes
1answer
27 views

Writing a test class for multi-callout method using MockHttpResponseGenerator

I have a future method which sends out two callouts. It looks something like this @future(callout = true) static webservice void SendCRMLeadFromTrigger(string leadID){ //FIRST CALLOUT ...
1
vote
0answers
25 views

Please Help me writing Test class for below given Apex Class [duplicate]

No compulsory Fields in Attendance object, public class showAttendance { public List<WrapperAttendance> PastAttendance { get; set; } public List<Attendance__c> PastList {get;set;} ...
1
vote
1answer
21 views

CaseHistory is not created

I am writing an Apex test for a trigger that fires when creating or updating cases. Per the Salesforce documentation, CaseHistory objects are created automatically when updating Case objects: ...
2
votes
3answers
44 views

Required field missing error in test case

I'm writing a test case. When I save I get the following error message: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are ...
5
votes
1answer
39 views

System.StringException: Invalid Id:

I have the following private method in my controller :: @TestVisible private DSLogin__c createBlankLoginInfo() { DSLogin__c obj = new DSLogin__c(); obj.Name = getSalesforceName(); ...
0
votes
0answers
28 views

Data displaying in Overall Code Coverage section in developer console is not consistent

The data displaying in Overall Code Coverage section in developer console is not consistent, but displays incorrect code coverage sometimes 100% and sometimes with lesser number. For example, ...
1
vote
2answers
27 views

Testing webservicemock never reached the response line in the generated class. why?

written a test class to test the callout that is using SOAP. I have generated class using WSDL. The response line in the generated class not covered though i tried several ways. Given below is the ...
5
votes
2answers
150 views

JSON.serialize is mucking with my datetime objects. How do I fix this?

I feel that the following assertion should be true, but it is not: DateTime testDate = DateTime.now(); System.assertEquals('"' + testDate.format('yyyy-MM-dd\'T\'hh:mm:ss.SSS\'Z\'' + '"'), ...
4
votes
2answers
44 views

Method defined as testMethod do not support web service callouts, test skipped

I have been struggling with this error for a few days now. I get this error every time I try to run a test for a method that has an httpCallout. I followed the architecture from ...
5
votes
2answers
26 views

Is there a way to set SystemModstamp on a newly created SObject in a unit test?

I need to create a SObject in a unit test with the SystemModstamp set. I've been using Opportunities in my unit test, but I am not tied to that specific SObject. I also am not tied down to ...
0
votes
3answers
98 views

How to include inner class/wrapper class in test method?

I am new to Salesforce. I have written a Apex class, where I've used an inner class ( PageSection) and I am creating a list of that innerclass and using in VF as a merge variable. My question is how ...
3
votes
1answer
70 views

Auto population of field in trigger

I'm trying to Auto populate Transportation_Zone__c depending on my Country__c. So if my Country__c (which is a text field) == "US", then the Transportation_Zone__c must be auto populated to "USA". ...
3
votes
2answers
122 views

Ways for the test to check the apex code is doing the right thing

One of the things I'm trying to do in my apex tests is to check that my code is doing the right thing internally, even if it returns the right result, e.g. Is it generating the right dynamic SOQL? ...
1
vote
3answers
74 views

Test class: Assertion Failed

I m trying to cover and test my apex code so I developped a test class to test my insertion, my the test is failed unfortulately; and gave me this error: Assertion error here is my test class: ...
1
vote
1answer
51 views

Inconsistent Test Code Coverage

I have a whole slew of testMethods in an AccountTriggerHandlerTest class. When I run the class as a whole, I get about 60% coverage, and it shows me that I'm missing one of my trigger methods. ...
0
votes
1answer
61 views

APEX unit test for lead trigger error : “Invalid field subject for Sobject Lead”

I have an error message for a test class that i try to create for 2 triggers. The error message is: "Invalid field subject for Sobject Lead" . Can anyone look at this and tell me what i do wrong , ...
2
votes
3answers
56 views

Need help calling a URL with parameters and parsing the results in a Unit Test

So, I have a class that is called by a URL and based on the information provided in the parameters, it runs it through a query and returns results as XML in a VisualForce page. Here's the Class: ...
4
votes
0answers
51 views

Field not accessible within runAs() method in Test class

I am checking for field accessibility of an User u whose Profile is p in apex Test class.To this profile field level security is set to Hidden for the field team_name__c.When I run as this user using ...
0
votes
1answer
37 views

Trigger Test Method stuck at 18% coverage

I've been working on this all night, so this post is my last resort. I have a trigger that creates a Chatter post when an Opportunity is "Closed Won," giving details of the sale. I thought I had ...
0
votes
1answer
99 views

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: execution of AfterInsert

The following is my test class, and I am getting the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PriceBookEntryUpdate: execution of AfterInsert on PriceBookEntryUpdate. How do I deal with another ...
5
votes
3answers
381 views

Can we use try catch inside a test class? Is that a best practice?

Though i have not tried a test class with try catch blocks of code, i often saw people wrote try catch block inside a test class. I need expert advise as doing so is a best practice or conventional. ...
0
votes
1answer
54 views

Auto population Trigger test class help

I have a requirement to Auto populate a field in my Sample__c object from my Product object whenever there is an Application Engineer name present. I started off thinking I could do a formula but ...
3
votes
2answers
146 views

Record ID: cannot specify Id in an insert call — clarification

So recently I got that error "Record ID: cannot specify Id in an insert call", and after doing some research I fixed it by. try{ insert p; ...
2
votes
1answer
22 views

Error while running a test class to add a partner to a user group

This is the test class I have Written and every time I run the test I get the following error: Class addPartnerUsersToGroupTest Method Name TestaddPartnerUsersToGroup Pass/Fail ...
0
votes
1answer
41 views

Creating a test class

Recently I wrote a trigger to auto populate Sampling_c off of my User Table which looks at RSM_c of the current user. And I can't logically think of how to create a trigger of a "artificial user". ...
1
vote
2answers
66 views

Apex test is slow during deployment, but fast any other time

I have a test that takes about 5 minutes to run during production deployment. If you just click "run test" or run it from execute anonymous, it's not slow at all (a few seconds). Is there a way to ...
-2
votes
3answers
62 views

Using private apex methods in a test? [closed]

I am a newbie in salesforce. I have a helper class which contains private methods. When i try to cal the methods they are not being called and my code is not getting covered. Please help me out. ...
1
vote
1answer
45 views

Make Test Class Specific to Scheduled Apex

I was wondering if there is a way to make a Test class only run for the Apex Class it's made for. Every time I want to import new classes or triggers, I have to turn off all of my scheduled Apex, then ...
0
votes
3answers
26 views

How to add a picklist value to Type__c of a Contact in a unit test?

I am trying to test a method in a services class in my org. Within my TestDataUtility class I have a List<Contact> createContact however, there is no Type field in this test data. I am not sure ...
0
votes
2answers
46 views

Help need for the coverage?

test case: @istest public class testcustomreport{ static testMethod void myUnitTest(){ list<batch__c> b=new list<batch__c>(); batch__c ba=new batch__c(); insert ...
1
vote
1answer
36 views

How to write a private inner class

I am trying to create a private DataUtility class within my test class. I need it to create a list of contacts within this private class. I am aware that I can create another class within my org but I ...
2
votes
1answer
50 views

How do I test cover simple JSON creation in a trigger?

I have an contact after trigger which collects data from Contact, add some personal, authentication pairs, and updates a 3rd party system. While the insertion of account/contact in the test class is ...
1
vote
1answer
68 views

Formula field not populating in Test class record - querying record doesn't work!

I have a custom object with a formula field that references a couple other fields on the object. The class I've written my test class for requires the formula field, which it uses in a SOQL query. ...
1
vote
1answer
59 views

Help understanding test classes for triggers

I'm a total newb when it comes to salesforce and have been learning it for a couple of weeks now. So I've been plugging away at a few triggers and I've got them working in my sandbox. Now I'm writing ...
0
votes
1answer
70 views

How can I test single email message code in a trigger?

I have a trigger to send an email alert. I am trying to test the single email message portion of my trigger; however, I am receiving an error. Any help on testing the actual email portion of the ...
2
votes
2answers
152 views

Test class failing for simple default lookup value trigger

I'm having trouble with what should be a simple test class for a simple trigger. The trigger inserts the ID of an account named Retail into a lookup field on the opportunity named Project__c if that ...
3
votes
3answers
92 views

Code Coverage report for all classes

Winter 14 release removed Code Coverage column from list of class and triggers. Did anyone found any (nice) workaround to check Code Coverage of ALL classes?
1
vote
2answers
67 views

Not covering the code coverage from following test case?

public with sharing class ChangePasswordController { public String oldPassword {get; set;} public String newPassword {get; set;} public String verifyNewPassword {get; set;} ...
-4
votes
1answer
50 views

Test Class Showing an error

When i implemented the test class for webservice it showing an error is Compile Error: Invalid type: AccountWrapper.Contacts in my test class My Class webservice String accName; webservice ...
0
votes
1answer
53 views

how to test the batch code?

How to write test class for this code 75% coverage or not? global class SearchAndUpdate implements Database.Batchable<sObject>,Schedulable { global final String Query; public ...
1
vote
1answer
52 views

Test.loadData() static resource text/csv vs. text/comma-separated-values

I am trying load a csv of User data for an Apex test from a static resource using Test.loadData(). When I upload the csv as a static resource, Salesforce gives is a MIME type of ...
0
votes
1answer
37 views

How to test a method within a class

I am fairly new to both unit testing and apex. I am trying to test a method within a class, but i keep getting an error which tells me method does not exist. I have a feeling that perhaps my syntax is ...
-1
votes
2answers
72 views

Need help with extension test class

I need some major help writing a test class for my extension. I've work half the day with no luck. There's no use in posting what I've got as it isn't working. This is my first extension class. Any ...
-1
votes
1answer
122 views

DML Exception Insert failed.

This is somewhat of a re-post, but I have additional questions. Some quick background of what I'm trying to do.. The following is my Apex Trigger. It is a validation Trigger on Sampling_c which ...
1
vote
2answers
124 views

How can i increase my code coverage in test class [closed]

How can i increase my code coverage in test class?? I am new to salesforce i am now trying to write some test classes please any one help me out by telling few tips/steps to increase code coverage
0
votes
1answer
41 views

How to cover this part in test class

Apex Class: public PageReference Save() { service.Asset_Name__c =assetname; insert service; Task T = new Task(); T.WhatId=assetname; T.WhoId=service.Employee__c; ...
5
votes
3answers
253 views

Apex test class for schedulable class that checks for 5 batches running already

I've setup some chain execution batch classes. For this setup we decided to chain the batch classes through schedulable classes. We thought it might be a good idea to include a check for 5 batch ...
1
vote
4answers
64 views

Test class and Validation

So after wrote my trigger and test class I start to think more in depth about how the test class and trigger talk to each other, and I begin to wonder is my trigger really working properly or did I ...