function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel Chirinos 6Daniel Chirinos 6 

Using sfdx source to retrieve profiles inconsistent result

Hello, I'm using salesforce cli to run basically "sfdx force:source:retrieve -m Profile:Admin", which I know technically sfdx is not that much compatible with profiles but, on a sandbox on a project, I got the object permissions and all that, but running that command on other sandboxes and my developer org brings only the user permissions, is that related to some org config or something? I'd love to know because I kinda like to use sfdx source for all I can.

 

Thanks in advance, hope someone can help me out on this

ShivankurShivankur (Salesforce Developers) 
Hi Daniel,

To retrieve specific profiles you can always use the sfdx command source:retrieve as follows:
sfdx force:source:retrieve -m "Profile:My Profile, Profile: AnotherProfile"
However, the metadata or setting for profile in different org could be different and so is the behavior you see.

Please refer to the standard documentation here:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_source.htm

Hope above information helps. Please mark as Best Answer so that it can help others in future.

Thanks.
Daniel Chirinos 6Daniel Chirinos 6

Yeah but like the main difference in my issue is not that the metadata should be exactly same, but that it brings different "sections" so to speak, retrieving Profile in one sandbox retrieves ObjectPermission tag(with the objects of that sandbox), and doing so in another one, does not even bring the tag, so I'm curious as I'm sure is a sandbox thing but don't know what. 

Igor Kudryk 15Igor Kudryk 15
Facing the same problem. The retrieving of metadata for profiles just breaks actually the file and git goes crazy. But there is actually nothing bad about doing manually some steps like this, without sfdx. So my solution is simply to add the object permissions manually after deployment :D Btw did you manage to solve the issue?
Daniel Chirinos 6Daniel Chirinos 6
Yeah haha I always end up writing the changes manually, but was just really curious about why would it behave so differently, haven't been able to figure out what could it be. If I ever do I'll update this hahahaha
Júlio LimaJúlio Lima
Did you have checked the version of each sanboxes. Other thing would be something related to what are current profile permissions in each sandbox. I think that in the Salesforce black box if something was set for the first time in a profile, behind the scenes Salesforce creates a base metadata. A test to confirm would be create 2 new sandboxes from production, do nothing about metadata and retrieve profile metadata through sfdx. If even in this moment the profile metadata are diferent from each sanbox, I have no idea. BUT, if is the same, try to change a permission in a object directly in one SB e try to retrieve and check if the whole metadata is so diferent.
Daniel Chirinos 6Daniel Chirinos 6
Just as an update, it seems by now on the newest versions it's consistent that it retrieves all references of the profile, so I guess this is fine now :) hopefully it's like that for everybody else
Rajat Burman 6Rajat Burman 6

Hi Daniel,
Just curious to know how were you able to retrieve all references of profiles using sfdx, I have been trying this since long and ending up doing it manually.
 

Daniel Chirinos 6Daniel Chirinos 6
Hello! I've just right click retrieved the profile if I have the file already, or "sfdx force:source:retrieve -m Profile:profileName" it's been giving me all references (or at least I can't see any expected things not being retrieved, granted it doesn't give something like managed package objects in my case), but in the end honestly depending on the case I do it manually, if I add just field permissions I rather do it manually and deploy than do it in UI and retrieving.
Marek Smerak (TH)Marek Smerak (TH)
Hi, it depends if the org/sandbox use source tracking or not. Without source tracking only permissions to metadatat listed in package.xml (or retrived in the same retrieve operation) are included in profiles metadata. But if source tracking is enabled, SFDX keep track of changes in the org/sandbox and when doing retrieve permission for these metadata is also included in retrieved profiles. Please see https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_source_tracking_source_tracking_profiles.htm and https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_setup_enable_source_tracking_sandboxes.htm