Questions tagged [unit-test]

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 tests is considered covered. At least 75% of an organization's codebase must be covered by unit tests and every trigger must have at least 1% unit test coverage.

Filter by
Sorted by
Tagged with
3 votes
1 answer
4k views

Test class for sending email with Attachment

I need a test class for sending a email public blob body; public PageReference pdfmethod(){ try { // to get mail id Opportunity_Potential__c opp= [Select ...
Binu Sfdc's user avatar
4 votes
2 answers
4k views

Test class / code coverage for insert trigger on update

Still new to all this, thank you in advance for your responses! I have the following trigger which inserts a custom object record on Campaign Member update: trigger ...
Robin Koehler's user avatar
0 votes
2 answers
397 views

How to write a test class? [closed]

I have a class i don't no how to write test class. This my test class method. Please help me. private static void decommAssets(Map<Id, Custom_Asset__c> assets, Map<Id, OpportunityLineItem&...
user5564's user avatar
1 vote
1 answer
4k views

Test method with query string

I have the following test method and keep getting: List has no rows for assignment to SObject. public static testMethod void TestChurchName() { PageReference pageRef = Page.ChurchHistoryDev; ...
Randy R's user avatar
  • 249
3 votes
1 answer
2k views

Class Test: 'Invalid id value for this SObject type,' How to reference id in test?

I'm writing a test for a Contact trigger that references a class. I get the error: "Invalid id value for this SObject type". Not exactly sure how to reference this. Thanks for any help. Kevin ...
Kevin Russell's user avatar
0 votes
1 answer
798 views

Test method not passing for duplicate trigger which checks for duplicate email (error : System.AssertException: Assertion Failed)

hi this is my trigger to test duplicate between two email address which is working fine and also it allows duplicate if the checkbox "allow_duplicate__c" is selected, but there is a problem with test ...
Sharat's user avatar
  • 1,029
6 votes
2 answers
427 views

Unit testing with callout conflicts with workflow rule

I am having a problem that I investigated down to this very simple minimalistic example that can be reproduced easily. 1) Create a workflow rule on the Account object that will send an email to the ...
Hugo's user avatar
  • 61
4 votes
1 answer
436 views

Unable to upload managed package due to incorrect test coverage

I'm trying to upload a beta version of a managed package I'm developing, but it fails saying the test coverage is only 74%. But when I estimate the test coverage I've 91% both from 'Apex Classes' and ...
BuddhiP's user avatar
  • 543
3 votes
1 answer
76 views

Test Class error

I have a test class, when i am excuting, getting the below error. System.DmlException: Update failed. First exception on row 0 with id a07J0000006hjjbIAA; first error: ...
user5564's user avatar
6 votes
1 answer
5k views

how to get test coverage for @future and http response method in class

Below is my apex class and trigger, that is used to send sms from 3rd party application and that is working fine, but i'm not getting test coverage for class. If i use @future method my apex class ...
Sharat's user avatar
  • 1,029
8 votes
1 answer
2k views

Unit Tests: create completed tasks for ActivityHistory?

In unit tests, is there a specific way of creating completed tasks so that they appear immediately in the ActivityHistory read-only object? (I have batch Apex that pulls data from ActivityHistory, ...
David Cheng's user avatar
  • 7,085
13 votes
1 answer
3k views

Clarification on Unit Testing a method that runs a SOSL query

I have a controller method that uses a SOSL query to generate a list of options. It works when used in the VF page, but the unit test is failing; logging shows the SOSL query is returning no results. ...
Jason Clark's user avatar
  • 11.9k
1 vote
1 answer
589 views

Test class for Trigger and web service class

This is my trigger, for sending SMS when account owner is changed trigger sms on Account (before insert,before update) { for(Account acc:trigger.new) { if(acc.Status__c=='Qualified' ...
Sharat's user avatar
  • 1,029
13 votes
4 answers
21k views

FIELD_CUSTOM_VALIDATION_EXCEPTION during Unit Test

I have a validation rule, such that setting a Case escalation status to "approved" can only be done via particular users and/or emails via the automated email parser. I have a Unit Test that accounts ...
Chris K's user avatar
  • 293
5 votes
3 answers
17k views

Test Class for a trigger failure: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

I have made a little trigger that updates record owner based on a parent(and another parent) record owner. The data model is: HR_Data__c < Clock_in_out_user__c < Clock_in_out_Date__c. The ...
dzh's user avatar
  • 4,106
0 votes
1 answer
93 views

I have problem with the assertion in testcase?

controller code: public with sharing class silogletter { public Contact contact {get;set;} public silogletter(ApexPages.StandardController controller) { for(contact record:[select Name, ...
Teja's user avatar
  • 1,422
2 votes
1 answer
3k views

Test class in salesforce of following wrapper controller

I created a controller which looks like this public class CustomAccountController { public Account acc{get;set;} private Id AccId{get;set;} public contactwrapper objconwrap{get;set;} ...
Vivek113's user avatar
  • 455
8 votes
1 answer
3k views

Static members and initializers in Test classes

If you have a test class with multiple test methods in it, and some static member along with a static initializer, then 1) Test methods will run in no particular order (i'm sure you knew this one ...
Kirill Yunussov's user avatar
9 votes
1 answer
9k views

Test class Rest Webservice parameters

I´m having problems with url parameters (req.requestURI) in my test class. This is my code. REST CLASS: @RestResource(urlMapping='/Accounts/*') global class StoreController { @HttpGet ...
Enry's user avatar
  • 3,726
3 votes
1 answer
244 views

My test classes are contributing towards uncovered code

I have a test class containing several WebServiceMock implementors. He looks like this: @isTest private class MyTestClass { public class ValidateMock implements WebServiceMock { public ...
Matt and Neil's user avatar
0 votes
1 answer
5k views

Test Class for batch apex scheduler

I have a problem in achieving 75% + code coverage for a test class which i have mentioned below please correct me where i'm going wrong. Now i'm getting 57% code coverage. Here is the apex scheduler ...
Sharat's user avatar
  • 1,029
5 votes
1 answer
15k views

how to complete 100% test coverage for scheduled apex class

I have created one scheduled class for weekly schedule and also created test class for it....now i done with test code coverage..but it only showing 50% of code coverage... what i am missing? Apex ...
sumit's user avatar
  • 479
2 votes
0 answers
763 views

Inserting a PersonAccount record using csv file in Testclass

i write a test class for the apex class which is based upon inserting the PersonAccount records.i try to insert a record using csv file in test class but i got a error at the time of ApexTestExecution....
Venkatsforce's user avatar
1 vote
7 answers
27k views

Test class for After insert/update Trigger

I have a trigger on Account object which will create an opportunity if the industry type is 'Electronics' and it's working fine but i have a problem with test class so please help out. Here is the ...
Sharat's user avatar
  • 1,029
1 vote
1 answer
1k views

Colloborationgroup-visibility-testclass execution

Is colloboration group,an object whose records are always visible even when testclass is executed. When i try to insert,say 95 records for chatter groups via testclass,it gave an exception saying ...
sfdc99999's user avatar
  • 3,585
10 votes
3 answers
8k views

How separation of Test Class can solve 101 SOQL Queries Limit Exceeded Error?

Recently one of my colleagues was trying to deploy to production some opportunity trigger activation, but during validation deployment two of ten test methods from TestMyMysteriousApexClass failed ...
Patlatus's user avatar
  • 16.8k
0 votes
1 answer
208 views

How to cover with tests a simple Apex Trigger

I am trying to cover with tests a very simple Apex trigger, but with no luck. 0% of code is covered. Here's the trigger: trigger AssignPricebookToOpportunity on Opportunity (before insert) { ...
justasd's user avatar
  • 1,463
-1 votes
2 answers
3k views

Problem with my test class: System.DmlException: FIELD_INTEGRITY_EXCEPTION

Yesterday i worked on my test class and its up to %79 code coverage only 16 lines not tested. And failures are here: Line 221. System.ListException: Missing id at index: 0 line 221 is delete(ordlist);...
user's user avatar
  • 39
1 vote
1 answer
2k views

what do you mean by System.assert(true) in apex testing?

We have a code like this --> NotificationsController notificationsController = new NotificationsController(); System.assert(true); notificationsController.ClickBtnBackToDB(); ...
Amit Agrawal's user avatar
11 votes
5 answers
6k views

How to perform mock testing on database queries?

In java , we perform mocking to test the database classes. Is there any way to test the classes in apex language & mocking also works in apex test cases. Now how will i perform these test cases ...
Amit Agrawal's user avatar
0 votes
1 answer
300 views

Test class 76 lines not tested,%0 covered. How i can fix it

My trigger working well.My problem on test class.Test class result is 76 lines not tested,%0 covered. How i can fix it. Pls help me. Here my trigger : trigger CreatingOrderLineItem on ...
user's user avatar
  • 39
6 votes
4 answers
10k views

Why is 75% code coverage required in Salesforce?

This might be a silly question, but I am new to Salesforce, so I am asking this question that why there is 75% code coverage concept is there in salesforce? What I know, in order to deploy or create ...
Noob_NoVoice's user avatar
  • 2,709
0 votes
1 answer
1k views

How to run multiple test scenarios in one test code, for the Same APEX code?

I have a previous question: How to achieve ~100% code coverage with if-then-else statements? I followed Peter Knolle advice and so far I have 90% coverage. I’m Just going through the code when I ...
user2333346's user avatar
  • 1,701
15 votes
8 answers
16k views

Code coverage on dev console

A quick question. We used to have a code coverage highlighted in dev console on which lines of the class are covered and not covered before. Has salesforce removed this option or do i need to ...
Prady's user avatar
  • 12.3k
1 vote
1 answer
1k views

Help with Apex Test Class I have Written

I have a trigger and I have also written a test class to test the trigger but only 20% of the trigger code is covered leaving 134 lines uncovered. My overall coverage is 60% and I'm trying to increase ...
user4675's user avatar
  • 233
2 votes
1 answer
73 views

Discovery tests failing on very simple scenarios

Let me preface this by saying that I am very unfamiliar with Salesforce. I have written a set of small discovery type tests to try and feel my way through the syntax and how things work, but I am ...
Joe's user avatar
  • 155
0 votes
1 answer
3k views

My test case is not detecting account team member?

trigger AccountTeam on Account (after insert) { Integer newcnt = 0; Integer newcnt0 = 0; AccountTeamMember[] newmembers = new AccountTeamMember[]{}; //list of new team members to add ...
Teja's user avatar
  • 1,422
0 votes
1 answer
2k views

Test class error while insert a record

I'm trying to insert a record under Account using test class as follows List< Account> c = new List <Account>(NameLocal='test44',Name='testprimary',Industry='Aerospace'); insert c; Error:...
Sindoora's user avatar
  • 735
1 vote
1 answer
177 views

How to write a Test method

Someone plz help me how to write test method for below method public static Integer getFolderIndex(String frup_folderName, String recordName){ Integer folderIndex = 0; if ( !frup_folderName....
Noob_NoVoice's user avatar
  • 2,709
1 vote
3 answers
354 views

Ebook or Website or Video Tutorials for learning Application Express (APEX) Unit Testing? [closed]

Will anyone tell me ebook or website for learning Apex Unit Testing ?
Amit Agrawal's user avatar
3 votes
2 answers
10k views

How to set the Controller Id for the test code?

I have the following class public with sharing class templicenseemail { private ApexPages.standardController standardController; public Trainee__c trainee { get; set; } public ...
user2333346's user avatar
  • 1,701
0 votes
2 answers
1k views

How can I fix this Compiler error?

I'm getting a compiler error for this test: @isTest public class TestDirectMailFilter { public static testMethod void testMyController() { Campaign c = new Campaign(); c.Name = 'Jacob for president'...
Jacob's user avatar
  • 3
3 votes
1 answer
8k views

Constructor not defined Error for test case

I have an error that seems common on the web, Though i cant find a definite answer that applies to my case: I have the following Apex code: public with sharing class templicenseemail { private ...
user2333346's user avatar
  • 1,701
1 vote
1 answer
708 views

Test Class is not working for contacts [closed]

I wrote a test class for below webservice but it **showing an contacts does not exist in test class may i know what is the problem, how to declare that contacts in test class global class ...
Sathya's user avatar
  • 1,203
6 votes
2 answers
13k views

How to assert a PageReference in Test Method for Visualforce Controller

Given the following test class, how do I assert that the PageReference is returning as intended? Test method: static testmethod testMyMethod(){ campaignmanageclass obj=new campaignmanageclass(); ...
bhagyashri chaudhari's user avatar
1 vote
1 answer
114 views

Help Code Coverage - Class Implements

I create multiple (x5) classes in my Trigger like this : class TypeHandler_XX implements TypeHandler { public void action(Task record) { /* Block code */ } } In the code that I ...
Simon Gazin's user avatar
6 votes
1 answer
13k views

Test class for REST Api

@HttpPost global static Map <String,String> doPost(String firstName, String lastName, String phone, String email) { Lead lead = new Lead(); Map <String,String> sta = new Map &...
bhagyashri chaudhari's user avatar
-8 votes
2 answers
668 views

Test Class For Trigger [closed]

I develop a trigger May i know how to write a test class for below trigger trigger insertMember2 on Account (after update){ List<Quote> QuoteList = new List<Quote>(); if(Trigger....
Sathya's user avatar
  • 1,203
7 votes
1 answer
10k views

How to achieve ~100% code coverage with if-then-else statements?

I have an apex code as follows: public with sharing class Account_Test { public String USerDate1 { get; set; } public List<Lead> ui{get;set;} public integer i; public List<...
user2333346's user avatar
  • 1,701
1 vote
2 answers
1k views

failure message system.dmlexception insert failed

//this is my before insert trigger public with sharing class Account_Amount { public Account_Amount(){} public void calAmmount(List<Account> accList){ AccountDiscount__c mc = ...
bhagyashri chaudhari's user avatar

1
86 87
88
89 90
95