logo
MENUMENU
  • Services
        • Salesforce

        • Salesforce OverviewWe help our clients to make the most out of their technology investments.
          • Salesforce Overview
          • Systems Integration
          • Managed Services
          • Field Service Lightning
          • Salesforce CPQ
        • Verint

        • Verint OverviewOur services cover Implementations, Upgrades, Migrations, Reporting Solutions & Application Support.
          • Verint Overview
          • Verint Knowledge Management
          • Verint KM Integrations
          • Verint Omni-Channel
          • Verint Unified Desktop & Case Management
          • Verint Workforce Optimization
          • Verint Intelligent Virtual Assistant
          • Verint Robotic Process Automation
        • Artificial Intelligence

        • Artificial Intelligence
          • AI Overview
          • Data Engineering
          • Analytics/BI
          • Predictive Analytics
          • Computer Vision
          • Natural Language Processing (NLP)
          • ML Ops
        • Cloud & Mobile Apps

        • Cloud & Mobile App Development OverviewOur services cover Implementations, Upgrades, Migrations, Reporting Solutions & Application Support.
          • Cloud & Mobile App Development Services
        • Let’s Get
          Started.

        • Let’s talk about how SPAR Solutions
          can positively impact your business.

        • START TODAY
  • Company
    • About Us
    • Why Work At SPAR
  • Resources
    • Blog
    • Case Studies

GET STARTED 1-855-772-7765

GET IN TOUCH
  • Services
    • Salesforce Overview
      • Salesforce Overview
      • Systems Integration
      • Managed Services
      • Field Service Lightning
      • Salesforce CPQ
    • Verint Overview
      • Verint Overview
      • Verint Knowledge Management
      • Verint KM Integrations
      • Verint Omni-Channel
      • Verint Unified Desktop & Case Management
      • Verint Workforce Optimization
      • Verint Intelligent Virtual Assistant
      • Verint Robotic Process Automation
    • Artificial Intelligence
      • AI Overview
      • Data Engineering
      • Analytics/BI
      • Predictive Analytics
      • Computer Vision
      • Natural Language Processing (NLP)
      • ML Ops
    • Cloud & Mobile App Development Overview
      • Cloud & Mobile App Development Services
  • Company
    • About Us
    • Why Work At SPAR
  • Resources
    • Blog
    • Case Studies

Object Composition on Force.com

Home > Force.com Development > Object Composition on Force.com

Object Composition on Force.com

December 3, 2015

Most programmers coming from a standard object oriented programming programming language like Java, C#, C++ etc. are used to working with composite objects. For e.g. an Account object will contain a list of associated Contacts and Cases. A Project object will have a list of associated tasks.

When you start working with the Force.com platform, the behavior of objects for both standard and custom objects is not what you would intuitively expect. If you query the system with the right SOQL queries, you will be able to get back a composite object. On the contrary, if you instantiate a new parent object instance, the associated child objects do not automatically show up in there.

This confounds new developers when they start writing custom code with Apex. Let us say that you have a situation where you have to collect a list of parent and child objects from the user or a bulk load process, and then persist them to the database. The inability to instantiate composite objects that represent your data model will force you to collect each object in a separate set of lists and save each list separately, while taking care to set the parent lookup ids for each object correctly.

The way to solve this on the Force.com platform is to use “wrapper classes”. You can define a wrapper class in Apex that is a composite of the parent object and it’s related list of child objects. For e.g., AccountWrapper would be a class that contains the parent Account object instance and a list of associated contacts and cases, or ProjectWrapper would contain the parent Project instance and it’s related Tasks list.

This approach allows you to instantiate an object that represent the account or project parent object and it’s related lists that simulates what you are used to with object composition on other platforms. The work of mapping account ids to it’s associated contacts and cases is no longer a set of for loops that can be prone to programming errors.

Swami Ganapathy
+ posts
  • Swami Ganapathy
    https://sparsolutions.com/author/sparwpadmin/
    SPAR’s Commitment to Diversity, Equality and Inclusion
  • Swami Ganapathy
    https://sparsolutions.com/author/sparwpadmin/
    A Complete Guide to Salesforce Field Service Lightning
  • Swami Ganapathy
    https://sparsolutions.com/author/sparwpadmin/
    Salesforce CPQ - Key features overview
  • Swami Ganapathy
    https://sparsolutions.com/author/sparwpadmin/
    Salesforce.com – Overcoming Apex code limits

Filed Under: Force.com Development, Salesforce.com

Search

Categories

  • Apex Testing
  • Big Data
  • Force.com Development
  • General
  • Healthcare
  • Highlighted
  • How to
  • Integration
  • Knowledge Management
  • Salesforce Field Service Lightning
  • Salesforce.com
  • SFDCHighlights
  • Uncategorized

Archives

  • September 2021
  • August 2021
  • June 2021
  • May 2021
  • March 2021
  • January 2021
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • March 2019
  • June 2017
  • December 2016
  • June 2016
  • December 2015
  • November 2015
  • October 2015
  • July 2015
  • February 2015
  • January 2015
  • October 2013
  • February 2013
  • January 2013
  • December 2012

Ready to Get Started?

Let’s talk about how SPAR Solutions can help you drive greater automation

Get in Touch

Ask us how to get started today.

SPAR Solutions logo

Terms of Service

OFFICE

375 Northridge Rd
Suite #400
Atlanta, GA 30350

CALL US

1-855-772-7765

Copyright © 2020, All Rights Reserved by SPAR Solutions. Digital Marketing by