forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

sf project retrieve start --metadata 'CustomField:<namespace>__*' doesn't retrieve customfields from standard objects #3052

Open rmartinez1ffdc opened 1 month ago

rmartinez1ffdc commented 1 month ago

Expected result

Custom fields with the specified namespace to be retrieved. Relevant standard object and field directories to be created under the objects folder if they don't exist yet.

E.g: "project/main/default/objects/Account/fields/mycustomfieldnspc.field-meta.xml"

Actual result

"Preparing retrieve request... done Nothing retrieved"

Additional information

When I try to retrieve the customfields created on standard objects by a managed package, the command sf project retrieve start --metadata 'CustomField:<namespace>__*' returns Nothing retrieved

It forces me to adjust the command to specify the standard object names in this way:

sf project retrieve start --metadata 'CustomField:<standardObjectName>.<namespace>__*'

E.g: sf project retrieve start --metadata 'CustomField:Account.c2g__*'

That solution is not aligned with the general behaviour of the --metadata flag. The documentation doesn't mention it neither.

Since I'm building a process to retrieve those custom fields (among other metadata) from different org types, with different versions of the packages, I can't really know in advance all the standard objects with custom fields created by the managed package on them.

Running the retrieve command with all the possible standard objects names in the org is possible and works well according to our tests, but it takes around 10 minutes and is an unnecessary overload.

System Information

CLI:
@salesforce/cli/2.61.8 darwin-arm64 node-v21.6.2

Plugin Version:
@oclif/plugin-autocomplete 3.2.5 (core)
@oclif/plugin-commands 4.0.16 (core)
@oclif/plugin-help 6.2.13 (core)
@oclif/plugin-not-found 3.2.22 (core)
@oclif/plugin-plugins 5.4.10 (core)
@oclif/plugin-search 1.2.10 (core)
@oclif/plugin-update 4.5.10 (core)
@oclif/plugin-version 2.2.14 (core)
@oclif/plugin-warn-if-update-available 3.1.18 (core)
@oclif/plugin-which 3.2.15 (core)
@salesforce/cli 2.61.8 (core)
apex 3.5.0 (core)
api 1.2.2 (core)
auth 3.6.65 (core)
data 3.6.8 (core)
deploy-retrieve 3.12.15 (core)
info 3.4.9 (core)
limits 3.3.32 (core)
marketplace 1.2.26 (core)
org 4.6.0 (core)
packaging 2.8.10 (core)
schema 3.3.34 (core)
settings 2.3.23 (core)
sobject 1.4.40 (core)
source 3.5.21 (core)
telemetry 3.6.15 (core)
templates 56.3.21 (core)
trust 3.7.32 (core)
user 3.5.32 (core)
SF ENV. VARS.
SF_AUTOUPDATE_DISABLE,true
SF_DISABLE_AUTOUPDATE,true
SF_UPDATE_INSTRUCTIONS,Use "npm update --global @salesforce/cli" to update npm-based installations.
Windows: false
Shell: zsh
Channel: stable

Diagnostics

:white_check_mark: pass - salesforcedx plugin isn’t installed :white_check_mark: pass - you don't have any linked plugins :white_check_mark: pass - [@salesforce/plugin-deploy-retrieve] sourceApiVersion matches apiVersion :white_check_mark: pass - [@salesforce/plugin-trust] can ping: https://registry.npmjs.org :white_check_mark: pass - [@salesforce/plugin-trust] can ping: https://registry.yarnpkg.com :white_check_mark: pass - [@salesforce/plugin-trust] can ping: https://artifactory.dev.financialforce.com/artifactory/api/npm/ffdc-npm :white_check_mark: pass - using latest or latest-rc CLI version :white_check_mark: pass - can access: https://test.salesforce.com :white_check_mark: pass - can access: https://appexchange.salesforce.com/services/data :x: fail - [@salesforce/plugin-auth] CLI supports v2 crypto :white_check_mark: pass - can access: https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-win32-x64-buildmanifest

mdonnalley commented 1 month ago

@rmartinez1ffdc I think you're right that this needs to be addressed. I'll mark it as a bug

