New answers tagged

0

Can it be the case that more than one callout is being triggered? If that's the case, here's a good start point https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock.html


2

You must have an unmocked callout in code that is invoked by your Account and Case tests, directly or indirectly. The most likely scenario based on your description is that some automation on Case invokes an update on Account - perhaps some type of roll-up functionality. Your refactoring of Account-related code introduced a new code path that executes on ...


0

I have sometimes found that it would return this error when there are no records to be found (ironically). This is especially when I did not initialize the list or use SOQL for loops. Ex - Where there are no Accounts in the org with Ids mentioned in the List 'accIds', I got the Too many SOQL queries error on running the test class. for(Account acc : ...


0

let checkBoxEl = element.shadowRoot.querySelector("lightning-input"); expect(checkBoxEl).not.toBeNull(); checkBoxEl.checked = true; checkBoxEl.dispatchEvent(new CustomEvent("change"));


1

In the base component stubs Salesforce provides, checkValidity() is provided as an empty function that returns undefined for inputs and comboboxes. According to the theory of testing that Salesforce puts forward, you want to avoid any dependencies on the internals of the lightning-input and lightning-combobox base components, such as what their methods ...


0

This is where the Enterprise Patterns and Apex Mocking comes in: Enterprise Patterns Selector layer (queries) Services layer (business requirements) Domain layer (trigger handler/methods on the sobject) Unit of Work layer (transaction) Apex Mocks allows mocking of these layers If you architect your code this way, then unit tests can be written on any ...


1

In general, if you have a framework which allows you to bypass triggers for test data setup, you should do it. My primary argument for doing so is that Unit Tests should test individual units. These tests should be atomic. If you are testing how some AccountService functionality works, that test should not be dependent in any way on what logic is in your ...


2

The upside to option #1 is that it can significantly reduce deployment times. In one organization I worked at, I was able to reduce the deployment times from 45 minutes to 15 minutes simply by disabling triggers during @testSetup methods and other test initialization methods (most tests started off with @isTest static void test() { initialize(); ... }). ...


2

In my experience, it is always best to consider the full end to end flow which includes triggers. The biggest advantage of this approach is that you always run the "worst case" scenario with regards to all types of limits that you can hit and are not hit by surprises when a user suddenly gets a 101 limit error because he/she was not bypassing. This also ...


3

The reason is, as any good unit testing framework would require, to ensure that the unit tests are not reliant on any external resources. Unit tests should be entirely self-sufficient. You don't want your tests failing simply because the external system that your callout invokes is temporarily unavailable from the Salesforce org, for example. The unit test ...


0

I found the issue. It was because of the way I was creating the Product2 eq object. I was setting only Name and Maintenance_Cycle__c when creating it, but turns out that there's another required field, Replacement_Part__c. Missing the field failed the validation, which is why the system couldn't create a number of objects after that, one of which caused the ...


2

One way to assert on email sent in APEX is to look at the email limits for the transaction. Between your startTest and stopTest you would include an integer to assign Limits.getEmailInvocations(); which will tell you how many invoked emails there are. Test.startTest(); ClassBeingTested.methodWithEmailCall(); Integer i = Limits.getEmailInvocations(); Test....


0

Looks like there is an after update trigger written on the MaintenanceRequest object within your org where you are trying to execute this code. The trigger code is failing and causing the update to fail. If you deactivate that trigger and try again, this update within the testMaintenanceTriggerPositive() should work fine. Also, have you verified if Closed ...


0

The possible reasons are:- Internal Users will not be able to share files with community Users if the files are attached to the 'Files' related list. Since, you have related the file to a Case record, It goes and sit in case record file related list. As a workaround, Use Chatter Publisher to share files with Community Users. Read more here:- Share object ...


1

Maybe try this: List<myclass.innerclass>result = myclass.mymethod('test'); Based on feedback from sfdxfox, Child class can only be accessed via parent class. And the first post explained pretty well in details, thanks


2

Please find below corrected test class after fixing your main class: You need to access inner class via main class. As a general rule , it is "MainClass.InnerClass" @isTest public class myclassTest{ @isTest static void mymethodtest(){ List<myclass.innerclass>result = myclass.mymethod('test'); system.debug(result); } } Your ...


-1

Your lead is owned by a queue not a user. PartOfTheOhana is right in that it's polymorphic but if the owner was a user your debug would work. Example: @IsTest static void methodName() { Profile profId = [Select Id FROM Profile WHERE Name = 'NPD Standard']; String orgId = UserInfo.getOrganizationId(); String dateString = String.valueof(Datetime....


2

I think the reason you're getting this is because the lead owner field is polymorphic. The lead owner can be a user, queue, partner user, etc. So, as a result, it's easier to run 2 seperate queries or do a join on the user object. Here's some docs on polymorphic fields - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/...


1

You're trying to query for records in a before insert trigger that are currently being processed by the trigger; i.e., have not yet been committed to the database and cannot be seen via SOQL. Trigger is before insert: trigger CaseCountAlertTrigger on Case (before insert) { Your test class performs exactly one DML operation: Test.startTest(); ...


0

I have no idea how but issue resolved. This was after a recent Sandbox refresh. I copied/pasted and renamed the trigger. No issues. I don't have an explanation.


0

Put your assert after the stop test - start test stop test is supposed to enclose the asynchronous code that you want to run, and wait for it to complete. Then you can make your assertion after it has finished.


0

The problem was in Contact as i was causing error for some other reasons when i removed contact part from test class i got the answer Test Class @isTest public class TestChapterRollupBatch { static testMethod void testMethod1() { List lstAccount= new List(); for(Integer i=0 ;i<10;i++) { ...


0

First Understand about Test Data in Salesforce:- Apex test data is transient and isn’t committed to the database. This means that after a test method finishes execution, the data inserted by the test doesn’t persist in the database. As a result, there is no need to delete any test data at the conclusion of a test. Likewise, all the changes to ...


0

Menu: Test / Clear Test Data -- followed by F5 -- works for me! on Chrome in Linux.


0

karthikselva's answer is spot-on, that JSON.deserialize will produce the same result in your use case where taxable is null if the field is omitted in either a unit test or in a real API call. This is not a bug but rather an intended feature of serialization and deserialization. Microsoft explains the concept of "serialization" rather well in its docs. ...


2

This error actually means that the execute method should be called only ones. In order to achieve this, you have to be sure that: 1) Your query in the start method returns all records in the test context that are available for the batch. In your example, it should be 1. So, check that only one account is present as you have LIMIT 1. 2) Remove (SeeAllData=...


2

The community user should have access to Loan_Doc_Sort__c record to upload files on it. You have few options, Change the OWD of Loan_Doc_Sort__c to public read-only external Create a manual share record for Loan_Doc_Sort__c after insert and share it with the commnunity user. Ensure The community user is the one creating the Loan_Doc_Sort__c in the test ...


2

You just need to create an instance of the inner class and it should cover the class that you have mentioned in the question. So the below test class should give you 100% code coverage @isTest public class ProdImedComAr_Test { @isTest public static void unitTest(){ ProdImedComAr.Respuesta req = new ProdImedComAr.Respuesta(); } } But ...


0

From this help article: Read, Create, Edit, Delete, View All, Modify All on all standard and custom objects Convert Leads Create and Customize Reports Edit Events Edit Personal Quota Edit Tasks Import Leads Import Solutions Manage Categories Manage Dashboards Manage Public Documents Manage Public List Views Manage Public Reports ...


0

The code that you showed doesn't have any callouts, so I assume that either your Account or Customer Todo trigger have a web service callout in it. In order to write a test class for a class that has a callout, you will need to implement a Mock class. You can read more about it here.


1

I believe the WHERE clause is not being fulfilled in the controller query: List<Unit__c> unitList = [select Id, Name, Owner_Account__c From Unit__c where (Owner_Account__c = :user.AccountId)]; How is Owner_Account__c set on the unit? When you insert them using: Unit__c u = TestData.getUnit(); Insert u; If it depends on the community user ...


2

Your last 2 debug statements return null because at this moment, your communityUser only has the values that you defined a few lines above. If you query that user right after insert with all these fields, then you should have all the info that you need: insert communityUser; communityUser = [SELECT Id, ContactId, Contact.AccountId, AccountId FROM User ...


0

The second-to-last statement prints null, because you can't traverse relationships that way. You can only access the Contact relationship from the User if you use a relationship query. The last statement prints null because you haven't set AccountId on the User.


0

This is a long running issue... It is a Custom Unmanaged Salesforce deployed piece of code that obviously does not need to meet the high standards they put on us, or it did once. Also has a number of hangups related to Portals/Sites, Portals were effectively replaced by Communities, and the evolution of them. This workaround is also lacking in info: https:/...


1

https://github.com/trailheadapps/lwc-recipes/pull/31/files/08bef0c3da0b620b875ab35140b8cb4095168183#diff-5cb65947ae0b0e7b8586ff96e0f1201e - change history for jest test. https://github.com/trailheadapps/lwc-recipes/pull/31 - thread discussing jest tests. Looking at some closed issues, it seems they mention this particular line/issue. It says it's closed and ...


0

Thank you Kevin. I have the same issue and figure out a working code sample as below: Test.startTest(); do_the_update_with_future_call(); Test.stopTest(); List<Account> checkAccounts = [ .... ] System.assertEquals(....) The result's query must be set after the "Test.stopTest()"! If the query is set between startTest and stopTest then the test will ...


0

Your tests are passing with false positives because your setup() method is not annotated correctly with the @testSetup annotation. That annotation is required to make the test setup method run prior to each unit test; otherwise, it's just an ordinary unit test itself, whose data-creation steps are not applied to the context of each other test within the ...


1

After some annoying debugging using a special logging tool we built that writes logs as records, I found the culprit was in List.contains(Object). This method does not know how to deal with an Id parameter when it's template type is also Id . My first step was to replace: if (RECORD_TYPE_IDS.contains(customRecord.RecordTypeId)) with... for (Id i : ...


1

You can easily remove the @seeAllData from the test class. Just take a look to this page Test classes has @seAllData set to false as default. you can set in this way the setting to true only for interested methods. The @isTest(SeeAllData=true) annotation is used to open up data access when applied at the class or method level. However, if the containing ...


0

You can try to check the emails after your test is done. Add something like this on your asserts. We just want to use a SOQL on the EmailMessage and get them by the email subject. // When Test.startTest(); // Your test Test.stopTest(); // Then List<EmailMessage> newMails = [SELECT Id, Subject FROM EmailMessage]; System.assert(!newMails.isEmpty(), ...


Top 50 recent answers are included