Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

New answers tagged

0

You have to query data from Contact again after the record is updated in order to retrieve the latest values. cont = [SELECT Primary__c FROM Contact]; System.assert(cont.Primary__c == true); Also: can you confirm via console that the field is being updated on the trigger? If not, I believe you will have to first update cont in order to ...


0

Your objective is a little misguided relative to the structure of Apex unit test classes and methods. A unit test class is little more than a container, whose scope can be made useful to you - you can use the class to group related unit tests, and associate them with a @testSetup data factory method they use in common to perform setup prior to running the ...


2

https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_sales_productivity_email_platform_features.htm It seems Enhanced Email was introduced in API 37 which is what's causing the issue. Before that, the emails we forwarded in the code did not create an emailMessage record. Now, they do as the set setSaveAsActivity defaults to true. I can ...


0

Just a shot in the dark, but I think it has something to do with Enhanced Email and it being enabled in version 37 Invalid type: Schema.EmailMessageRelation


-2

Here is the test class for your code.You just need to make your function in the helper class as static. @isTest public class CaseCreateHelperTest { @isTest public static void checkCase(){ Account acc=new Account(Name='CreateCase', Phone='123456'); List accList=new List(); accList.add(acc); CaseCreateHelper.createCase(accList);...


2

The issue arises because you haven't inserted test data. I recommend you insert it in @TestSetup method of your TestClass. In the very basic case you can do it next way: @IsTest public with sharing class TestClass { @TestSetup static void dataSetup() { ContentVersion contentVersion = new ContentVersion(); contentVersion.PathOnClient ...


0

The thing you got is that test class does not see any data in your org. Add this files in @TestSetup or add @isTest(SeeAllData=true) annotation to your test method. Also note that you cannot use both TestSetup and SeeAllData at the same time.


1

Further to @AdrianLarson's suggestion, the variant on this pattern that I use is: // Set up the test data ... try { // Do the stuff you want ... // Directly after where we expect an exception, add: System.assert(false, 'Expected an exception to be thrown'); } catch (TheExceptionTypeExpected e) { // Inspect the exception's details and ...


2

If you are trying to verify that your exception bubbles up as AuraHandledException, I typically prefer a pattern as follows: // set up data AuraHandledException expectedException; Test.startTest(); try { // do stuff } catch (AuraHandledException e) { expectedException = e; } Test.stopTest(); system.assertNotEquals(...


1

Personally I would put all the code in the catch block into a separate method that accepts the exception and any other state that is needed as its parameters (it can also return a value if required). Then I would write a unit test just for that method and not worry about the single uncovered line (the call to this method) from the catch block in the first ...


4

Simply create an instance of inner class and populate its properties by test data: OuterClass.ExistingAccountResult result = new OuterClass.ExistingAccountResult(); result.salesforceaccountid = // testId result.status = // testStatus result.includeinfunnel = // testData result.masterid = // testId result.accountid = // testId


0

Checkout https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_httpcalloutmock.htm to review how to do a mock callout. example: private class myMock implements HttpCalloutMock { public HTTPResponse respond(HTTPRequest req) { HTTPResponse res = new HTTPResponse(); res.setBody('<wREPLY ...


1

The method you're trying to test has the following signature: createCandidacy(List<String> incomingReport) Your test code is attempting to pass a List<Report> to the method instead of a List<String>. Looks like you probably wanted to do something like createCandidacy(new List<String>{reportId}); Beyond that, you should probably ...


0

You should be able to set VersionData on the ContentDocumentVersion


2

Use Test.setCreatedDate() method for the case created, to set the date Days which are -63 from Today's Date in test class. This will help you to meet the last condition written in query from execute method & thus your test class will provide you coverage for delete statement from execute method.


0

I think you need to create two different Contact records - one which is directly related to the Account and another where the Contact is indirect in your test code. I would recommend using a TestSetup method so that you can use this data in multiple methods if needed. You then need to update those contacts in your test class (I assume this runs when a ...


0

You are not even calling your searchAccounts method, you should include a method invocation sentence within your test @isTest public class AccountSearchControllerTest5{ static testMethod void TestMethod1(){ Retail_Account__c rta1 = new Retail_Account__c(name = 'ABC',address__c = 'main st', city__c = 'Tampa', state__c ='FL', zip_code__c = '34609'...


2

You're running a before insert trigger, but your trigger's action depends on querying the database for existing Cases - Cases that aren't part of the current trigger invocation but have already been committed to the database. In addition to sfdcfox's and Adrian's comments, you'll need to insert test data in two DML statements: the first (with 10, or 25, or ...


3

This trigger pattern is going to cause nightmares. When you write your unit tests, they will either check very little about what your code does (and provide variable coverage), or they will fail intermittently, depending on when you run them. First of all, you should move your code out of the trigger body and into an Apex Class, which is something you should ...


1

It appears you forgot to add the records to the list: for(integer i=0; i<10; i++){ Case ca = new Case(); ca.Subject = 'Test Subject - Field Test ' + i; ca.Description = 'Test Description - Field Test ' + i; ca.Origin = 'Web Email'; ca.Type = 'Other'; ca.Reason = 'Other'; // These should be set by the trigger! //ca....


0

I hope this is not the only way, but if it is, then you should definitely write your test in this syntax. try { ApprovalTriggerHandler.bBypassTrigger = true; System.debug('Statement after insert.'); // Insert other records } catch (Exception e) { ApprovalTriggerHandler.bBypassTrigger = false; // Handle this exception here } Otherwise ...


0

@isTest public class TestProductTableApplication { @testSetup static void setup() { ProductTable__c product = new ProductTable__c (Name = 'carrot', Price__c = 10, Amount__c = 1500 ); INSERT product; } @isTest static void deleteProductTable(){ ProductTable__c product = new ProductTable__c(Name = 'Test'); insert ...


1

Welcome to SF Stack Exchange. First you need to set your instantiation ProductTable__c testproduct = ProductTableCmpController.getProducts(); in your test to a List. The method you are calling is a list, so the test method needs to also be a list. Your method also receive a parameter of type string. public static List < ProductTable__c > ...


1

The reason for this error is because there are two Location references known to the Apex Compiler (the Location class and the Location SObject) You need to code: Schema.Location locationStandardObject; locationStandardObject = new Schema.Location(); “Location” in Salesforce can also refer to the geolocation compound field found on many standard objects. ...


1

The reason of the given error message is that maximum amount of unit tests executions per 24 hours is reached. According to the documentation: The maximum number of test classes you can run per 24-hour period is the greater of 500 or 10 multiplied by the number of test classes in the org. For sandbox and Developer Edition organizations, this limit ...


3

Don't worry, You're Doing It Right. Unit tests are almost always larger than the code they're testing, assuming you're doing actual unit tests, and not just smoke tests, because you need to check a lot of conditions in order to make sure everything is working correctly. Unit testing comes in three phases: setup, test, and validation. In the setup phase, you ...


1

In my case Account Owner was being changed, so there is a custom code written on After Update event of Account. This would take new Account Owner and add Account Share record (Read access) for Account's Parent Account record. In some cases, this new Owner being set on child account would already be there as a Owner on Parent account, and it would cause ...


1

https://corevalue.net/code-coverage-for-custom-metadata-based-decisions/ You could essentially create a class to handle the querying of all your custom metadata and a test class for it that would allow you to create the records you want the query to return if need be. This class would check a map variable you set in test execution to see if there's a ...


2

I can see the benefits of the CustomMetadataDAO approach from the comments above, but I tend to go a bit more direct. Since custom metadata records stay the same for a whole transaction, I tend to make them static, TestVisible, and lazy-instantiated. e.g. @TestVisible private static List<Degree_Offering__mdt> degreeOfferingMetadata {get { if(...


0

Thanks Phil and Roti, of course it was simpler than I thought. Solution below for those interested. global class CreateDOService implements Metadata.DeployCallback{ public static Metadata.DeployContainer DOContainer = new Metadata.DeployContainer(); public static Id JobId; @HttpPost global static void createDO(String fullName, String ...


2

Your problem has nothing to do with invocable variable. You are trying to access the 0 index element immediately after creating instance Parametri in test class. You should add element in list instead. Try below: EmailPreventivoAccettato.Parametri Parametri1 = new EmailPreventivoAccettato.Parametri(); Parametri1.IDPreventivo = '0Q03E000000I5OLSA0'; ...


1

You have created the list, but not an Object in it, change your code a bit: EmailPreventivoAccettato.Parametri ParametriObj = new EmailPreventivoAccettato.Parametri(); ParametriObj.IDPreventivo = '0Q03E000000I5OLSA0'; ParametriObj.Gruppo = 'TEST'; EmailPreventivoAccettato.SpedisciMail(new List<EmailPreventivoAccettato.Parametri>{ParametriObj});


4

Honestly, you make assertions for a method that returns void the same way you write assertions for anything else you're testing. Assertions are about validating the results of running a piece of code. If your method is inserting a record, assert that you have one more record after running the code compared to before (query before and after) If your method ...


1

Here's a hack. If you are running a test (as in, the code is called by a test class), then don't filter by activityId EmailMessage emailMessage; if(Test.isRunningTest()){ emailMessage = [SELECT Id FROM EmailMessage LIMIT 1]; } else{ emailMessage = [SELECT Id FROM EmailMessage WHERE ActivityId =: task.Id]; } This would work because in your test ...


1

You are getting this error because, the app you are using have no permission for Case Transfer and the logic which you are trying to implement have case transfer mechanism. This problem can be overcome by proving Case Transfer permission. Profile->App Permissions ->Transfer Case


1

you need to create the Mockresponse class and then you need to create the fake response. in Test class you should call this mockresponse class and not the actual endpoint. PFB the sample code. @isTest global class MockHttpResponseGenerator implements HttpCalloutMock { // Implement this interface method global HTTPResponse respond(HTTPRequest req)...


0

Did you add Test.StartTest() and Test.StopTest() in your test methods? This provides a separate set of governor limits to the code which is in start and stop block, these two statements cannot be called more than once within a test method and they are not required to be used but in some situations may be critical. https://developer.salesforce.com/docs/...


0

Summary: This seems like a simple criteria (only when a certain field changes), a simple template to create, and something workflow is perfect for (do this one action when this happens). For the criteria, you can use the ISCHANGED() formula when you select "every time a record is created or edited". If, even if you use workflow for this situation, you're ...


1

Hello, The problem IS the structure. Let's analyze your code. You have a test class called : FLLC_Foreman_Job_Packet_Helper_Test In this class you have a method called getPhotoNotesFieldMapTest and I suppose it's a test method so you should have @test also on it. (Point of attention 1) you have your return statement before the assert ==> the assert will ...


2

Nothing can be written after return statement. Methods with @IsTest annotation should be void. What I suggest you to do. Move method getPhotoNotesFieldMap to the separate class, remove Test from method name. In your test class set ethod: @IsTest static void getPhotoNotesFieldMapTest() { Map<String, String> toCheck = YourNewClass....


0

It turns out to be zero because (a) the future method is not called until Test.stopTest(), and (b) immediately after Test.stopTest(), you go back in to the test's governor limits. In addition to Adrian's suggestion, you could also have a "universal" method that does the actual callout and provides a nice hook for consistent monitoring: public class ...


1

You could contact Support and ask for a temporary increase, although by the time they get to it, you'll probably be reset already. I would strongly advise that you modify your code to gracefully fail when the limit is reached instead of throwing an exception. It's possible to make sure that you never get this error with some careful error handling, and ...


Top 50 recent answers are included