Debug “Validation Errors While Saving Record(s)” error message when calling Test.loadData()

Sometimes when you use Test.loadData() you might receive some confusing error message saying “Validation Errors While Saving Record(s)”, it is hard to understand what is wrong in data so it is possible to use the following code to debug the problem


StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'TestData' LIMIT 1];
String body = sr.Body.toString();
String[] fields = body.split('\r\n')[0].split(',');
SObject[] records = new List();
String[] lines = body.split('\r\n');
for ( Integer j = 1; j < lines.size(); j++ ) {
SObject r = new Custom_Object__c();
String[] data = lines[j].split(',');
for (Integer i = 0; i < fields.size(); i++ ) {
System.debug(LoggingLevel.ERROR, '@@@ fields[i]: ' + fields[i] + ' + data[i] ' + data[i] );
r.put( fields[i], data[i]);
}
records.add( r );
}
insert records;

So when you run a code like this you will find out the exact problem you face

Posted in salesforce | Leave a comment

Salesforce Bug in Tests: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

I have finally reproduced the bug about “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out ” error being raised when it should not be raised. It happens when there is a thrown and caught mixed DML Exception in the setup transaction inside a Queueable job, and a callout from queueable or batchable in the test transaction (but not in future method).

Code of dummy batchable class b can be located here: https://gist.github.com/bdovhan/76326745c347dde00717c0318e3bc15b

Code of Apex Test Class TRB reproducing the CalloutException bug referencing class b in one test method can be found here

In this class, there are three apex test methods. Methods testB and testQ, which make callout from Queueable or Batchable, fail, while method testF, which makes callout from Future method, doesn’t fail.

I have also created a repository which contains both apex classes and setup scripts to create a scratch org and push the script to the scratch org.

Currently working with Salesforce support to identify this as an issue and retrieve from them acknowledge of this issue.

 

 

 

Posted in Bugs, platform-bug, salesforce | Leave a comment

Migrating from PC to Mac

Today is my first day working on the Mac machine.

I feel very awkward since I don’t know how to perform basic operations on Mac (I used PC over 15-20 years I think).

So I need some cheatsheet to help myself.

Cmd-Ctrl-Q: Lock screen.

Cmd-W, Cmd-Q: Close window or tab

Shift-7, Shift-6: insert comma or dot on Ukrainian keyboard layout.

Shift-Cmd-5: invoke video screen capture tool. Cmd-Ctrl-Esc to finish video capturing.

Shift-Cmd-4: Printscreen selected region.

Shift-Cmd-3: Printscreen.

Cmd-Left: Move cursor to the beginning of the line.

Cmd-Right: Move cursor to the ending of the line.

 

open /: invoke finder window with root folder

which sfdx: display location of the executable file

 

Posted in Mac | Leave a comment

In my previous posts I have reported an issue which yields

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

exception where it should not arise.

First time I reported this was at February 12, 2015, later on November 9, 2016 I have noted that the corresponding known issue was marked as resolved but the actual problem wasn’t solved, also on December 1, 2016 I have suggested a workaround to this bug.

As of Summer 2019 (v.46), I can confirm that this particular bug seems to be resolved.

However, another bug has arised recently.

To reproduce it, a dummy batch class is needed.


public class b implements Database.Batchable<SObject>,Database.AllowsCallouts{
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT id FROM user WHERE IsActive=true limit 1');
}
public void execute(Database.BatchableContext bc, List<User> users) {
new Http().send(new HttpRequest());
}
public void finish(Database.BatchableContext bc) {}
}

 


