0

I am freshman in salesforce dev. but, today, i am facing a little issue. i want query all account address record and insert to new object.

i have following query:

for account: SELECT Name FROM Account

for address: SELECT Account_vod__c, Name, Address_line_2_vod__c FROM Address_vod__c

but, i don't know that how to join two sqls in one?

if you konw it, please tell me that how to do this?

Many thanks

5
  • Is there a relationship between the Account object and the Address_vod__c object? If so, what is the name of that field?
    – Mark Pond
    Commented Jul 5, 2013 at 16:25
  • Account_vod__c in address object and this is account id. when i create new address, account_vod__c need to look up account object.
    – yutaolife
    Commented Jul 5, 2013 at 16:28
  • @MarkPond if address and account no relationship, how to write the soql?
    – yutaolife
    Commented Jul 5, 2013 at 16:30
  • Is the type of the Account_vod__c field a Lookup or Master-Detail or just Text?
    – Mark Pond
    Commented Jul 5, 2013 at 16:38
  • Account_vod__c Data type is Master-Detail(Account)
    – yutaolife
    Commented Jul 5, 2013 at 16:43

1 Answer 1

2

What you are performing here is a relationship query. The documentation about relationship queries can be found here: Force.com SOQL and SOSL Reference: Relationship Queries I would highly suggest reading the documentation to get a better understanding of the syntax to perform this type of query and how to work with the results.

Each Account will have a List<Address_vod__c> children under it which you can access using the relationship syntax.

Your query for an Account with it's child Address_vod__c records will likely look like this:

List<Account> accounts = [SELECT Id
                            , Name
                            , (SELECT Id
                                    , Account_vod__c
                                    , Name
                                    , Address_line_2_vod__c 
                                    FROM Address_vod__r)
                            FROM Account
                            LIMIT 10];

// iterate over the Accounts
for (Account a : accounts) {
    system.debug('Account: ' + a);

    // iterate over the Address_vod__c records under the Account 
    // using the relationship syntax
    for (Address_vod__c addressVOD : a.Address_vod__r) {
        system.debug('Address VOD: ' + addressVOD);

    }
}
1
  • Many thanks @MarkPond. i will read that document. Many Many thanks.
    – yutaolife
    Commented Jul 5, 2013 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .