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
Pierre MICELIPierre MICELI 

Help on a SOQL formula

Hi all,

I'm not a regular SFDC user, and I've never used SOQL. However I need to create a simple query but I can't find the right formula. I read a lot on the topics but the more I read the more I'm confused.

If you can help, it will be great.

I just want to retreive 4 fields : 2 from Opportunity table and 2 from Campaign table. In Opportunity table there is primary key 'CampaignId' which links the 2 tables. I need to retreive opportunitites 'Stage' and 'Amount' with the camapign 'name' and campaign 'type'. As you guess, campaign name & campaign type are available on campaign table only.

That's where I'm stuck on the SOQL.

I can't put the righ ones on the right order.. between select, child parent etc.

Is there a generous soul to help me here ? 

thanks !!









 
Best Answer chosen by Pierre MICELI
nagendra 6989nagendra 6989

 Hi Pierre MICELI,

As i understand you want to retrieve four fields 2 from opportunity and 2 from campaign sobject.

If you want to retrieve any respective fields from parent object then directly you can give the field name and the respective sobject name as below.

[select name,amount,stagename from opportunity];

As campaign is a child of opportunity if you want to retrieve any of the child fields you can just simply use the dot(.)notation as below.

[select Campaign.name,Campaign.status from opportunity];

The SOQL query to retrieve two fields from opportunity(parent) and two fields from campaign(child) can be as below

[select name,amount,stagename,campaign.name,campaign.type from opportunity];

Please let me know if it helps you.......

Thanks & Regards,
Nagendra.p
9848950830

All Answers

ManojjenaManojjena
HI Plerre,

You can try like below .
 
Select Name,StageName,Campaign.Name,Campaign.Status FROM  opportunity
Here Name and stageName are opportunity fields .if you need to pull any campaign fields then you need to add campaign,fieldapi name .

Let me know if it helps !!
Thanks
Manoj
 
nagendra 6989nagendra 6989

 Hi Pierre MICELI,

As i understand you want to retrieve four fields 2 from opportunity and 2 from campaign sobject.

If you want to retrieve any respective fields from parent object then directly you can give the field name and the respective sobject name as below.

[select name,amount,stagename from opportunity];

As campaign is a child of opportunity if you want to retrieve any of the child fields you can just simply use the dot(.)notation as below.

[select Campaign.name,Campaign.status from opportunity];

The SOQL query to retrieve two fields from opportunity(parent) and two fields from campaign(child) can be as below

[select name,amount,stagename,campaign.name,campaign.type from opportunity];

Please let me know if it helps you.......

Thanks & Regards,
Nagendra.p
9848950830
This was selected as the best answer
Pierre MICELIPierre MICELI
Hi Nagendra & Manoj

You made my day !
Yes it works, and by reading your answers, it was quite simple... I was looking for a more complex solution trying to recreate links between tables. So everything is fine now.

thanks again