Tagged Questions

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)

0
votes
1answer
17 views

Is there a way to initialize a custom setting in a test class?

My test class inserts test quote line items which sets off a trigger, that calls a Util class to pull a query of qli fields, 5 of which have their names stored in custom settings (I'm not 100% why ...
0
votes
1answer
22 views

page reference code coverage

suggest me how to cover page reference in test class. public PageReference selectedPricingReq(){ system.debug('-----> acceptedPRID: '+acceptedPRID); Pricing_Request__c prcReqObj = ...
1
vote
2answers
64 views

How do I test an apex trigger that sends an email

Trigger is: trigger emailtemplate on opportunity(after update) { List<opportunity> oList = Trigger.new; List<opportunity> nList = trigger.old; ...
0
votes
0answers
14 views

code coverage considering comments and debug statements

(Please dont mark it as duplicate).For one of my class, comments and debug statements are getting considered for code coverage. I cleared the test data/results but then also the comments and debug ...
11
votes
2answers
51 views

Test.loadData() - undocumented behavior

Premise I want to load Accounts and their related Contacts using Test.loadData() and StaticResources. How do I do this given that the Contact records must have the ID of their parent Account yet the ...
4
votes
2answers
36 views

How to generate a random string value based on regex pattern

I'm trying to build a random external ID generator that can take a complex pattern described in RegEx and generate any number of unique strings for unit tests. Ideally something like Xeger which ...
1
vote
3answers
23 views

MIXED_DML_EXCEPTION when creating PermissionSetAssignment in test class

I keep getting following exception when trying to assign permission set to a user in test class: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML ...
2
votes
1answer
21 views

JSON.createGenerator(true)

I am creating a JSON generator that returns the created object to be parsed in a different method. However when I am creating a field using the writeStringField method of JSON with a value of null, it ...
0
votes
1answer
48 views

Mock Unit Test for a REST API callout

After attending DF14 I have a fairly solid understanding of the HttpCalloutMock() when unit testing for REST callouts, but I'm having trouble implementing unit testing for the first time. The ...
6
votes
2answers
58 views

Best Design for an easily maintained Unit Test?

I'm attempting to design a Unit Test Utility that we can use across our 15++ UE Orgs. I'm aiming to accomplish the following goals: Reads from a declaratively-maintained map of required field/values ...
4
votes
1answer
158 views

How is the Test Code coverage required for deploying calculated?

Would like to Know- suppose we've sandbox from which we deploy to production. There is already set (A) of classes, some of whose test classes are failing Now we want to deploy Different set(B) of ...
5
votes
2answers
72 views

Test Class SeeAllData=true Annotation

I am creating a test class that will test my controller class which uses almost 5 to 8 objects that has many DML statements like insert and delete, however I am feeling a little bit worried about not ...
2
votes
1answer
19 views

Constructor not defined error when deploying to production

i'm getting a bit lost in the weeds with the error I'm getting when trying to deploy this simple test class to production. In the sandbox, it compiles fine and runs fine test-wise, but when it comes ...
0
votes
1answer
56 views

Please help me with below test coverage

I have below trigger. And i have one test class. Trigger is Covered 76%. i want to make it more than 90%. The code which is not covered is at line numbers : For Trigger 1 :14,17,25,26,27,32 For ...
3
votes
1answer
24 views

Tool for check valid test cases in Salesforce?

We have a existing project which has a number of invalid test cases - which means, test cases only have the code coverage but don't have system.assert in it. I remember there is a tool to find those ...
0
votes
2answers
37 views

Increase test coverage for query IsSandbox =true

I am checking for sandbox with help of query select Id from Organization where IsSandbox =true limit 1 but now in production and developer org my code coverage is going down to 33% as this query is ...
1
vote
3answers
37 views

Unit test for trigger SOQL query that is uncovered

I'm having an issue finishing up my unit test, and I think it is related to the SOQL query in my trigger. The trigger itself checks to see, upon Lead creation, if a Contact exists with a matching ...
0
votes
1answer
15 views

Test Class to cover NotesandAttachment

I am creating one test class to cover this query.The query is covered, I tested one value retrieved but it does not go into for(NoteAndAttachment h:actOpen.NotesAndAttachments) loop. List< ...
2
votes
0answers
47 views

No test coverage on after insert trigger

I can't quite tell why code coverage is saying that there are 0 lines covered. My objective is that every time an Award is inserted, an Award Judging Criterion is inserted with a link to the Award. ...
1
vote
3answers
104 views

Problem with System.assertequals in test class code

I have below trigger code : trigger updateopportunities on Account(after update) { Set<Id> accountIds = new Set<Id>(); for(Account ac : Trigger.new) { ...
2
votes
1answer
42 views

Cannot use @istest in Apex Triggers

I'm brand new to Apex/Salesforce development, and am attempting to create some Apex triggers and tests. Each time I try to add a new class, when I start it with @IsTest I am unable to save it. I see ...
1
vote
1answer
28 views

Help Creating a Test Class for a VF Controller

Apex newbie here and would really appreciate the help on a test class I'm trying to write. Basically, a VF page called "Invoice" is getting created when a button is pressed on the Quote object. The ...
2
votes
2answers
66 views

Test class Standard price book entry error STANDARD_PRICE_NOT_DEFINED

i got error in my test class. System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: [] my test ...
0
votes
0answers
31 views

System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped

we have written trigger for echo-sign object, after updating object through our trigger, echo-sign code calls @future method from their managed package. this future method has webservice callout. Our ...
0
votes
3answers
96 views

Apex test 3% code coverage,

Need Help! I have a test class GoogleMap_Meeting_Controller_Tester with 3 objects, location(master), groups(child) and meeting(grand child). The SOQL query is returning a rowthe Apex coverage is still ...
-3
votes
2answers
57 views

Help with Code coverage, Loop and if conditions

I'm unable to have code coverage. Wrote a test class that has 24% coverage. How should I test loops and conditional statements? Following is my Apex Class... public class OrderTrackingList{ ...
0
votes
1answer
54 views

Test class is not full coverage

Here is my apex class and Test class: Some of lines are not covered in the class, i'l mentioned -------- like this. Apex Class: public with sharing class TaskController { private ...
1
vote
1answer
33 views

Help with controller test class. First Attempt! [duplicate]

It's my first take on writing Test Class. Following is my Apex Class... public class OrderTrackingList{ public OrderTrackingList(ApexPages.StandardController controller) {} public ...
3
votes
1answer
40 views

How to achieve Test Coverage for Interface Classes

I am using the trigger framework presented here, which uses several interfaces and utility classes: ...
2
votes
2answers
31 views

System.JSONException in Salesforce Test Class

I got error in test in this condition. while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'periodName' )) { ...
1
vote
3answers
42 views

Write test class for webservice callout in apex class

I have one apex class in which I am calling one webservice of one of my managed package installed in my org. When I am writing the test class for my apex class, it is throwing the error callout ...
2
votes
1answer
28 views

How to create object by it's name?

I'm writing a REST service which calls external service. I want to write a test for my service. I came up with no possibility to mock this call as it's in managed package. I want to wrap this call ...
0
votes
1answer
27 views

Need Code Coverage for CRUD If Block, How can I achieve that?

Here is my Controller Code --- // creates a new Attachment__c record Attachment__c objAttach = new Attachment__c(); private Database.SaveResult saveCustomAttachment() { ...
2
votes
1answer
65 views

How does one test Visualforce components with custom controllers

I have created a custom Visualforce component. It is backed by a custom controller. I am struggling to write unit tests for it. The limited VisualForce documentation indicates that to test it I ...
-1
votes
1answer
71 views

How to write down test class for If else condition

Scenario: If First name or Email or both missing from existing contact then error message should be display. ................ Apex class controller if(contact.Id !=null && contact.Email != ...
2
votes
1answer
35 views

Unable to create ConnectApi test data

I'm stuck trying to write a test method for the ConnectApi. Specifically, I have a remote action that uses the ConnectApi.QuestionAndAnswers.getSuggestions() method, which returns related (Chatter) ...
7
votes
1answer
60 views

Unit testing complex workflows

I'm working on a project that entails refactor of a lot of complex workflow rules. I was wondering if anyone here writes unit test to test their workflow rules? Seems like it would be a good idea ...
2
votes
1answer
159 views

Which is more recommended, test classes or inline test functions?

So up until now every time I make an apex class, I make a separate class that tests that class (usually the same name with the suffix "TestClass"), which is what I've seen a lot of people do. However ...
0
votes
1answer
25 views

How to write unit tests for a post install script?

I'm trying to write a unit test for a post install script class, a class that implements InstallHandler interface. I'm testing two cases: 1- No previous version is defined, for that I just use this: ...
1
vote
1answer
54 views

code coverage for the test class

i have a batch class which i am scheduling for run. and i have a test class for the batch class. the batch class is working fine . but the code coverage is 44% . important note: when the batch ...
2
votes
1answer
33 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
92 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
64 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 ...
0
votes
3answers
63 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
157 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
66 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
81 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
53 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
70 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
37 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 ...