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
Software EngineSoftware Engine 

Need help in writing Query - Urgent

Hi,
 
Account is the parent table for Opportunity and contacts.
 
My Driving object should be Opportunity.  How to get the contact details of FirstName,Lastname from Oppoortunity Object.
 
Select o.account.contact.firstname from opportunity o    // its giving error.
 
Thanks,
 
sfdcfoxsfdcfox
You need to use the OpportunityContactRoles table, or use account as the driving object. For example:

select id, name, (select id, contactid from opportunitycontactroles where isprimary = true) from opportunity where id = '003......'

select id, name, (select id, name from opportunities), (select id, firstname, lastname from contacts) from account where id = '001.....'

I hope this helps you out. Without more information, I don't know what else to offer for assistance with this query.

~ sfdcfox ~
Software EngineSoftware Engine

 

Hi,

  Thaks for yr reply. I should query from five tables.  Five Tables and their fields as follows.

  Table Name             Field
   ----------------          -----------
    Account                  Name
    Contact                   FirstName
    Campaign               CampaignCode
    Opportunity             CloseDate
    User                        RepID

   I not getting how to get the Firstname from contacts wtih Opportunity as Driving Object. Because where condition field is also from opportunity table

select  o.CloseDate,                                      // from Opportunity
            o.Account.Name,                               //  from Account
            o. ???                                                 //  FirstName from contacts  ??? 
            o.Owner.REPID__c,                         //   from User
            o.Campaign.Campaign_Code__c    //   from Campaign

from opportunity o where QA_Done__c = TRUE;

Can any body write a single query to get the result from the above 5 tables with a where a condition?

 

SuperfellSuperfell
Which contact(s) though? all contacts for the account, the contacts ascociated with the opportunity?, the contacts associated with the campaign. You can't work out the query until you understand exactly which dataset you're trying to obtain.
Software EngineSoftware Engine

 

It is the primary contact associated with Account.

 

SuperfellSuperfell
I don't beleive there's a standard way to track primary contact, so you'd need to find out exactly how that's being tracked in your particular organization setup.