Salesforce Community Bug with Experience Bundle and How to Solve It

Yitzchak Meirovich
Cloud Computing
June 9, 2020

Bug Link: You cannot deploy a Salesforce Community to a Sandbox containing LWC and Experiences folders in the same deployment package.

Tl;dr

You need to run two deployments, one with LWC and the other with Experiences. Each cannot have the other in the deployment. Use .forceignore to hide the folders during each deployment.

Current Salesforce Setup

sfdx-cli/7.58.2-937f666ed4 win32-x64 node-v10.15.3

Salesforce Spring ‘20

Api Version 48.0

Let’s Set the Stage

For several months I’ve been developing successfully with Salesforce Community using the *.site file in the siteDotComSites folder. As many may or may not know this file contains all site configuration, but it is not human-readable. Salesforce responded to the need to manipulate the site configuration programmatically by creating the Experience Bundle. It’s expected that you begin relying on the Experience bundle for making changes to your Community environment instead of or in addition to the Community Builder. In my situation, when I don’t know how or where to make the change in the Experience files I make the change in the Builder and pull the changes to my local environment. The Experience files are updated with the changes. Slowly, I’m learning what changes need to be made and where. 

What is confusing about this problem is that deployment to a development Scratch Org succeeds without issue. This bug only shows up when you are trying to deploy to the Dev Sandbox. 

If you deploy with both LWC and Experience folders in the package you may receive an error response such as the following:

 
  
"componentFailures": [
       {
         "changed": "false",
         "componentType": "ExperienceBundle",
         "created": "false",
         "createdDate": "2020-05-18T11:22:55.000Z",
         "deleted": "false",
         "fileName": "sdx_sourceDeploy_1589800918321/experiences/Employee_Portal_New1",
         "fullName": "Employee_Portal_New1",
         "problem": "An unexpected error occurred. Please include this ErrorId if you contact support: 783257549-153786 (-217057537)",
         "problemType": "Error",
         "success": "false"
       }
     ],
 


Don’t you love Salesforce’s very detailed error messages? :) It’s as clear as mud!

The solution lies in making two separate deployments, but it’s also how you make those deployments. 1) LWC must be deployed before Experiences. 2) .forceignore must exclude the relevant folder. 

In Azure Pipelines, our CICD system, I created a Build task to modify the .forceignore file and add the Experiences folder paths to the file before calling “sfdx deploy”. After the first deploy I modify it again and replace Experiences with LWC. Then I call deploy again. Remember, .forceignore tells the compiler what to IGNORE, not what to include. So, Experiences first means LWC is included and vice-versa on the second deployment. Here’s what it looks like. 

My .forceignore file has the following line at the bottom in VS Code.

 
  
# DO NOT ADD ANYTHING AFTER THIS LINE DUE TO CICD PROCESSING
#$ 

 


Why not include the path from your development environment? 

This is due to the human problem of forgetfulness. When I’m deploying to the Scratch Org in development there is no bug and if I include this in my unit testing I will forget to comment/ uncomment the line. Therefore, it is better to ignore the issue in development and handle it in the Build process.

I use “#$” as a placeholder for the Python task: 


 
  
#modify .forceignore experiences --> push lwc to Sandbox

import fileinput
import sys
 
def replaceAll(file,searchExp,replaceExp):
    with open(file, 'r') as fin:
        print(fin.read())
    for line in fileinput.input(file, inplace=1):
        if searchExp in line:
            line = line.replace(searchExp,replaceExp)
        sys.stdout.write(line)
 
replaceAll(".forceignore","#$","force-app/main/default/experiences")
with open(".forceignore", 'r') as fin:
    print(fin.read())

 


Notice I look for “#$” and replace it with the experiences folder path.

Then, in Powershell we call to validate our deployment:

 
  
#push lwc
sfdx force:source:deploy -p force-app -c -l $(testlevel) --loglevel error --json

 


Then I modify the .forceignore file again with another Python task:

 
  
#.forceignore lwc--> push experiences
 
import fileinput
import sys
 
def replaceAll(file,searchExp,replaceExp):
    with open(file, 'r') as fin:
        print(fin.read())
    for line in fileinput.input(file, inplace=1):
        if searchExp in line:
            line = line.replace(searchExp,replaceExp)
        sys.stdout.write(line)
 
replaceAll(".forceignore","force-app/main/default/experiences","force-app/main/default/lwc")
with open(".forceignore", 'r') as fin:
    print(fin.read())

 


I look for the experiences path and replace it with lwc.

I then deploy again in Powershell:

 
  
#push lwc
sfdx force:source:deploy -p force-app/main/default/experiences -c -l $(testlevel) --loglevel 
error --json

 


Here, I deploy only experiences. I can leave it as force-app, but it will take a little longer to deploy. If you try to deploy experiences WITHOUT modifying .forceignore it will not work. At least it didn’t for me. 


Hope Salesforce fixes this bug soon.

Happy coding!









Yitzchak Meirovich

AWS Authorized Instructor. Educating developers about the benefits of AWS Devops and Frontend web development

Keep Reading

Newsletter EuropeClouds.com

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form