Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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 ...

-2
votes
0answers
14 views

Need Help in Writing Unit Test Class

//Could any of you kindly help me with the test class of below Class global class LicenseBasedRouting{ public static ServiceChannel channel; @InvocableMethod public static void ...
0
votes
1answer
18 views

SysAdmin Cannot delete EventRelation in Unit Test?

I have a unit test that creates an Event (in the future) and some EventRelations (for Contacts, with isInvitee=True), and then later deletes 1 of the EventRelations, via runAs(SysAdmin). Pretty sure ...
0
votes
1answer
22 views

Methods defined as TestMethod do not support Web service callouts - Unit Test

We have a custom object called 'support' - we have process builder configured for this object. in one of the process builder action it will invoke Apex (Invocable Method). This will trigger a callout ...
-3
votes
0answers
18 views

How to cover JsonGenerator in a test class?

A similar question was already posted here, but the accepted answer didn't really address the issue. Everything on my code is covered by the test class except for the JsonGenerator rows, how can it ...
-1
votes
1answer
20 views

Test Class/Method for TriggerHandler - Negative scenario

For this class below, which essentially counts the number of Open cases on an Account, on update/insert/delete of a Case, can anyone help me write/provide a scenario of a test method that can hit the ...
-1
votes
1answer
34 views

Need help with a Test class coverage

Hello guys i need help to cover this Trigger on a Test Class, this Test Class also covers another class so some Data is not refering to the Trigger. This is the Test Class: @isTest private class ...
0
votes
0answers
22 views

INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST

while writing a test class i am getting this error System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Resource Type: bad value for ...
0
votes
1answer
25 views

How to use if(!Test.isRunningTest()){} for a specific test

