New answers tagged

1

The problem for me was that the status of the permission set group (PSG) changed after adding the PSG-Component and second Permission Set. I had to assign the PSG first before inserting new components. This fixed my problem: //create user with permissions public static User createUserPermissionDataModel() { //permission set PermissionSet ps = new ...


1

Apex allows you to set the CreateDate field, all you need is to use below during data creation, Test.setCreatedDate(<recordId>, datetimevalue); In your case, when you are creating the Error log use below, ErrorLog__c err = new ErrorLog__c(); .. insert err; Test.setCreatedDate(err.Id, DateTime.newInstance(2020,12,12)); This will ensure that create ...


0

There is an Isolation of Test Data from Organization Data in Unit Tests. This means that you can't query the record in your unit test. You must explicitly create records that are to be queried within your unit test, except for some exceptions, like Users, Profiles, and Record Types (see the above link for more details).


1

It's the same as you'd do for any other method: @isTest static void myTest() { // Set up test data Opportunity record = TestUtils.createTestOpportunity(); // Set any parameters you need ApexPages.currentPage().getParameters().put('id', record.Id); Test.startTest(); // new X() calls the relevant constructor testController controller = new ...


1

The thing that I'm seeing here is that you've left out the new keyword when trying to create a new instance of your PrintPackingListWrapper class. A quick test via Anonymous Apex shows that missing that keyword does in fact generate the "Method does not exisst of incorrect signature" error. public class MyInner{ public MyInner(String str){} } /...


6

This is expected and called out in the documentation. The system method runAs enables you to write test methods that change the user context to an existing user or a new user so that the user’s record sharing is enforced. The runAs method doesn’t enforce user permissions or field-level permissions, only record sharing. What would be a valid use case for ...


3

Testing exceptions is hard (well, harder than testing most other things). The reason why you're not catching an exception is because an exception isn't being generated. If you provide a nonsense value for an Id in a query via a variable bind, you'll just get 0 rows as a result rather than an exception (that goes for both normal and dynamic SOQL queries). ...


0

This worked for me RecordType rt = [Select Id From RecordType Where DeveloperName = 'Staff' limit 1]; RecordType accountRT = [Select Id From RecordType Where DeveloperName = 'organization' limit 1]; UserRole r1 = [SELECT Id FROM UserRole WHERE DeveloperName = 'YourUserRole' limit 1]; Profile portalProfile = [Select Id from Profile where name =...


3

Some observations If I login to the sandbox directly, and run all tests - they pass - no error Go to Setup and check the status of the Permission Set Group MyPSG - it is Updated I injected an assert into the User mock factory to check the value of PermissionSetGroup.Status just before I assign it to the PermissionSetAssignment.PermissionSetGroupId - The ...


1

I think it is because the start method returns no sobjects to execute. On this line global String queryString = 'SELECT Product2Id, Product2.Global_List_Price__c, CurrencyIsoCode FROM PricebookEntry WHERE Product2Id != null AND CurrencyIsoCode !=\'USD\' AND Product2.Global_List_Price__c > 0 '; is defined the query used. So the start method should return ...


1

In your test class you should set the current page via Test.setCurrentPage(page) method. Then you can add to the page the id of the record you're using in your test. Replace DokuBox_6 D6 = new DokuBox_6(); with: PageReference dokuboxPage = Page.DokuBoxPage; // Assuming that the VF Page name is DokuBoxPage Test.setCurrentPage(dokuboxPage); ApexPages....


0

Based on the line number you have mentioned. There might be a null getting entered here orderedProducts.add(o.Product2); So after this line you can write orderedProducts.remove(null);, so that it does not contain any null values. So your code will look like this: for(OrderItem o : trigger.new){ newOrderItemIds.add(o.Id); if(o.ServiceStartDate__c == ...


1

Seems your problem is here: for (orderItem o : itemsMissingStartDate) { Integer leadTimeDays = itemsWithLeadTime.get(o.Product2Id).intValue(); // map may not contain key } Your itemsWithLeadTime.get(o.Product2Id) call can certainly return null. You can drop the .intValue() call as it serves no purpose here, but then you just move the NPE down one ...


4

I wonder why you would want to write a trigger to achieve this functionality. If Account owner is changed, the owner of associated contacts is automatically changed. Please refer below article for more details: https://help.salesforce.com/articleView?id=sf.account_owner_transfer.htm&type=5 RECORD TRANSFERRED ITEMS Account Contacts related to the ...


0

As @DerekF said in his answer, custom settings are data and so need to be created in the context of unit tests. However, what Derek didn't mention is that if you do this, and actually commit custom settings instances to the database, you will run into database locking problems if you run unit tests in parallel where the same instances are created in the ...


1

As @sfdcfox says in his comment, I needed to first turn on the replay debugger and then run either Debug All Tests or Debug Test. (To turn on the replay debugger in vscode, command+shif+p/control+shift+p and type "turn on replay" and you'll see that option appearing). Now if you click on this feature, (which shows up right next to the Run Test at ...


1

Custom setting data is data (as opposed to being metadata). That means that you need to explicitly create data for them in tests, just as you would for an Account, Contact, or Opportunity. If you were to use a Custom Metadata Type (which is suggested as a replacement for list-type custom settings), then you wouldn't need to explicitly add records for it in ...


2

There is this example in the Using the runAs Method documentation that shows how to switch profile in a test: @isTest private class TestRunAs { @isTest static void testTriggerUsingRunAs() { // Create a unique UserName String uniqueUserName = 'user' + DateTime.now().getTime() + '@org.com'; // Pick the Profile you want ...


0

Test methods by default cannot see pre-existing records in an org. The test method itself should insert the records it needs. So this code: callReport.Loan_Apps_to_Relate__c = 'a071F00000A99Z4QAJ,a071F00000A99YpQAJ'; Loan_Application__c loanAppRelate = new Loan_Application__c(Id = 'a071F00000A99Z4QAJ'); Loan_Application__c loanAppRelate1 = new ...


2

Seeing your trigger logic would help quite a bit, but It's worth noting that hard-coding Ids in your tests is typically a bad idea. Your best bet would be to actually create and insert your Loan_Application__c records before inserting your Call_Report__c record. Then, you'll have to re-query your Call_Report__c record to get any field updates that happened ...


2

As you have found from debug logs, the problem was with netsuite_conn__NetSuite_Id__c field, that was used without querying it in the first place. However, for the general usefulness of this question for the community, I want to add some tips: Check DEBUG_LOG when running your tests. If log is not available, you can detect the problem place via code ...


0

You can specify existing unrelated tests to run on classes that are unrelated to your deletion package. If the tests generate 75% coverage for those unrelated classes, then your deployment will succeed. This works with the ant command-line tool and the Developer Workbench.


0

There are a couple of things you can try to bypass the error, Find out the permission sets that the Managed Package needs and assign them to user running the Test class. Make sure your profile has access to the metadata types from the package If none of the above works because the custom metadata type is protected, I suggest reaching out to the vendor(Geo ...


0

It appears your code fails on: QuoteLineItem qLIServiceoffer = [select Id,Product2.name,vlocity_cmt__AttributeMetadataChanges__c,PriceBookEntry.Product2.vlocity_cmt__AttributeMetadata__c,vlocity_cmt__AttributeSelectedValues__c from QuoteLineItem where QuoteId = :subquote and Product2.name = :sourceproductname]; Because you never provided a value for ...


3

If the purpose is to avoid executing in production, you can write: @TestVisible static Boolean s_isSandbox = [SELECT Id, IsSandbox FROM Organization].isSandbox; public Boolean isSandbox(){ if(!s_isSandbox) { throw new CustomDeveloperException('You cannot use this method in production'); } } To get this to pass unit tests, you can write:...


2

In the end this is the answer we came up with. We broke our deployment into two stages: STAGE 1: Code changes include any updates to code we are keeping, as well as gutting any classes we intend to remove, leaving nothing but the signature. This made it so only the code and unit tests we were keeping ran as part of PROD deployment. After this deployed ...


0

My Answer The documentation on Salesforce recommends that we is Test.isRunningTest() But with this particular inner class set up it would not work as well and resulted in uncovered code. In this situation, we can handle segments of Queueable Apex that is called from a void method. However, there are problems if your method needs to assert the results of the ...


1

This specific error is a simple omission of the implementation of HttpCalloutMock. Change: global class MockFirebaseResponseGenerator To: global class MockFirebaseResponseGenerator implements HttpCalloutMock Note, too, that it is unlikely you need to make any of what you have here global and should instead use public. The global access modifier is for ...


Top 50 recent answers are included