+ Reply to Thread
Results 1 to 4 of 4

Thread: Select from two tables

  1. #1
    lachof is offline Junior Member
    Join Date
    Nov 2007
    Posts
    10

    Question Select from two tables

    Hello all!

    I am trying to get the product and standard price but i only get the ID value.

    Here is the code:

    PHP Code:
    public function GetProductDescriptionAndPrice($ProductId)
            {                       
                
    session_start();
                
    $location $_SESSION['location'];
                
    $sessionId $_SESSION['sessionId'];
                
    $wsdl $_SESSION['wsdl'];
                
    $username $_SESSION['usr']; 
                
    $password $_SESSION['pwd']; 
                
    session_write_close();   
            
                
    $client = new SforcePartnerClient();
                
    $sforceSoapClient $client->createConnection('../'.$wsdl);
                
    $client->setEndpoint($location);
                
    $client->setSessionHeader($sessionId);
                
    $loginResult $client->login($username$password);
                
                
    //Get Description and Price
                
    $query "SELECT Id, Name, Family, IsActive, Description, ProductCode,  (SELECT  UnitPrice FROM PricebookEntries) FROM Product2 where id = '".$ProductId."'";
            
                
    $queryResult $client->query($query);
                
    $records $queryResult->records;    
                
                
    $counter 0;
                foreach (
    $records as $record
                {                
                    
    $sObject = new SObject($record);        
                    
    $Id $sObject->Id;
                    
    $Name $sObject->fields->Name;
                    
    $Description $sObject->fields->Description;
                    
    $ProductCode $sObject->fields->ProductCode;                                
                    
    $qr $sObject->queryResult[0]->records;                    
                    foreach (
    $qr as $record2
                    {
                            
    $UnitPrice =  $record2->fields->UnitPrice;
                    }
                    
    $counter++;           
                }
                
    $ProdArr = array();
                
    $ProdArr['Description'] = $Description;
                
    $ProdArr['UnitPrice']= $UnitPrice;
                
    $ProdArr['Id']= $Id;    
                return 
    $ProdArr;
            } 
    What am i doing wrong?
    Is there a better way to do this?


    Thnx in advance!!
    lachof.

    "So crucify the ego, before it's far too late
    To leave behind this place so negative and blind and cynical,
    And you will come to find that we are all one mind
    Capable of all that's imagined and all conceivable.
    Just let the light touch you
    And let the words spill through
    And let them pass right through
    Bringing out our hope and reason ...
    before we pine away"
    Tool.Lateralus.Reflection

  2. #2
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Isn't it PriceBookEntry, Not pricebookentries

    ALSO have you tried your SOQL in the Data Loader to make sure it works or the sforce_explorer @ sforce @ sourceforge to see if it works? I use it for SOQL to make sure it works before I code it into a script

    ~Mike

  3. #3
    lachof is offline Junior Member
    Join Date
    Nov 2007
    Posts
    10

    Exclamation

    Thnx for your response Mike.

    I use Apex Explorer 8.0 and strangely the query works as posted. If i chnage the query to select form priceBookEntry i get this error:

    Didnt Understand relationship 'PriceBookentry' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropiate names.
    What i did? I used two separate queries. I know I know not the best way to do it but i intend to fix it once i get a test working. I'll post the correct way when I have it.

    Lachof

  4. #4
    toivo is offline Junior Member
    Join Date
    Feb 2008
    Location
    Sydney, Australia
    Posts
    3

    Thumbs up Relationship query results

    In a similar relationship query I would expect results from this:

    $queryResult = $sObject->queryResult[0];
    $qr = $queryResult->records;
    foreach (
    $qr as $record2) {
    $UnitPrice = $record2->fields->UnitPrice;
    }

    You could use one of the following to see the structure of the object:

    print_r(get_object_vars($queryResult));

    var_dump($queryResult);
    Regards,
    toivo

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1