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 (3)

6
votes
1answer
27 views

Test execution order issues with Queueable and @future method

Test code: * Test.startTest(); * System.enqueueJob(new MyJob()); * Test.stopTest(); * System.debug('Quering record for assertion'); Expected Queueable job execution: * Job Start * Query records * ...
1
vote
1answer
21 views

Data to use in unit tests, how to manage?

while doing unit testing in Salesforce, how do you handle the test data? Do you make new sets of data each time? (thats what Im doing right now) Any other suggestions? On a tangent, how do I ...
2
votes
1answer
14 views

How to write test class of sending emails?

As i am not aware of test classes i am bit confusing how to write test classes. Can any one one please suggest me how to write test class for below class: public class genericSendanEmailClass { ...
0
votes
1answer
23 views

formula field is not getting executed in test class

formula field is not getting executed in test class, due to this condition is fails in apex class. the test class is below @isTest(seealldata=false) public class ...
0
votes
1answer
18 views

Account FieldSet is not getting covered in my test Class

Hi I have a method in my controller which use dynamic Apex but I'm not getting the code coverage for the below lines, any help is appreciated. public void beforeUpdate (List<Account> lAccounts) ...
0
votes
0answers
18 views

Mock managed API?

I have a apex class that calls the API from a managed package (Zuora Order Builder) and these API calls' implementation (within managed package) have web service callouts to an external system (Zuora)....
1
vote
1answer
18 views

Not able to cover batch class which is deleting expired content document

I am writing test class for batch class which will delete all the content documents which are expired. And I am getting this error "System.SerializationException: Not Serializable: com/salesforce/api/...
0
votes
0answers
27 views

How to cover code coverage, showing too many soql query

I've one trigger on patient object and this object and 10 record type and same object related to another 5 object. Now I've written class on patient object to create opportunity for all the record ...
1
vote
1answer
23 views

Inactive Trigger Test Code Question for potential solution

I was reading this: Are inactive triggers counted against test coverage? And I had an idea pop into my head: Can I cover several apex triggers, using a single test function, if they all contain the ...
0
votes
0answers
27 views

Running Tests in Production WHILE Deploying to Production - Row Lock Error

In our test classes, we utilize testSetup methods that create and insert records in preparation for their use in the test methods of the class. I found today that if I'm running tests in Production ...
0
votes
2answers
27 views

Need to increase code covergae [on hold]

I have 61% coverage i need to increase saveAccount() method. public with sharing class AccountCustomLookupCntrl { public Account account {get;set;} // new account to create public List<...
0
votes
1answer
29 views

APEX CPU TIME LIMIT exception while no unnecessary loop already removed

I try to load 200 data and run test class for my trigger.my test class fail due to APEX CPU TIME Limit .I read on static variable but it is work on bulk upload and if I am using Trigger framework that ...
0
votes
0answers
17 views

Workflow Working on Page but not in test class

S1SD1__c, S1SD2__c and S1SD3__c these are three checkbox and StageName is picklist on Opportunity object when stagename is Stage 1 - Qualified and all three checkbox are checked and when click on ...
0
votes
0answers
8 views

How to Create Person Account Portal User in Test class?

How to i Create Person Account Portal User in Test class. I am using Site.createPersonAccountPortalUser(u, ownerId, password); to create User.
0
votes
0answers
28 views

Getting error in Test class [on hold]

I have a trigger to update custom function field on event. Contact related to activity, I need to pull his functional role ( custom field) on Activity page layout. So whenever I create an activity and ...
0
votes
1answer
39 views

Help to writing test class for Rest class POST method

I writen rest class for updating the lead details below. @Restresource(urlmapping='/Lead/*') global class Cls_LeadData { @HttpPost global static void updateLead(String codeid, String ...
1
vote
0answers
29 views

APEX Plugin failing test but working otherwise

I've got a trigger that helps copy some stuff over when a lead is cloned trough a visual workflow. Even though it works properly when testing it in the flow, the plugin fails when trying to unit test ...
2
votes
1answer
23 views

How to prevent package triggers clashing with local triggers?

Assume there's a trigger on before-update of Account that sets Account.FIELD to "Value 1". A custom setting determines if it can run. This trigger along with related unit tests is included in a ...
1
vote
1answer
32 views

Test Class for Chart Controller

Below is a Visualforce Chart Controller example directly from the offical documentation. https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting_overview_simple_example.htm ...
0
votes
1answer
21 views

How do I cover 'addError' in test class

My Requirement is I have to cover so.AddError() in the test class. Apex Class: if(accountToUpdate.Inactive__c== true && accountToUpdate.Inactive__c <> accountBeforeUpdate.Inactive__c) ...
-4
votes
0answers
14 views

Test Class for the below trigger [closed]

trigger EmailAfterDelete on Account(after delete) { Messaging.reserveSingleEmailCapacity(trigger.size); List<Messaging.SingleEmailMessage> emails = new List<Messaging....
0
votes
2answers
36 views

how to cover the test class for apexpages.addmessage

I have written a test class that covers 86% leaving out the apexpages.addmessage () in catch block, but majorly it throws the validation exceptions on that object when I try to update a record.(Here I ...
2
votes
1answer
102 views

Help getting sufficient test coverage: stuck at 16%

So I've been reading and noticed that as a general rule you should shoot for 75-90% code coverage for a trigger, aiming for 90% or higher if possible. I feel proud of myself for getting the test ...
2
votes
1answer
23 views

How do I block and wait for an Apex job to finish executing?

I need to run an apex job inside a test: test.startTest(); Id jobid = Database.executeBatch(new ApexJob()); and then wait for the apex job to finish and then stop the test: test.stopTest();
0
votes
1answer
19 views

How to cover the code inside the for()

What do I need to set contactsFromQ_List2 and completeContacts_List2 to in order to cover the code in the two for() loops? This is the values of the two lists. contactsFromQ_List2 = [Select ...
6
votes
1answer
94 views

Why do static and non-static lists behave differently in batch and test contexts?

Given the following batch code: global without sharing class POCBatch implements Database.Stateful, Database.Batchable<Sobject>{ public static List<String> staticList = new List&...
0
votes
0answers
21 views

System.DmlException: Process failed. First exception on row 0; first error: MANAGER_NOT_DEFINED, Manager undefined.: []

How to set Manager on test class for approval manager Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; User u = new User( Alias = 'testu', Email ...
0
votes
1answer
26 views

how to call approval process in test class

in test class this portion is not covering because their is approval process if (opp.StageName != 'Closed Lost') { System.debug('---class--' + opp.StageName + ' ---' + oldOpportunityMap.get(opp....
0
votes
1answer
22 views

Compile Error: Illegal assignment from Id to User

Account acc = new Account(); acc.name = 'test'; insert acc; Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; User u = new User( Alias = 'testu', ...
0
votes
3answers
33 views

@ symbol unrecognized

Below code creates error on save: Error: Compile Error: unexpected token: @ at line 15 column 0 Why is @ an unexpected symbol? @istest or @isTest is all over the Salesforce docs, I have tried both: ...
0
votes
1answer
38 views

I wanna make Database.SaveResult method handle the DML exception in a test class?

I am testing a trigger that does not allow Contacts to be inserted when LastName is set to 'LASTNAME'. While creating a test class for such a trigger ,I am using the following piece of code: @isTest ...
0
votes
1answer
31 views

Need help setting up test class

Below is my attempt at a test class. I get an error "List Index Out of Bounds: 0" . Anyone know why and what to do next? This is my controller. public class vfCtrlr_Show_Training_Schedule { //...
2
votes
1answer
31 views

Test coverage for a user trigger: How to prevent “DML not allowed on User” in test-class?

I want to deploy a trigger on user. Therefore I need > 1% coverage on the trigger. To invoke the trigger in my test class, I've tried this: @isTest public class elfTriggerFrameworkTest { public ...
0
votes
0answers
20 views

Standard Question object not accessible [duplicate]

I am system admin, Setup -> Quick Search -> Question is not visible in my setup. Actually their was a trigger written on it before an year. Now while compiling my test cases I am not able to ...
2
votes
1answer
36 views

Test class for Scheduled class not created records?

I'm having trouble figuring out why, when executing Test Class, which fires a Scheduled Class and the Batch Class within it, data I expect to be there, isn't. @isTest static void ...
0
votes
4answers
24 views

how to call webservice method from test class

This my web service method in controller: webservice static void generatePoints(Id opportunityRecID) { ...some logic... } how to call this method from test class? please help me
-1
votes
1answer
20 views

Webservice Test Class help? [closed]

I am pretty new to Salesforce development and I am having a hard time writing a test class for some code that I am writing for a Jira to Salesforce connector. Below is my class and trigger, but I am ...
0
votes
1answer
27 views

how to create the object processInstance in test class

how to create the object processInstance in test class? System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [...
2
votes
2answers
35 views

How to test schedulable job with future method?

I have daily job that makes callouts and updates some records. There is @future method invocation in execute() method. I have created test according to this guide: https://developer.salesforce.com/...
0
votes
1answer
18 views

how to insert filter type lookup value for a field in test class

how to insert filter type lookup value for a field in test class I have a field ProductModel(its a self relationship master details i have upload all images) Field on OPPORTUNITY Object its a lookup ...
0
votes
0answers
17 views

unable to complete code coverage and test class is fail for custom setting

here my class.... public class MaxmindSettings { public String APIKey {get;set;} public Decimal firstRating {get;set;} public Decimal secondRating {get;set;} public void getData() { ...
3
votes
2answers
59 views

Building Dynamic Test Classes that don't break due to Destination Org's - validation rules or Required Field settings

Scenario: I have built a solution for a Customer and I have used Apex for this solution.The deployment went well. But after few months the customer added some validation rules to the Sobject and when ...
0
votes
1answer
16 views

Test Class code coverage on Redir method

Test class is failing with an error: Page: <apex:page standardController="Contact" extensions="DispatcherContactEditController" action="{!nullValue(redir.url, urlFor($Action.Contact.Edit, ...
0
votes
1answer
33 views

Testing SOQL Calls in Custom Controller

I'm trying to write a test class for a custom controller that only has some variable definitions and SOQL calls. I've never written a test class for a SOQL call before and honestly have no idea where ...
4
votes
4answers
657 views

Is it worth it to try for 100% org coverage?

I saw an older post where someone had asked is it possible to get 100% code coverage, the responses were that it's real easy to get around 80% and then to cover the other 20% you're starting to get ...
0
votes
2answers
52 views

Class test for Trigger to match a field in object A with object b and populate a relationship lookup in b

I need some help to create a test class to validate the trigger down, someone help me? I do not know where to start, I've tried to get some example and build the class but I could not, yet Trigger ...
0
votes
1answer
48 views

Test class not covering code in batch apex

HI I created a batch apex but my test class is not covering the entire code, not sure where i am going wrong. Looks like query in start method is not returning any test records which i created. Please ...
0
votes
2answers
38 views

Salesforce Unit Test Class

Hi I have created an apex class as seen below for an Apex Visualforce page. But I am having a hard time creating the test class for the code. I would appreciate any help. public class ...
0
votes
1answer
12 views

can we encode/decode image stored in static resource using EncodingUtil [closed]

Can we encode/decode image stored in static resource using EncodingUtil? I want to write test class for 'upload photo' functionality, for that I need get image stored in document. Hence I'm trying to ...
0
votes
1answer
34 views

how to insert content version in test class

how to insert content version in test class what value set for versionData pathOnClient FirstPublishLocationId