3

I'm using DX to pull a few objects/fields/custom MDTs/classes/triggers/profiles from an existing sandbox, to push into a scratch org. Everything is working fine, except that the profiles all fail:

PROJECT PATH                                                       ERROR
─────────────────────────────────────────────────────────────────  ────────────────────────── 
force-app/main/default/profiles/Admin.profile-meta.xml             invalid cross reference id 
force-app/main/default/profiles/Standard.profile-meta.xml          invalid cross reference id 
force-app/main/default/profiles/SolutionManager.profile-meta.xml   invalid cross reference id 
force-app/main/default/profiles/ReadOnly.profile-meta.xml          invalid cross reference id 
force-app/main/default/profiles/MarketingProfile.profile-meta.xml  invalid cross reference id

I've gotten to this point as follows:

  1. sfdx force:mdapi:retrieve -s -r ./ -k package.xml -u sourceorg
  2. unzip unpackaged.zip -d mdapipkg
  3. sfdx force:mdapi:convert --rootdir mdapipkg
  4. sfdx force:org:create -f config/project-scratch-def.json -a bkmc
  5. sfdx force:package:install -i 04tb0000000MXkF -u bkmc
  6. sfdx force:source:push -u bkmc

Step 5 installs a recent version of Declarative Lookup Rollup Summaries, as my package.xml includes some custom metadata from that package.

I want to get the CRUD/FLS for the objects/fields in the package setup correctly for the standard profiles, which is why I've included the profiles in my package.xml. I've reviewed the *.profile-meta.xml files, and confirmed they have no IDs (given the "invalid cross-ref" messages"). I've confirmed they only include objects, fields, and layouts which are present in my project. I even tried removing all of the <userPermission> elements from the profiles, thinking that there could be a mismatch between enabled features in my source and scratch orgs that could lead to a source org userPermission that isn't in the scratch org. I can't get any result beside "invalid cross ref".

Also tried pushing with --json to see if that returned any more info:

    {
        "error": "invalid cross reference id", 
        "fullName": "Admin", 
        "type": "Profile", 
        "filePath": "force-app/main/default/profiles/Admin.profile-meta.xml"
    }, 

Based on this answer to a question on a "cannot delete profile" error, I tried sfdx force:source:pull to get "clean" copies of the profiles (as seen by the scratch org) to try and find the issue, but it doesn't pull the profiles. I removed my local profile files and tried another pull, but it still didn't pull profiles.

How can I resolve the errors and push the profiles?

Update: forgot to add: in spite of the errors, all of my objects/fields/code/etc is pushed into the scratch org, but the profile CRUD/FLS is not. Once this happens, if I try to push the code again, I get the same "cross ref" errors for the profile, and I get "An unexpected error occurred. Please include this ErrorId if you contact support:..." errors for each class and trigger. At which point I can only delete the scratch org and lather/rinse/repeat.

3

I have been experiencing similar issues, and although I don't understand why it's happening in the first place, I have found that making a small change to each problematic profile within the scratch org, will allow me to pull these profile changes down locally. After this, pushing everything to the scratch org will work.

Use sfdx force:org:open to open the scratch org in the browser. Go to Setup, do some benign change to each profile that is generating the error(s). Then pull all of your changes down with sfdx force:source:pull. This will overwrite the local profile meta-xml files. After this, you can push everything to your scratch org.

If you wish, you can then undo the changes you made to the profile either in the scratch org (then pull changes) or locally in the xml file (then push changes).

Since I use Illuminated Cloud for development, I prefer this method over trashing and recreating a scratch org, as I find it less of a hassle to do quick profile changes in the scratch org than to change the org connection to my project and regenerate the appropriate offline symbol table for Illuminated Cloud.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.