@isTest class TOTTest {
private static final Integer STATUS_CODE_200 = 200;
private static final String STATUS_OK = 'OK';
private static final String SUCCESS_RESPONSE = '{"response":{"metadata":[{"totalrowcount":1},{"rendertime":0}]}}';

public class q implements Queueable,Database.AllowsCallouts{
public void execute(QueueableContext context) {
new Http().send(new HttpRequest());
}
}

private static testMethod void testQ() {
insertData();
Test.startTest();
Test.setMock(HttpCalloutMock.class, new MockHttpResponse());
System.enqueueJob(new q());
Test.stopTest();

}

private static testMethod void testB() {
insertData();
Test.startTest();
Test.setMock(HttpCalloutMock.class, new MockHttpResponse());
Database.executeBatch(new b());
Test.stopTest();

}

static void insertData() {
//insert new Test_Object__c();

insert new User(
Username='julfy@i.ua',
LastName='D',
Email='julfy@i.ua',
Alias='D',
CommunityNickname='D',
TimeZoneSidKey='America/Los_Angeles',
LocaleSidKey='en_US',
EmailEncodingKey='ISO-8859-1',
ProfileId=UserInfo.getProfileId(),//'00eE0000000z6DLIAY'
LanguageLocaleKey='en_US'
);
}
}

Posted in Uncategorized | 2 Comments

How to switch from Salesforce Lightning Experience to Classic and Back?

Many newbies are asking about this.

How to switch from Salesforce Lightning Experience to Classic and Back?

This is the video screenshot demonstrating this.

Switch To Classic And Back - opt

😁

Posted in salesforce | Leave a comment

How to amend not latest commit message in pushed branch

git rebase -i HEAD~3
Replace pick with reword
Press Esc then :x! to save and close
Change commit message
Press Esc then :x! to save and close
git push –force origin feature branch

Posted in Git, Uncategorized | Leave a comment

My Aura to LWC migration article is published

My Aura to LWC migration article is finally published on corporate blog

I have written this article on February.

Also I have prepared the presentation on the same topic for internal knowledge sharing meeting inside a company and also for a Lviv Salesforce Development Meetup earlier this yeat.

Posted in Uncategorized | Leave a comment

Mapping Salesforce Profile Name to Profile Developer API Name

Earlier I have post a question on SSE about how to map Salesforce Profile Name to Profile Developer API Name.

Finally I have found solution.

While one of the possible point-and-click way is suggested by @user3375426 to create an outbound changeset and click add Profiles there, another programmatic way is to query Fullname field on Profile using Tooling API.

In Tooling APIname field corresponds to the displayed name of Profile and Fullname field corresponds to Developer API Name of Profile. It is not possible to query by Fullname and query to retrieve Fullname are limited by 1 row, so it is not possible to get Developer API Name of every profile at once, however, it is possible to query one by one and retrieve their API name in such way.

For example, to find ‘System Administrator` profile, the following query can be used

select id, name, fullName from Profile where name like '%admin%' limit 1

enter image description here

Also, we can verify that StandardAul is the Standard Platform User profile by making query

select id, name, fullName from Profile where name='Standard Platform User'

enter image description here

So the query results confirm that StandardAul is the Standard Platform User profile.

Just to summarize, the mappings for Standard Profiles in Professional Edition

Name                 API Name
Contract Manager     ContractManager
Marketing User       MarketingProfile
Solution Manager     SolutionManager
Read Only            ReadOnly
Standard User        Standard
System Administrator Admin

and the mappings for Standard Profiles in Enterprise Edition

Name                               API Name
Contract Manager                   ContractManager
Marketing User                     MarketingProfile
Solution Manager                   SolutionManager
Read Only                          ReadOnly
Standard User                      Standard
System Administrator               Admin
External Identity User             External Identity User
Guest License User                 Guest License User
High Volume Customer Portal User   High Volume Customer Portal User
Customer Community User            Customer Community User
Customer Community Plus User       Customer Community Plus User
Partner Community User             Partner Community User
Partner Community Login User       Partner Community Login User
Work.com Only User                 Work.com Only User
Chatter Only User                  Chatter Only User
Analytics Cloud Security User      Analytics Cloud Security User
Analytics Cloud Integration User   Analytics Cloud Integration User
Customer Community Login User      Customer Community Login User
Company Communities User           Company Communities User
Customer Community Plus Login User Customer Community Plus Login User
Standard Platform User             StandardAul

I have added here two screenshots, one for Professional Edition standard profiles mappings Profile name and API names for Professional Edition

and another one for Enterprise Edition standard profile mappings Profile name and API names for Enterprise Edition

Hit like if you find this post super-awesome.

Posted in salesforce, Uncategorized | Leave a comment