Teach Me Salesforce

A community approach to learning salesforce.com

Archive for the ‘Uncategorized’ Category

Salesforce DX Monoliths: Chipping Away at the Metadata (part 2)

leave a comment »

After carefully removing all the metadata that I do not think I’ll need I got myself to the test of force:source:push again. It seems like I’ll always have to do –forceoverwrite because I always see a conflict with the Business Account record type.

The source:push generated some errors of course. The first two that jump out at me are those related to history-tracked fields:

force-app/main/default/objects/Lead.object-meta.xml The entity: Lead does not have history tracking enabled
N/A The entity: Account does not have history tracking enabled (12:13)

I mistook this for issues with the  true in the object files to accompany the true in the fields’ definitions but it actually appears to be due to true because when I deleted the Record Type History Tracking I was able to avoid the error.

The next error I got seems like it might actually be a bug (I’ll explain after)

N/A Required field is missing: businessProcess (75:18)

Since I’m trying to deploy Leads with a Record Type, you need to have a business process associated with the record type. I did keep the .businessProcess file for this purpose but I noticed that there is no  tag in the Lead’s .recordType file’s XML. I reverted the file back to its original state to make sure I hadn’t inadvertently deleted it. When I added  and the name of the Business Process, that error along with another one that was apparently related was cleared up.

force-app/main/default/permissionsets/My_pSet.permissionset-meta.xml In field: field – no CustomField named Lead.my_field__c found

I’m glad the above error was somehow dependent on fixing the business process because I had no idea why that would be considered missing. Now it seems like it must be due to the compiler’s inability to load the Record Type which defined that picklist’s values for the Record Type.

The next error was coming from the PersonAccounts, which frankly are performing much better than expected given their troublesome history.

force-app/main/default/objects/PersonAccount.object-meta.xml An unknown exception has occurred.

I was able to clear this up by removing  Private from the PersonAccount.object-meta.xml file. I didn’t consider it on my first review but when I was looking at the file now I realized that there is no sharingModel setting for a PersonAccount since it’s not a real object. Account takes care of its sharing model setting.

One error remains!

force-app/main/default/profiles/API.profile-meta.xml invalid cross reference id

The dreaded “invalid cross reference id”! Oh how many times I’ve been stumped by those 4 vague words. I guessed correctly that it’s probably the reference to the PersonAccount.PersonAccount record so I simply deleted it from the profile altogether…and Hooray! I got the metadata to push successfully!

Advertisements

Written by Always Thinkin

January 17, 2018 at 4:38 pm

Posted in Uncategorized

Building Salesforce DX Scratch Orgs from Monolithic Metadata

leave a comment »

Salesforce DX is revolutionizing SDLC for SFDC. Getting all your metadata from a mature org (the proverbial Monolithic metadataset) is a challenge. I am accepting that challenge and documenting the struggle here, for you.

This post will likely grow over time as I refine the process. Or, perhaps like the advice I’ve read to break down your metadata into distinct modular applications, this will break down into multiple posts.

My Salesforce environment is composed of ~35 UE Orgs that have similar metadata, roughly 80% consistency. So I’ll get to do this ~35 times to perfect it.

Our metadata is hopefully average enough that it represents a good cross-section of the typical Salesforce org out there and thus will help others in this project.

Some Metadata Stats:

Custom Objects: 44
Lines of Apex Code: 161,849 characters of Apex Code
Installed Packages: 0 (actually quite a few but left out of the DX metadata)

Step 1: Metadata Retrieval

I use Copado to backup my metadata daily to Github. So I did not have to use one of the metadata retrieval tools (e.g. Salesforce package.xml Builder) to establish my full set of metadata for conversion.

Step 2: Metadata Conversion

This was the first hurdle. I used sfdx force:mdapi:convert on the unedited metadata I retrieved and starting receiving errors. (error message TK)

I attempted to delete the specific referenced files like SvgIcon.cmp but it seemed like every file in the aura/SvgIcon/ and aura/Toast/ folders was going to throw the error so I deleted all the files and left the empty folders. This allowed me to successfully convert my metadata.

However, I made a mistake in the referenced target folder (-d OUTPUTDIR) in sfdx force:mdapi:convert -r . -d ./force-app and instead of going to the force-app/ folder I created as a sibling to config, the force-app folder was created automatically in the same folder as all my metadata.

Step 3. Create the Scratch Org

Nothing fancy here: sfdx force:org:create -d 30 -v 2U-DevHub -f config/project-scratch-def.json -a 2Ufull01 with the following configs:

{
“orgName”: “2U”,
“country”: “US”,
“edition”: “Enterprise”,
“hasSampleData”: “false”,
“features”: [“PersonAccounts”, “Communities”, “CustomApps”, “CustomTabs”, “DebugApex”, “API”,”MultiCurrency”, “AuthorApex”],
“orgPreferences”: {
“enabled”: [“NetworksEnabled”,”S1DesktopEnabled”, “ChatterEnabled”],
“disabled”: [“IsNameSuffixEnabled”]
}
}

Step 4. Pushing the Metadata

This is where I expect things to get really hard, and where I’ll be documenting what had to be done to make it work.

Next Up: Salesforce DX Monoliths: Exploring 2GP (2nd Generation Packaging)

Written by Always Thinkin

January 4, 2018 at 11:43 am

Posted in Uncategorized

Apex Workshop Webinar 11: Custom Settings

leave a comment »

The video for the workshop session on Apex with Custom Settings can be found on YouTube here: https://youtu.be/UGFvV501qHo

The trigger and its unit test we worked with in this session is available here:

Written by Always Thinkin

July 8, 2017 at 7:15 pm

Posted in Uncategorized

Apex Workshop Webinar 10: Exception Handling

leave a comment »

The video for the workshop session on Apex Exception Handling can be found on YouTube here: https://youtu.be/mFlUdCNsfso

The trigger and its unit test we worked with in this session is available here:

Written by Always Thinkin

July 8, 2017 at 7:05 pm

Posted in Uncategorized

Apex Workshop Webinar 9: Unit Tests

leave a comment »

The video for the workshop session on Apex Unit Testing can be found on YouTube here: https://youtu.be/s_45tsHHbp0

The trigger and its unit test we worked with in this session is available here:

Written by Always Thinkin

July 8, 2017 at 7:01 pm

Posted in Uncategorized

Apex Workshop Webinar 8: Invocable Apex

leave a comment »

The video for the workshop session on Invocable Apex Classes can be found on YouTube here: https://youtu.be/7_cmcvmFn0U

The original source is from a presentation at Dreamforce ’16 based on https://github.com/mshanemc/processBuilderBlocks.
In our session we worked with:
PBB Lock: https://github.com/mshanemc/processBuilderBlocks/blob/master/src/classes/PBBLock.cls
PBB Delete: https://github.com/mshanemc/processBuilderBlocks/blob/master/src/classes/PBBDelete.cls
PBB Utility (dedupe): https://github.com/mshanemc/processBuilderBlocks/blob/master/src/classes/PBBUtilities.cls

Ohad’s String Utility

Written by Always Thinkin

July 8, 2017 at 6:54 pm

Posted in Uncategorized

Apex Workshop Webinar 7: Classes

leave a comment »

The video for the workshop session on Apex Classes can be found on YouTube here: https://youtu.be/7yLutQjwxnI

The triggers and their unit tests for practicing are available here:


Written by Always Thinkin

July 8, 2017 at 6:09 pm

Posted in Uncategorized