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
0
votes
1answer
14 views

Declarative Rollup Summary - error

I want to create a Declarative Rollup Summary , but I hit the following error : dlrs_pse_AssignmentTest.testTrigger System.DmlException: Insert failed. First exception on row 0; first error: ...
0
votes
0answers
3 views

How to create a DataCategory & DataCategoryGroup record for Apex test class?

I am trying to create a Knowledge__DataCategorySelection record but am missing DataCategoryGroupName value. I am unable to create a DataCategoryGroup record as it is an invalid type. ...
2
votes
2answers
76 views

How do you know what to include in a test class for any given trigger?

I've had a fairly simple run in writing test classes, but am not sure if I'm doing it right or adhering to best practices. Below you'll find one of my triggers and its corresponding test class (100% ...
0
votes
1answer
19 views

Trigger on ContentDocumentLink gets fired for current user in test class

I am trying to increase test coverage of an after-trigger on ContentDocumentLink. The problem is that the trigger gets fired twice. I found out from this answer that the trigger fires one extra time ...
0
votes
1answer
43 views

Developing A Test Class [duplicate]

I've written Apex classes but this is my first time written a test class. I've read a number of sources and watch videos but I don't grasp the foundation to get a test to successfully cover my code. ...
0
votes
0answers
17 views

automatically associate a contact created in their salesforce instance with the respective account based on the email domain [closed]

ABC containers require the ability to automatically associate a contact created in their salesforce instance with the respective account based on the email domain specified in the primary email ...
0
votes
2answers
18 views

test class error : Method does not exist or incorrect signature

public class MyController { @AuraEnabled public static Account getAccount(String accId){ Account acc = [SELECT Id,Name FROM Account WHERE Id =: accId]; return acc; } } @...
0
votes
0answers
32 views

How to test code coverage for Unlocked Packages when data cannot be inserted?

I am running into an issue related to SFDX packaging and was hoping you could help me. To provide some context: I am using the ServiceChannel object for some tests related to PendingServiceRouting, ...
0
votes
1answer
30 views

System.UnexpectedException: Start did not return a valid iterable object

I am trying to write a test method for my batch class so I can deploy it, but I am getting this error. System.UnexpectedException: Start did not return a valid iterable object. The batch class looks ...
0
votes
1answer
24 views

Code Coverage Failure Your code coverage is 73%. You need at least 75% coverage to complete this deployment [duplicate]

I did run all tests in my sandbox and also tried to run them each individually - the overall avg code coverage is around 88%. However, when i try to validate my change set in prod, it is throwing an ...
0
votes
0answers
16 views

ContentFolderMember doesn't exist in unit test

This is a part of my test function: ContentWorkspace cw = [ SELECT Id, Name FROM ContentWorkspace WHERE NAME = 'Workspace' ]; // Create document ContentDocument doc = doc_TestData('Test', 'pdf'...
0
votes
0answers
19 views

Help with Test class for After Insert Trigger [duplicate]

I am new to Apex. So not much aware about the coding experiences. My requirement is as below We have a third party user bringing us the leads. This third party integration only will insert the leads. ...
3
votes
2answers
79 views

Custom Setting proxy class, how to make its operation transparent outside of tests?

It's been fairly well established1, 2 that inserting/updating custom settings in a unit test hurts several aspects of the test: Makes tests take longer to execute Makes it hard to run tests in ...
0
votes
0answers
12 views

MilestoneUtils - setup CaseMilestone in test class

I am am attempting to use the class from this help article but the test included did not provide full coverage (commented below) of the MilestoneUtils Class. https://help.salesforce.com/articleView?id=...
0
votes
1answer
23 views

Can someone help me with this one ? Why I am getting Output Twice

