Everything You Need to Know about Custom Objects

Introduction

Salesforce’s custom objects are an administrator’s best friend, and the common acquaintance of the developer as well. Naturally, one of the great capabilities of Salesforce is its extensibility and customizability (is this a word?). There’s probably no better example of this extensibility than custom objects; being able to define a new database with all of its columns using only clicks and in a pretty user-friendly manner.

Video Breakdown

However, to properly create a custom object, you’ll need to understand the basic steps required – these steps include:

  • Creating the object and its tab and making them available to users and within apps
  • Making custom fields, relating to other objects in the system, and setting up field tracking, if necessary
  • Creating list views and page layouts and confirming that related objects have related lists, if necessary
  • Integrating this custom object into workflows, processes, and logic — this, for example, could include using SOQL, Apex, or the REST API
Lookup vs. Master-Detail

I chose to give Opportunity and Invoice objects a master-detail relationship (and not a lookup).

I chose to do this because I want my invoices to be closely related to their parent opportunities, given that the invoices will be “bills” to that same customer. Because of this, in the video I mention that they’re intrinsically related; if I delete an opportunity, I probably don’t need to keep those invoices sitting around as they would if they were related by a lookup.

At the same time, I did choose to allow reparenting of invoices in the case that for some administrative reason I need to create a new Opportunity to replace the old, I don’t want to lose the related invoice history.

Code Snippets FROM THE VIDEO

SOQL Query

SELECT Id, Name, Payment_Date__c, Amount__c, Status__c FROM Invoice__c WHERE Type__c = 'Incoming'

Apex Insert

Invoice__c newInvoice = new Invoice__c(
    Payment_Date__c = Date.Today(),
    Type__c = 'Incoming',
    Status__c = 'Sent',
    Amount__c = 250.00,
    Opportunity__c = '0061I000003cBem'
);

try {
    insert newInvoice;
} catch (Exception e) {
    System.debug(e.getMessage());
}

REST Endpoint URL

/services/data/v43.0/sobjects/Invoice__c

HTTP POST Request JSON Body

{
  "Payment_Date__c" : "2018-06-16",
  "Type__c" : "Incoming",
  "Status__c" : "Sent",
  "Amount__c" : 50.0,
  "Opportunity__c" : "0061I000003cBem"
}

That’s all! Hope this was helpful.

1 comment

  • I am a newbie to SalesForce coming from a different technology. I had seen your YouTube video on Formula Fields and came to your blog from its link. Where can I get more examples for statements like “CASE” or the usage of Picklist.

    I am not able to add picklist values where Display text and API values are different. I end up adding and then editing API value later. I am also not able to find out how to add new values to an existing Picklist. Is there a standard developer guide link you can share for such issues? Thanks a lot!

Recent Posts

Categories