In preparation for the CzechDreamin Pawel asked me to help him with preparation of 40 Field Service Lightning (FSL) instances. No problem, the guide has just 12 pages and I’m super lazy, luckily I heard about Salesforce DX.
1. Authenticate to instances
This was the most manual step as I had to login into each instance.
sfdx force:auth:web:login -a fslX
where X is number from 1 to 40.
2. Create a batch
Second step is old good bat file, which will run my commands on each instance.
for /L %%A IN ( 1, 1, 40) DO (
sfdx %1 %2 %3 %4 %5 -u fsl%%A
The for cycle starts at 1, has increment of 1 and finish at 40, will take first 5 arguments from command line and run them as sfdx parameters on specific instance (-u fsl%%A where %%A is the number).
I saved this file as run.bat.
3. Install package
First step in configuration is easy, install a package.
run.bat force:package:install --package packageId
where I got the packageId from the installation link (04txxxx).
4. Download data from referential instance
Pawel configured one instance as an example, from which I could take metadata. The good approach is download only metadata you need to push, but I found out it is easier to download all of them and copy those I need to separate directory to push them to instance.
First of all I had to create the package.xml file. At VS Code you can use the extension for generating it, but I used the old good Package Builder and saved the package.xml file in a root of my DX project.
run.bat force:source:retrieve -x pathToPackageXML
I went through the data directory, created a new folder and copied what I would need – permission sets, object definitions (because there is sharing and feed tracking set), custom fields and fields which has to be tracked (because it is enabled on field level), quick actions, layouts (which includes page layouts and global layout) and profiles.
Sadly, the profiles are super tricky. If you download them as part of the whole package they are downloaded completely, would you use -m Profiles switch it won’t include the page layout assignment definition (and most likely other things as well).
5. Permission Sets
You copied the permission sets to your new folder and just push them in the instance.
run.bat force:source:deploy -p pathToNewFolder
And then you assign them to the one user you have there (I had to run it several times for each permission set I had there):
run.bat force:user:permset:assign --permsetname 'permSetName'
6. Limit sharing on objects
Sharing is set on the object definition file, which is in the objects/objectName directory. If you already copied all those needed file in the directory you already pushed them to your instance. If not, copy now and use our best command
run.bat force:source:deploy -p pathToNewFolder
7. Enable feed tracking
The previous step also enabled the feed tracking on object, just didn’t enable it on specific field. Copy the specific field to your directory and deploy.
It is habit by now, you could compressed it all in one deploy.
8. Page layout assignment
I failed on this one. The assignment is done in profiles, I downloaded them with all the metadata, but DX doesn’t download metadata from managed package, so it doesn’t even download the relation to them in other metadata (like assignment in profiles).
Would you add the reference manually and deploy, nothing will happen.
Eclipse saved me – at least I thought so – as I was able to use it to download the metadata of managed package, copy it to my directory, change all names of referenced component to include the package name and successfully add it to profile and deploy.
Sadly it deployed the page layouts as well as another copy with the same name, which created a bit of mess.
9. Custom fields & actions
Just copy them to your directory and deploy. For global actions I also had to deploy global layout.
10. Update Data Integration Rules
The other request was to update Data Integration Rules to bypass triggers. I was able to download them but never upload them back, even without changing anything.
Object Name: The Field Mapping API Name can only contain underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.
It took me a while to figure all of that (as I did it for the first time) and then I look back, proud and had a simple question – why didn’t I create sandboxes? It would be way easier.
But doesn’t matter, I learnt more where the things are set and I feel I can use this in future for a few things. DX is simple, I used about 5 commands all together, the most important part was to find out where all the settings are stored.
Indeed, the training orgs are Enterprise licences, not developer. However now, every attendee holds his/her own training org which they can now use to continue learning. Thanks for the guide how you did it – not sure if I would be able to repeat all these steps myself. Good learning though