As for a workaround, have you tried `sf project retrieve start --metadata 'CustomField:*'. From my testing locally that will give you all the fields on a standard object:

❯ sf project retrieve start --metadata 'CustomField:Account*'
Retrieving v61.0 metadata from test-xolxqlblsmay@example.com using the v62.0 SOAP API
Preparing retrieve request... Succeeded

Retrieved Source
==============================================================================================================================
| State   Name                      Type        Path
| ─────── ───────────────────────── ─────────── ──────────────────────────────────────────────────────────────────────────────
| Changed Account.AccountNumber     CustomField force-app/main/default/objects/Account/fields/AccountNumber.field-meta.xml
| Changed Account.AccountSource     CustomField force-app/main/default/objects/Account/fields/AccountSource.field-meta.xml
| Changed Account.AnnualRevenue     CustomField force-app/main/default/objects/Account/fields/AnnualRevenue.field-meta.xml
| Changed Account.BillingAddress    CustomField force-app/main/default/objects/Account/fields/BillingAddress.field-meta.xml
| Changed Account.CleanStatus       CustomField force-app/main/default/objects/Account/fields/CleanStatus.field-meta.xml
| Changed Account.DandbCompanyId    CustomField force-app/main/default/objects/Account/fields/DandbCompanyId.field-meta.xml
| Changed Account.Description       CustomField force-app/main/default/objects/Account/fields/Description.field-meta.xml
| Changed Account.DunsNumber        CustomField force-app/main/default/objects/Account/fields/DunsNumber.field-meta.xml
| Changed Account.Fax               CustomField force-app/main/default/objects/Account/fields/Fax.field-meta.xml
| Changed Account.Industry          CustomField force-app/main/default/objects/Account/fields/Industry.field-meta.xml
| Changed Account.Jigsaw            CustomField force-app/main/default/objects/Account/fields/Jigsaw.field-meta.xml
| Changed Account.NaicsCode         CustomField force-app/main/default/objects/Account/fields/NaicsCode.field-meta.xml
| Changed Account.NaicsDesc         CustomField force-app/main/default/objects/Account/fields/NaicsDesc.field-meta.xml
| Changed Account.Name              CustomField force-app/main/default/objects/Account/fields/Name.field-meta.xml
| Changed Account.NumberOfEmployees CustomField force-app/main/default/objects/Account/fields/NumberOfEmployees.field-meta.xml
| Changed Account.OperatingHoursId  CustomField force-app/main/default/objects/Account/fields/OperatingHoursId.field-meta.xml
| Changed Account.OwnerId           CustomField force-app/main/default/objects/Account/fields/OwnerId.field-meta.xml
| Changed Account.Ownership         CustomField force-app/main/default/objects/Account/fields/Ownership.field-meta.xml
| Changed Account.ParentId          CustomField force-app/main/default/objects/Account/fields/ParentId.field-meta.xml
| Changed Account.Phone             CustomField force-app/main/default/objects/Account/fields/Phone.field-meta.xml
| Changed Account.Rating            CustomField force-app/main/default/objects/Account/fields/Rating.field-meta.xml
| Changed Account.ShippingAddress   CustomField force-app/main/default/objects/Account/fields/ShippingAddress.field-meta.xml
| Changed Account.Sic               CustomField force-app/main/default/objects/Account/fields/Sic.field-meta.xml
| Changed Account.SicDesc           CustomField force-app/main/default/objects/Account/fields/SicDesc.field-meta.xml
| Changed Account.Site              CustomField force-app/main/default/objects/Account/fields/Site.field-meta.xml
| Changed Account.TickerSymbol      CustomField force-app/main/default/objects/Account/fields/TickerSymbol.field-meta.xml
| Changed Account.Tier              CustomField force-app/main/default/objects/Account/fields/Tier.field-meta.xml
| Changed Account.Tradestyle        CustomField force-app/main/default/objects/Account/fields/Tradestyle.field-meta.xml
| Changed Account.Type              CustomField force-app/main/default/objects/Account/fields/Type.field-meta.xml
| Changed Account.Website           CustomField force-app/main/default/objects/Account/fields/Website.field-meta.xml
| Changed Account.YearStarted       CustomField force-app/main/default/objects/Account/fields/YearStarted.field-meta.xml
git2gus[bot] commented 1 month ago

This issue has been linked to a new work item: W-16959563

rmartinez1ffdc commented 1 month ago

Hi @mdonnalley Yes, that would retrieve the custom fields but also any other not related to the namespace we need.

We have applied another workaround by specifying the name of the standard object since for our use case we need to be able to filter what we retrieve by namespace.

Thanks for considering this issue that quickly

agarciaodeian commented 2 days ago

Hi @mdonnalley, Do you have an expected date to work on this bug? This is also affecting me and my team. Thanks!