I have a class with a callout and a unittest mock for the callout. The callout has a scheduler. If I create a unittest for the scheduler the scheduler tries to do a callout If i use if(!Test....
0
votes
2answers
21 views

How to write a unittest for scheduled apex

I have a scheduler for a callout class. I am trying to write a unittest for my scheduler but do not know how to test the execute part Class global class or_guestsSchedulable implements Schedulable{ ...
2
votes
2answers
20 views

Test a schedulable class with callout by directly invoking `execute`

I have a Schedulable class. My execute method has a future callout in it, and running it by using System.schedule doesn't run that callout: Test.startTest(); MySchedulableClass msc = new ...
0
votes
1answer
30 views

How to code coverage for aggregate for loop?

public class WCT_CountryrealignUpdate2{ @InvocableMethod public static void NewcountyUpdate2(List<id> countyIds1){ Boolean t; List<New_country__c> ...
1
vote
1answer
24 views

PageReference.getURL() returning URL:[delegate:{MY RELATIVE URL}]

Im am trying to get the URL of one of my PageReferences whenever i call its method to return it to me i get this result URL:[delegate:{MY RELATIVE URL}]. Anyone know if why it's returning this, Please ...
0
votes
1answer
21 views

How to test 'throw new MyException()' in HttpResponse Callout?

I always get an Fail when try to test the negative scenario. How can I fix it? Sorry, I'm just learning. Callout: public class MyException extends Exception {} public class Token{ public String ...
0
votes
1answer
12 views

Illegal assignment from List<or_guestsJSON> to or_guestsJSON

I an trying to write a testclass for a JSON object but het the error: Illegal assignment from List to or_guestsJSON. How do I annotate the list in my testclass? Class public class or_guestsJSON ...
-2
votes
0answers
23 views

Test class is not working for error page message [closed]

controller method: public pageReference submitForApproval() { try{ if(CompetencyRecord.Employee_Name__r.Investment_Approved_Person_CF_30__c == true){ tab5error = false; ...
0
votes
1answer
20 views

How to generate Test data for KnowledgeArticleVoteStat object? [closed]

I've created the KnowledgeArticle record and a record for Vote by passing ParentId and Type ='Up' but how can I get the record for KnowledgeArticleVoteStat? Any sooner help will be appreciated.
0
votes
1answer
24 views

How can I test my Web Token and posted record from Post Callout?

I try to use HttpCalloutMock to test my post callout. But I become System.NullPointerException: Attempt to de-reference a null object. I need to test and web token, and posted object. I'm just ...
1
vote
1answer
39 views

deployment using change set- run specified test

Hi i have a changeset which has 2 apex class and their test classes with 65% and 80% individually test coverage, if i choose a option of run specified test, will that be deployed? Because one of apex ...
-1
votes
1answer
26 views

How to fix Attempt to de-reference a null object in test for Post Callout?

I become an error System.NullPointerException: Attempt to de-reference a null object in my test: public class Token{ public String accessToken{get;set;} } public static String accessTokenBody(){ ...
1
vote
1answer
19 views

How can I test Post Callout with web token's access? HttpCalloutMock

My POST Method (data for web token - is my custom object's fields): public class Token{ public String accessToken{get;set;} } public static String accessTokenBody(){ //our web token (data is in ...
1
vote
1answer
16 views

How to set the variables of invocable method in unit test

I have an invocable method with varables. I am stuck how to set these in unittest Class public class or_service { public class invoceVars{ @InvocableVariable public id ...
-1
votes
1answer
22 views

How to write test class with invocable with multiple variable [closed]

I am looking at the solution on how to call the invocable method with different data points How invocable method and bulk behavior in Process Builder work? I am calling this invocable method from ...
0
votes
1answer
26 views

How to test access token for HTTP callouts?

I have an access token for my HTTP callouts. How can I test it if I wanna use Static Resource? But I can also use the HttpCalloutMock Interface. it doesn't matter My access token is in custom object. ...
1
vote
1answer
10 views

Method does not exist or incorrect signature: void parse(String) from the type or_propertyJSONTest

I am new to apex callouts and trying to do some JSON parsing. I used the online tool https://www.adminbooster.com/tool/json2apex which worked great. I got a class and a testclass from the ...
1
vote
1answer
32 views

How can I test Callouts with HttpCalloutMock?

How can I test this method? I try the test code from trailhead but can't make any coverage. Callout: public class Token{ public String accessToken{get;set;} } public static HttpResponse ...
2
votes
1answer
13 views

Receiving error “Org cache is only supported in Data Silo tests”

I've implemented platform cache, I'm running a test and i received the following error: caused by: cache.Org.OrgCacheException: Failed Cache.Org.contains() for key 'timeZones': Org cache is only ...
0
votes
0answers
15 views

@HttpDelete: how to change SOQL filter from Id to the custom External_id?

We have an example from trailhead. But how can we change Id =: recordId to the External_id =: recordId in SOQL? I think we also change the logic of our code, because if just change it - Http-service ...
0
votes
1answer
33 views

'Last Viewed By' Account field test - System.QueryException: unexpected token: 'null'

Trying to create a Last Viewed By field on Account. I'm newbish at Apex and not seeing what I'm missing here... I'm sure it's a rookie mistake. Adapting code from http://www.sfdcpanther.com/setting-up-...
0
votes
1answer
18 views

Correct HttpPatch and correct test for it

I need to update a right record with ExternalID = Id of inserted record. And I try to check this field (ExternalID) in SOQL, but get an error System.QueryException: List has no rows for assignment to ...
0
votes
1answer
26 views

How to avoid: Error uncommitted work pending in my testclass

I am doing do a callout trough a processbuilder with a future call. Before I do the call I get some variables from a custom setting. When I do an insert in my testclass for my custom setting I get the ...
0
votes
0answers
33 views

Cannot specify Id in an insert call: [Id] in unit test for HttpPost

I have this error because I duplicate my object by method's calling. How can I fix it? My HttpPost: public static Avia__c ParseRequest(RestRequest req) { Avia__c a = new Avia__c(); String ...
0
votes
1answer
31 views

Test Class Not Covering Original Class

So I am trying to cover this Chatter Answers Class so I can increase my system's code coverage. The test class runs successfully but the original class is still 0% covered. What do I need to do to ...
1
vote
1answer
30 views

Test for HttpPost service: how to take JSON body for test?

I have a HttpPost methods. And I really don't know how to test it correctly. My methods: public static App__c ParseRequest(RestRequest req) { App__c app = new App__c(); String body = req....
0
votes
1answer
24 views

How to make Test Coverage 100%? HttpGet method

How can I test this for 100% coverage? @HttpGet global static List<Box__c> getBox(){ RestRequest req = RestContext.request; String boxId = req.params.get('Id'); if(boxId == null) ...
0
votes
0answers
20 views

salesforce query returns integer instead of decimal

I have a query which returns an object s that has a field called Tier__c which is decimal. I insert the object in my test class with Tier__c as 1.0 and call create function from the helper class. ...
0
votes
2answers
30 views

Test trigger before insert

I'm trying to test a test a trigger that adds an error if the field Active__c is set to true on CreditInfo_Eval_Rules__c (son of CreditInfo_Fields__c) and the field Used__c is updated to false. I'm ...
0
votes
0answers
24 views

Assigning a lookup field by ExternalId in test class not working

I am trying to assign a lookup field on a custom object, log__c, to a related Asset record based on an external id field on the Asset record. This assigns a record as expected when calling the method ...
1
vote
1answer
30 views

What kind of test can I write to check the file?

I have a controller for VF Page. This code upload a profile's image (we can see it after that) and delete it. What kind of test can help me to check this file? I need to know, is it uploaded or not. ...
0
votes
1answer
36 views

Static method cannot be referenced from a non static context (PageReference)

What is wrong here? Candidate__c cand = new Candidate__c(); insert cand; PageReference pageRef = Page.UploadCandidatePhotoVF; Test.startTest(); Test.setCurrentPage(pageRef); ...
0
votes
2answers
26 views

Make the test work: File insert, check this File

This code is a controller for my VF Page. It inserts ContentVersion and ContentDocumentLink. After that a candidate field Photo__c take a ContentVersion.Id value. How to check it correctly? Now ...
0
votes
1answer
13 views

Why does my country returns null on creating an account?

I am creating a testdatafactory. creating a country goes well. When creating accounts my country fields are null if i debug CountryList it returns the created country record. Factory class @isTest ...
0
votes
2answers
34 views

How to build a testdatafactory without error : DUPLICATE_VALUE, duplicate value found: duplicates value on record with id: : []

I an trying to create a testdatafactory which i can use to call in my tesclasses. What I want to achieve is small buildingblocks with which I call another method if a lookupfield needs to be filled. I ...
0
votes
2answers
17 views

do I need to update or insert a list, set or map in testclass

When ik create a list, set or map and add records to these do I need to update / insert after adding records. I did a test system debug on a testclass with only a return. My debug returns a list with ...
2
votes
1answer
56 views

Is there any way to set set salesforce userid from apex test class

Is there any way to set set salesforce userid from apex test class. For Example: SetupTest st = new SetupTest(); Account billing = st.Account('Billing'); billing.Name = '...
2
votes
2answers
35 views

Code coverage annotation for or statement next line or same line?

Ik have a class with several or statements. To make the code more readable I placed the or statements on a next line. My dev console shows that there is no coverage for these lines. Do I need to place ...
0
votes
1answer
46 views

Script-thrown exception in Test class for Batch apex callout

I have a batch class which makes multiple http callouts to an HR system and then with the absences returned checks for existing absences and upserts. However when I try and run test class for the ...
-2
votes
2answers
32 views

Methods defined as TestMethod do not support Web service callouts -ApexPages.StandardController controller [duplicate]

I am trying to test my Apex class, getting following error response "Methods defined as TestMethod do not support Web service callouts" public with sharing class CreateOrder { private Boolean failed ...
-3
votes
1answer
31 views

Unable to cover apex Test class

Apex Class public class get_data{ public static map<string,map<String,String>> get_tier(String fetchFrom){ map<string,map<String,String>> dataFields = new map<...
1
vote
0answers
20 views

Unaltered Test passes in Sandbox AND Production, but fails during unrelated deployment validation

I am trying to deploy a few classes. I've got a Sandbox that I literally created this morning off of Production. Nothing is different between the two except the 3 classes I'm deploying. How can it ...
0
votes
1answer
31 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when System.runAs(u) in a test class

I need to create a Patient_Registration__c (which is a Person Account) under a specific user in my test class. Following is my code in the test class: Profile p = [SELECT Id, Name FROM Profile WHERE ...