function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dr.tDr.t 

How do I get the data from reference Objects?

Just now, i m developing the tool which can search some data from salesforce objects data by VBA.

 

I wanna join some tables, but we cannot join some object by SOQL.

So, I try to write the code like below

 

 

sid = "SELECT companyCode__r.Name, companyName__c FROM PaymentRequest__c"
    Set qr = sfApi.query(sid, False)
    For Each v In qr
        Set s = v
        Set sop = s.GetJoinResults("companyMaster__c")
        Worksheets("test").Range("A1").Cells(irow, 2 + (ci + ci - 1)).value = s("companyName__c ")
        Worksheets("test").Range("A1").Cells(irow, 2 + (ci * 2)).value = sop("Name")
        ci = ci + 1
        irow = irow + 1
 Next

 

 

 

companyMaster__c is refered from PaymentRequest__c  by companyCode__c.

But i couldnt get the value of "companyCode__r.Name", and get error message like "Did not set with block variables".

 

How do I get companyCode__r.Name value.

 

Is anyone figure out this?

Please help me...

cactusdavecactusdave

Here is an example of how we have SOQL'ed combining the account and contact objects successfully:

 

// Query the Contact Objects getting data from Account as well
Map<Id, Contact> entries = new Map<Id, Contact>([select Id, accountid, account.AccountNumber, account.Site,  Email from Contact where id in :contactids]);

 

As you can see the ID, Accountid, and Email come from the contact. The AccountNumber and Site come from the Account Object. I hope this helps.