9

sObject classes don't implement interfaces at all. Unfortunately, that won't be a viable solution here. One very common solution to this issue (needing to create an object and populate non-writeable fields) is JSON deserialization. It's viable here; an example: LoginHistory l; l = (LoginHistory)JSON.deserialize( '{"UserId": "'+UserInfo.getUserId()+'", ...


8

I typically use a fairly simple pattern and don't bring in a framework. It would look something like the following: public virtual with sharing class MyObjectHelper { static MyObjectHelper instance = new MyObjectHelper(); @TestVisible static void setMock(MyObjectHelper mock) { instance = mock; } public static Boolean canQueryObject(SObjectType ...


8

Consider removing the seeAllData=true annotation, since you do not appear to need it and use of this annotation without a specific (and rare) reason for requiring it is very bad practice. Doing so makes your unit tests fragile due to exposure to the full and changing breadth of your org's production data. Your unit test populates the Grade_Level__c field: ...


6

Based on previous answer, following approach worked for me Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + '/_ui/common/apex/test/ApexTestQueueServlet'); request.setMethod('POST'); request.setHeader('content-type', 'application/x-www-form-urlencoded'); request.setHeader('cookie', '...


6

This isn't possible today. I've reached out to the Surveys team to ask them either mark the object type as not available for Apex triggers, or make it possible to test Apex triggers on it.


6

There are a few different ways to attack this problem, but the most common is to create a user with permissions, and then use System.runAs to execute your tests. I normally grant permissions to my packages via permset and not profiles, so I create a user, give it a permission set that I created, and then run the tests. That way I don't depend on the admin ...


6

It looks like the issue is on this line Map<String, List<dashData>> results = NPD_IdeaDashboardController.makeDashMap(memberList, campList); There is no dashDatain local namespace, its innerclash so you have to refer it as Map<String, List<NPD_IdeaDashboardController.dashData>> results = NPD_IdeaDashboardController.makeDashMap(...


6

Typically, if I want to verify the callout is made and there may be asynchronous processing involve, I just track it on my mock. class MyMock implements HttpCalloutMock { Integer calls = 0; public HttpResponse respond(HttpRequest request) { calls++; // mock implementation here } } Then, in your test, you just cache your mock ...


6

In your query, Id = :WorkOrder.Id should be Id = :fieldVisit.Id The binding operator works with a record not with SObjectType. // WorkOrder.Id returns field API name as Schema.SObjectField data type // this is used mainly with dynamic apex // where as query filter expects a primary data type Schema.SObjectField Id = WorkOrder.Id;


6

Any unit test you ever run in Salesforce will roll back all DML Operations at the end of the transaction. Same with emails sent out. Unit tests do not persist any change to your org, other than incrementing auto-number fields unless you configure them to avoid it. See, for example, from Add a Test Class in the Apex Developer Guide (emphasis mine): The ...


5

The problem is that Test.stopTest executes the asynchronous code, then resets the governor limits back to the state it was in immediately before Test.startTest is called. If you really wanted to verify the output, you'd need a static method to check: public class MyQueue implements Queueable, Database.AllowsCallouts { @TestVisible static Boolean ...


5

The comment from @muenzpraeger was correct. The event handler won't fire on its own, so it needs to be fired directly from the test. So the test.js would look something like this: var element = createElement('c-test-component', {is: TestComponent}); document.body.appendChild(element); const handler = jest.fn(); element.addEventListener('formsaved', ...


5

I've been struggling/battling with this since the Spring '13 release. It tends to manifest in one of two ways when parallel testing is enabled: As you found, Tests fail with APEX CPU Timeout Exceeded messages, or Entire tests classes fail with Could not run tests on class 01p400000000001 because: connection was cancelled here messages. The sad truth is ...


5

In unit test context, Custom Settings are treated as data (not metadata), and hence are not visible due to test isolation. Your unit test's setup, whether in your @isTest or an @testSetup method, must construct and insert any Custom Settings records you wish to have available to your test code. You get a NullPointerException because there is no visible ...


5

It's determined by the PathOnClient field as populated when you create the ContentVersion. As an example, in one of my orgs I uploaded a file called App.logo.png through the API, populating its file name in the PathOnClient field and App.logo in the Title field. The system inferred png as the value for FileExtension.


5

The solution for this is to move the queries into a Selector layer and then use dependency injection to use a mock selector during testmethods rather than the PROD selector when running normally Now I am a particular fan of the fflib pattern and ApexMocks (which exploits the StubApi) for doing all this but there are other approaches that accomplish the same ...


5

Nor average, neither sum of percents. If some test methods cover one line of code twice, it only means that this exact line of code is covered. So the actual test coverage is linesCovered / allLines * 100. Example: imagine 1st test class covers one method in your controller (30%), 2nd test class covers 2 methods including the previous mentioned one (50%), ...


4

There were several Salesforce issues related to System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Besides of the issues mentioned, additional issues that I have encountered with, were: The problem with @future(Callout=true) methods. First time I reported this was at February 12, 2015 Spring 15 ...


4

You should not be testing the results against a fixed set of options but rather that: The token is the correct length The token is made up of the correct characters The token is different on average n% of the time where n depends on the token length and number of options per character.


4

In a before insert trigger, there are no record Ids assigned yet. If you're testing in the UI, try creating a new record, it should have the same error (but it won't be visible in the UI since it is asynchronous). You can move the logic to after insert/after update to avoid this problem.


4

I tend to use .getUrl() and .startsWith() e.g. System.assert(nextPage.getUrl().startsWith(Page.ExpectedPage.getUrl()), nextPage.getUrl()); It's good to use startsWith() in case the controller puts parameters on the end.


4

When you compare 2 objects in Salesforce (as far as it is known it is based on Java), it actually compares not objects, but their hashCode results, or what is returned as compareTo method from Comparable interface. Since given class (PageReference) is system, it is impossible to know if two PageReference objects are same - event if those are created from ...


4

No, your coverage is not adequate, even if you hit every line. You should look up and read about Cyclomatic Complexity, and aim to cover every major branch. Specifically, you do not have a test method which verifies a System Administrator is exempted from the rule. Similarly, you should verify that all users are still able to delete records where ...


4

The object must be the object that matches the HttpCalloutMock class: Test.setMock(HttpCalloutMock.class, new MockHTTPResponseGenerator()); If you need different responses, they must all come from the respond method, or you need to use different classes for each mock. global class MockHTTPResponseGenerator implements HttpCalloutMock{ global ...


4

This is related to Summer'19 changes: OWD External Org-Wide Defaults in Orgs with Communities Custom Object Access Settings Default to Private


4

The wrapper class's instance variables have no access specifier, meaning that they get private as the default: [private] List<Revenue_Pipeline__c> revPipe = ; [private] List<Revenue_Pipeline_Schedule__c> = ; It's the instance variables that need the @TestVisible annotation, rather than their enclosing class. That will make them available in ...


4

Thanks for raising this issue. We recently cleaned up our warning and error messages because some of them were un-actionable or just creating too much noise. This particular warning will no longer be logged in a future release: https://github.com/salesforce/lwc/commit/1afe614236cd0a2c801617afbbdeaeea9b8a30ff


4

You can just pass e. g. a file name after your script name E. g: npm run test:unit mycomponent.test.js Would all tests matching a file named mycomponent.test.js


4

SOSL doesn't return results in test classes, so you have to use special methods to set the results. To ensure that test methods always behave in a predictable way, any Salesforce Object Search Language (SOSL) query that is added to an Apex test method returns an empty set of search results when the test method executes. If you do not want the query ...


4

FileType isn't writeable, but PathOnClient is - it's createable, but not updateable. The system will infer the type of file from the pathname extension you supply in that field. (ContentNote records will have type SNOTE; they don't have extensions). See the SOAP Reference: FileType is defined by either ContentUrl for links or PathOnClient for documents, ...


Only top voted, non community-wiki answers of a minimum length are eligible