0

how to combine the two soql queries as asingle query?

 Contact con = [Select Id,Name,AccountId From Contact Where ContactId In (Select ContactId From User Where Id=:UserInfo.getUserId()];
 List<Opportunity> opp =[select Name,Amount from Opportunity where id=:con.AccountId];

Thanks,

This is my apex class :::


 Public class OpportunityDetails{

   Opportunity c = new Opportunity (); 
   public Opportunity getC(){ 
   return c;
  }

    public ApexPages.StandardSetController setCon {
        get {

            if(setCon == null) {
                setCon = new ApexPages.StandardSetController

               Here I'm going to place those two queries as a single soql query

               // (Database.getQueryLocator([select name,amount from opportunity where AccountId In (select accountId from Contact where Id =: UserInfo.getUserId())]));

           }
            return setCon;
        }
        set;
    }

   public List<Opportunity> getOpportunities() {

        return (List<Opportunity>) setCon.getRecords();
    } 
  • consider accepting the below answer, I believe it answers what you were attempting to do and it will help point others in the right direction should they have a similar question. Thanks – glls Nov 3 '17 at 14:48
0

These two query are on different object and Salesforce doesn't support query multiple object in single SOQL. So you can't do that.

If you want to search something you can use SOSL. It allows us to select multiple objects.

  • thanks for giving the reply and i'm trying to access salesforce opportunities in customer portal but customer portal licences are not having the opportunities access so is there anyway to access the opportunities. – sekhar Oct 12 '17 at 9:57
  • @sekhar use without sharing in class to query data and wrapper to display it on UI. – Tushar Sharma Oct 12 '17 at 9:58
  • I'm manually sharing the account object and giving the opportunities access for opportunities and added the portal users for accessing but in portal still it shows insufficient previligers.any idea on this – sekhar Oct 12 '17 at 9:59
  • @sekhar I don't think you can share opportunity with portal user. There license doesn't support it. – Tushar Sharma Oct 12 '17 at 10:01
  • Sharma is there any other way to access the opportunities? – sekhar Oct 12 '17 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.