This is how my trigger looks: trigger problem5 on Contact (after update) { if(Trigger.isAfter) { id currentID ; if(Trigger.isupdate) { double ...
0
votes
1answer
37 views

SFDX Test Coverage Calculation process is flawed and unusable

In my org we have several custom profiles, including community profiles. My sfdx project is structured in a way that the profiles are included in the file repository, but are not included when the ...
0
votes
1answer
24 views

System.AssertException: Assertion Failed: Expected: true, Actual: false ? True is expected

I am testing my piece of trigger trigger problemOne on Account (before insert , after insert , before update) { if(Trigger.isBefore) { //If new record is created : if(Trigger....
0
votes
0answers
26 views

How to write test class that retrieves the account history data? [duplicate]

I am using an apex class(HistoryManager) which has a method getHistoryRecords that takes 2 parameters namely a soql query(String) and a recordId(String) and calling it in the connectedCallBack() ...
3
votes
2answers
125 views

How to rollback DML after catching exception in unit test

I have a custom business logic that will block certain profiles from editing/creating/deleting an account. Because of other requirements, mainly around Record Types, I can't use profiles and ...
1
vote
0answers
31 views

How can Product2.StockKeepingUnit already exist in a test? [duplicate]

I'm trying to create some Apex tests. Of course I am NOT using SeeAllData=true. When I try to insert some instances of Product2, even though I've inserted none before, I get: System.DmlException: ...
0
votes
0answers
12 views

Is there any way to find when a System fields was published?

Use Case I would like to write a test to ensure a permissionset grants read permissions on all of fields. I've got that working just fine, but as managed packages update and the platform itself ...
0
votes
0answers
22 views

first error: INVALID_CROSS_REFERENCE_KEY, Entity not available: [PricebookEntryId]

When I am trying to run my test class I am getting the below error. System.DmlException: Update failed. First exception on row 0 with id 8023B000000ekyaQAA; first error: INVALID_CROSS_REFERENCE_KEY, ...
0
votes
0answers
20 views

Test Class for system.runas(user) not working for UserInfo.getUserId Coverage

Im stuck at 52% coverage of a vf controller that queries and displays timecards__c records of UserInfo.getUserId in a table. What is basically not getting covered is the if else statements after the ...
0
votes
1answer
29 views

Apex Class on ContentDocumentLink

I'll start off by saying that I am in no way a Developer, and the code I am posting is from things I have found online and recycled for my use-case. It's working, but I know it's not structured ...
0
votes
1answer
40 views

Trying to create a test class for Httpcallout but getting error Illegal assignment from void to System.HttpResponse

Could you please help me with this test class? I am using Genderized API to populate the custom filed on Lead name gender (Gender__C). API Link - https://api.genderize.io/?name=peter Get_Gender_Lead -...
0
votes
2answers
25 views

i'm trying to write test apex but it gives me this error Illegal assignment from List<RL_Service_Detail__c> to Boolean

@AuraEnabled public static List<RL_Service_Detail__c> deleteContact(String conid) { if(conid != null){ RL_Service_Detail__c delContact = [Select Id from ...
2
votes
2answers
34 views

Any way to dynamically set the Relationship on an Object?

I am writing a test class for my code and am running into an issue that is annoying me. So I was wondering if there is any way to do this. I have an Apex class with some functionality that I am Unit ...
1
vote
1answer
28 views

INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Error When Running Test Class

I've been trying to run my test class via Visual Studio Code, but I get the following error message: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Deployment to org is ...
0
votes
1answer
24 views

How to set checkbox for unit testing, but it is inside a wrapper class?

I have an apex class that steps a user through a visualforce page. They select a product family and then are presented with a list of products. They can then select one or more of these, via a ...
1
vote
2answers
64 views

System.runAs not working if system user not selected

I created a very simple method on a before insert trigger, that adds the number 11 to a value if a regular user creates a record, But it doesn't add anything if the service user creates it. So for ...
0
votes
1answer
31 views

INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call While testing my Apex Trigger

I am new to salesforce, and I am getting an error : INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call I am trying to test my Trigger My Trigger trigger invoiceTrigger on ...
0
votes
1answer
23 views

Test apex class salesforce coverage code

i have a test class for salesforce @IsTest public class JsonGCloudApiApex_TEST { // This test method should give 100% coveragex static testMethod void testParse() { ...
0
votes
0answers
24 views

Keeping a ViewAllData permissionset viewing all fields

I have a permissionset which I want to grant broad read-only access to nearly all fields and objects. I've granted the permissionset the ViewAllData permission already, but that permission does not ...
3
votes
1answer
47 views

Impossible to test Task created from Messaging.sendEmail?

I have added some fields for Compliance to EmailMessage and Campaign objects. When a list email is sent, a batch job finds the tasks and copies those fields from the campaign related to the list email....
0
votes
1answer
21 views

How to call rest api from test class?

I have written a rest api class and working test class coverage. While calling the api class from the test class, i am facing the below error. Error: Compile Error: Method does not exist or incorrect ...
0
votes
1answer
29 views

Update Records from CSV TestClass [duplicate]

I'm running into an issue where my code coverage is lower than I'd like. I've hit a wall where the lines of the controller in the image below are not covered. I'm not sure how to get those lines to ...
0
votes
0answers
34 views

Please Tell me where i am wrong in this Trigger

emphasized textPlease Tell me where i am wrong Requirement Details: Account should have two fields of type text area Current Issues(Products), Past Issues(Products) Keep count of total issues/Cases ...
0
votes
1answer
43 views

List index out of bound while testing [closed]

Would like to seek for assistance, already debug my code but still error :( @isTest static void fetch() { system.runAs(new User(Id = UserInfo.getUserId())){ Account testAcc = new ...
0
votes
1answer
32 views

Issue while parsing JSON in Test Class

Below is my test method: static testMethod void callbackdateTomorrow() { Date currentDate; CurrentDate = date.today(); System.RestContext.request = new RestRequest(); ...
1
vote
0answers
21 views

How can I find out what “uncommitted work” is allegedly pending?

I have two schedulable batch processes, identical in every way except one is for Opportunity and the other is for Appointment__c. In real life, both batch processes work exactly as expected, which is ...
1
vote
1answer
18 views

Im getting “no viable alternative at character '&quot;'” while executing apex class for batch class

I have Created a Batch and test class for code coverage. However Im getting the following error message while executing the test apex. "no viable alternative at character '"'" Batch ...
0
votes
2answers
33 views

Custom Controller Test Class Coverage

I have a custom controller for a VF page that allows users to add and remove rows of records to create before they are actually created. My test class covers the addition of rows, but it does not ...
0
votes
2answers
37 views

how can i leave a field without value if the condiction is true?

for(Account acc : lstAc){ Account acount = new Account(); if (acc.Property_Managment_Company__c == 'Independent') { acount.ParentId = THIS FIELD SHOULD BE EMPTY. }...
0
votes
2answers
102 views

What are three ways for a developer to execute tests in an Org?

What are three ways for a developer to execute tests in an Org from the following options ? Bulk API Tooling API Setup Menu SalesforceDX MetaData API In my opinion, it should be Tooling API, Setup ...
0
votes
1answer
35 views

Create a test class for RestResource class with a response code

I have a @RestResource class which receives data from a third party, finds the matching record and updates it, then returns a success/fail to the third party. I've just added the RestContext.response ...
0
votes
0answers
16 views

my batch brings records and identifies if they're acc or cont for a particular field. How do I test it?

@isTest public class ALN_Integration_BatchTest { public static testMethod void metodoTest(){ ALN_Integration__c rec = new ALN_Integration__c(); rec.First_Name__c = '...
0
votes
0answers
24 views

Apex test class code coverage issue [duplicate]

Iam having trouble with a code coverage issue in one of my apex class code coverage please find the code below. Apex class: public class Executeapex { public static void executethismethod(){ ...
0
votes
0answers
23 views

Mock Selector in fflib

I am new to fflib, currently I am struggling with tests. Maybe there is someone who can help me :) public class someclass{ SEL_Contact contactSel = SEL_Contact.newInstance(); public ...
0
votes
1answer
21 views

i'm testing a batch. In the last block i have to verify that the list is not empty and the name equal to 'Kinder'. How can I do that?

@isTest public class QWE_Integration_BatchTest { public static testMethod void metodoTest(){ QWE_Integration__c rec = new QWE_Integration__c(); rec.First_Name__c = '...
0
votes
0answers
20 views

How to mock responses when the callout is being made in a dependent class?Question [duplicate]

I have a WrapperClass which calls HelperClass.doSomething(). doSomething() makes two callouts: callout1, do something, callout2, do another thing, return. I want to write tests for WrapperClass. Is it ...

1
2 3 4 5
82