Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:25:53+00:00 2026-06-12T05:25:53+00:00

I require a separate object which contains the related fields of a child object.

  • 0

I require a separate object which contains the related fields of a child object.

Currently I do it like this:

Opportunity opp = [SELECT Id, Name, Account.Id, Account.Name FROM Opportunity LIMIT 1];

Account acc = new Account(
    Id        = opp.Account.Id,
    Name      = opp.Account.Name
);

When working with a large related object I have to initialise many more fields than this and the script becomes very large and ugly.

What is the quickest way to initialise the related field data into a separate object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:25:54+00:00Added an answer on June 12, 2026 at 5:25 am

    You must define the all fields in your SOQL query (mor info here).

    But it is not necessary if you want to clone the object:

    Opportunity opp = [SELECT Account.Id, Account.Name 
                       FROM Opportunity 
                       LIMIT 1];
    
    Account acc = opp.Account;
    

    Example with Custom Object:

    Contract__c c = [ Select Account__r.FirstName 
                      From Contract__c 
                      Where Account__r.FirstName != null 
                      Limit 1];
    
    Account a = c.Account__r;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

require installed gems are not visible. Test with hpricot which I installed several times:
require 'coderay' puts CodeRay.scan('puts Hello, world!', :ruby).page This code will print full HTML page
Require a huge help here, since this is affecting our production instance. One of
I am developing android application which requires user to Login. This application relies on
Currently I am working on a problem which is implemented as a combination of
I was recently told that I should keep my code in separate files; like
I've read in DDD book (Eric Evans) that procedures which require to be used
I'd like to have a dojo grid which connects to a server url which
I have a model called MessagePerson which has the fields of details which depict
I have a data model which contains an array of Product objects. Before reporting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.