Grit
  • Welcome
  • gritholdings SDK
    • API Reference
    • Collection of Useful Prompts
  • Evaluation
    • Evaluators
  • Concepts
  • LangChain
  • LangGraph
  • Agent Architectures
    • Planner-Worker-Solver
  • Prompt Management
  • Memory
  • Guardrails
  • Others
    • AWS
      • AWS CDK
    • Migrating a Service to Docker
    • React
    • Salesforce
      • Object Reference
      • Writing Apex
      • Experience Cloud
    • Grit API Reference
    • Style Guide for Documentation and User Interface Text
Powered by GitBook
On this page
  • Custom Objects
  • Creating New Custom Object
  • Renaming Custom Object
  • Deleting Custom Object
  • Custom Fields
  • Adding New Custom Field
  • Retrieving a field value from another lookup field
  • Add new field: Master-Detail Relationship
  • In Campaign Member Object, Status Field, how to change picklist value
  • Deleting Custom Field
  1. Others
  2. Salesforce

Object Reference

Custom Objects

Creating New Custom Object

  1. In scratch orgs, go to Setup → Object Manager. Click Create → Custom Object.

  2. Fill required fields, with the following optional:

    1. Allow Search

    2. Add notes and attachments

  3. Click on for Launch New Custom Tab Wizard after saving this custom object.

  4. Add the field in Setup -> Permission Set -> [PERMISSION_SET] -> Object Settings -> [OBJECT] , enable Tab Settings, Object Permissions.

  5. Click save

To create record page, use Highlight Panel and Tabs for the components.

Renaming Custom Object

  1. Backup the data in the current custom object

  2. Create a new custom object

  3. Push to prod

  4. Delete the old custom object in prod

If renaming custom object is performed in scratch orgs and then pushed to a prod, it will automatically delete the old object and replace with the new custom object. You will lose all data in the old object.

Deleting Custom Object

  1. Go to Permission Set, Profile, Tabs, then remove all checkmarks related to this Custom Object

  2. Pull the metadata using sf org pull --targetusername scratch

  3. Go to Setup - Object Manager - Click Object - Click Delete

  4. Pull the metadata again using sf org pull --targetusername scratch

  • You have to perform this for each of the custom objects.

  • If you perform delete object first before removing the other items such as Permission Set, Profile, Tabs, etc, you’ll get an error when you try to perform ./main.sh rebuild (it will show something like below):

=== Component Failures [2]
 Type  Name                                  Problem                                                              
 ───── ───────────────────────────────────── ──────────────────────────────────────────────────────────────────── 
 Error Example_Business Profile                 In field: field - no CustomObject named Specialty__c found           
 Error Example_Business_Customer_Community_User In field: field - no CustomObject named ExperienceSpecialty__c found
  • When you try to fix it by editing the codes directly from the source code, you’ll get an unexplained error (in this case, CustomObject1 app tab not showing up although everything else shows deployed successfully. To fix this, always use the UI to remove checkmarks, then perform sf pull.

Custom Fields

Adding New Custom Field

  1. Add new field through Setup -> Object Manager , choose name, field type, etc.

  2. Add the field in Setup -> Object Manager -> <OBJECT> -> Page Layouts. Use the drag and drop to input to details section.

  3. Save by performing sf pull to pull the metadata changes from scratch orgs to the codes in Git.

Retrieving a field value from another lookup field

  • Use formula field

  • Select Formula Return Type

  • Click on Advanced Formula, then Insert Field

  • You should be able to use lookup field value

Example usage: show percentage in Opportunity.Probability from Account.Type field

Add new field: Master-Detail Relationship

If A has multiple B , you need to add master-detail relationship from B.

In Campaign Member Object, Status Field, how to change picklist value

The Status field on the Campaign Member object cannot be updated using the Standard field. This is because the Campaign Member Status field is record-based, meaning its value can differ for each individual record. To resolve this limitation and update the Status field on Campaign Member records, follow these steps:

  • Go to Setup → Object Manager. Find or search for ‘Campaign’ → Find ‘Page Layouts’ in the sidebar → click to edit the ‘Campaign Layout’.

  • Scroll down the list to find “Related Lists.” Drag the “Campaign Member Status” related list onto the page. Then save.

  • When you create a Salesforce Campaign, you don’t need to create Campaign Member Statuses because there are two default Campaign Member Statuses: Sent and Responded. You can use or modify these, or create additional ones to suit your campaign needs. To edit an existing status, use the dropdown arrow and click on the Edit option.

The custom solution for updating the Status field on Campaign Member records will not be saved in the metadata. This is because the Status field is record-based, meaning its values are stored at the individual record level rather than being defined in the object's metadata.

To ensure consistency across all Campaign Member records and maintain a standardized set of status values, consider automatically setting the default value of the Status field to Planned whenever a new Campaign is created.

Deleting Custom Field

  1. In scratch org, go to Object Manager → Custom Object → Fields → Click Delete → Confirm Delete. Then, perform sf pull.

  2. In prod, go to Object Manager → Custom Object → Fields → Click Delete → Confirm Delete

When applying updates using the Salesforce CLI (sf) command, keep in mind that custom fields in production orgs are not automatically deleted, even if they are removed from the page layout. To completely remove a custom field from a production org, you must manually delete it after running the sf command to apply the update.

PreviousSalesforceNextWriting Apex

Last updated 12 months ago