# Mobile-name → Salesforce SObject name mapping

The local SQLite table name and the org SObject API name are related but rarely identical.

## Mapping rules (apply in order)

### Rule 1 — Exact match

Try `<TableName>` verbatim first. If the SObject exists, use it.

### Rule 2 — Append `__c`

Mobile `Visit` often corresponds to `Visit__c` in org. Try suffix `__c`.

### Rule 3 — Managed-package prefixes

Field sets for CG Mobile are frequently under a managed-package namespace. Common prefixes:

-   `retailexecution__<Name>__c` — Salesforce Retail Execution
-   `cg__<Name>__c` — CG industry package
-   `CGCloud__<Name>__c` — CG Cloud package

### Rule 4 — Fuzzy search

If none of the above match, list all SObjects containing the base word:

```bash
sf sobject list --sobject all --json | jq -r '.result[]' | grep -i "<base-word>"
```

Pick the most plausible match and confirm with the user before proceeding.

## Reverse mapping

When reading org metadata, strip the prefix/suffix to get the likely local table name:

-   `retailexecution__Visit__c` → `Visit`
-   `cg__Order__c` → `Order`
-   `Account` (standard SObject) → `Account`

## When no match exists

If no SObject matches the local table name under any rule, the table is:

-   A purely local/synthetic table (no org counterpart, normal for some context-menu DSs)
-   Or the org is disconnected from the mobility configuration

In either case, stop the org investigation and report back to the user.

## Example trace

Mobile DS references table `Visit`, column `CustomerRating__c`:

1. Rule 1: `sf sobject describe --sobject Visit` — typically fails for standard package visits
2. Rule 2: `sf sobject describe --sobject Visit__c` — may or may not match
3. Rule 3: `sf sobject describe --sobject retailexecution__Visit__c` — likely match
4. Found. Proceed to field check.
