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
nhnh 

Contact OwnerId field

I'm using the Perl API (latest release) to query the contact  table and need to pick up the OwnerID field so I can look up their email and notify them if I update a contact record through the API. 

However when I query the contact table all I get returned is blank OwnerID fields.  How do I get hold of this data?  The sample code I'm using is below:

Also, I'm not familiar with Oracle query syntax as I use mysql.  What is the syntax to sort a query.  In mysql it is  'order by field' or to reverse 'order by field desc'  but this is not accepted in the API query call.

Thanks

Nigel Hall

 

my $COLUMNS = "Id,OwnerID,CreatedDate,FirstName,LastName,Email";
my $LIMIT = "10";
my $DATATYPE = "Contact";

my $query_str = "select $COLUMNS from $DATATYPE";

$result = $port->query( 'query' => $query_str );

if ($result->fault()) {
    print $result->faultstring();
    print "\n  error on: $query_str\n"
} else {
    my $i = 0;

    my $count = 1;
    foreach my $elem ($result->valueof('//queryResponse/result/records')) {
        my %DATA;
        foreach my $col (split(',',$COLUMNS)) {
#           printf "$elem->{$col} - ";
            $DATA{$col} = $elem->{$col};
        }
        print "rec: $count\n";
        foreach my $field ( keys %DATA ) {
                printf "%-15s: [%s]\n", $field, $DATA{$field};
        }
        print "\n";
        $count++;
    }
}

Message Edited by nh on 02-18-2004 04:32 PM

Message Edited by nh on 02-18-2004 04:32 PM

adamgadamg
Hi nh:

Can you post the XML messages so we can see whats happening? When I run that query using a simple Java program, it works fine, so I assume there is a problem somewhere in how the result is being parsed.

W/r/t "order by", the API does not currently support ordering. (Or joins.) You'll need to do that in your client code.
nhnh

Adam,

I found the problem.  XML is below.

The query method was being called with  OwnerID which caused XML data to return but I couldn't get at in the client as the fieldname is really  OwnerId.  Looks like the SQL is OK with case-insensitive fields and should really throw an error on an invalid field name.  I'll make sure and double check these field names.

Any idea on when query sorts will be available.  Its going to get difficult when dealing large amounts of data.  I don't really want to read the entire table just to sort it locally when I just want to get the 20 most recent leads or contacts.

Thanks

Nigel

 

 

SOAP::Transport::HTTP::Client::send_receive: POST https://www.sforce.com/services/Soap/c/2.5
Accept: text/xml
Accept: multipart/*
Content-Length: 578
Content-Type: text/xml; charset=utf-8
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Body><namesp1:login xmlns:namesp1="urn:partner.soap.sforce.com"><username xsi:type="xsd:string">kwalls@e-myth.com</username><password xsi:type="xsd:string">web29mar</password></namesp1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Cache-Control: private
Connection: close
Date: Thu, 19 Feb 2004 01:52:20 GMT
Server: Resin/2.1.6
Content-Type: text/xml; charset=utf-8
Content-Type: text/xml; charset=UTF-8
Client-Date: Thu, 19 Feb 2004 01:52:20 GMT
Client-Peer: 63.146.199.44:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign International Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign
Client-SSL-Cert-Subject: /C=US/ST=California/L=San Francisco/O=Salesforce.com, Inc./OU=Applications/OU=Terms of use at www.verisign.com/RPA (c)01/CN=www.sforce.com
Client-SSL-Cipher: DES-CBC3-SHA
Client-SSL-Warning: Peer certificate not verified
Client-Transfer-Encoding: chunked
Set-Cookie: sid=UHd2LqxfRKqaVDs_xe6RQOycGuZvJ8M7JZoXNYKJfHzPRsGZtZPCbmju7VpGmvsn4CBZhYxNyRle9H2tBjoiGfbtzKggVlhL; path=/

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
 <soapenv:Body>
  <loginResponse xmlns="urn:partner.soap.sforce.com">
   <result>
    <serverUrl>https://na1-api.salesforce.com/services/Soap/c/2.5</serverUrl>
    <sessionId>UHd2LqxfRKqaVDs_xe6RQOycGuZvJ8M7JZoXNYKJfHzPRsGZtZPCbmju7VpGmvsn4CBZhYxNyRle9H2tBjoiGfbtzKggVlhL</sessionId>
    <userId>00530000000cJ4dAAE</userId>
   </result>
  </loginResponse>
 </soapenv:Body>
</soapenv:Envelope>
SOAP::Transport::HTTP::Client::send_receive: POST https://na1-api.salesforce.com/services/Soap/c/2.5
Accept: text/xml
Accept: multipart/*
Content-Length: 850
Content-Type: text/xml; charset=utf-8
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Header><SessionHeader><sessionId xsi:type="xsd:string">UHd2LqxfRKqaVDs_xe6RQOycGuZvJ8M7JZoXNYKJfHzPRsGZtZPCbmju7VpGmvsn4CBZhYxNyRle9H2tBjoiGfbtzKggVlhL</sessionId></SessionHeader><QueryOptions><batchSize xsi:type="xsd:int">2</batchSize></QueryOptions></SOAP-ENV:Header><SOAP-ENV:Body><namesp2:query xmlns:namesp2="urn:partner.soap.sforce.com"><query xsi:type="xsd:string">select Id,OwnerID,CreatedDate,FirstName,LastName,Email from Contact</query></namesp2:query></SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Date: Thu, 19 Feb 2004 01:52:24 GMT
Server: Resin/2.1.s030924
Content-Type: text/xml; charset=utf-8
Client-Date: Thu, 19 Feb 2004 01:52:24 GMT
Client-Peer: 63.146.199.40:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign International Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign
Client-SSL-Cert-Subject: /C=US/ST=California/L=San Francisco/O=Salesforce.com, Inc./OU=Applications/OU=Terms of use at www.verisign.com/RPA (c)01/CN=na1-api.salesforce.com
Client-SSL-Cipher: DES-CBC3-SHA
Client-SSL-Warning: Peer certificate not verified
Client-Transfer-Encoding: chunked

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
 <soapenv:Body>
  <queryResponse xmlns="urn:partner.soap.sforce.com">
   <result>
    <done>false</done>
    <queryLocator>01g300000000C1cAAE-2</queryLocator>
    <records xsi:type="sf:Contact" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
     <sf:CreatedDate>2004-01-24T00:11:26.000Z</sf:CreatedDate>
     <sf:FirstName>Peter</sf:FirstName>
     <sf:Id>00330000002EeaoAAC</sf:Id>
     <sf:LastName>Swanson</sf:LastName>
     <sfwnerId>00530000000cJ4EAAU</sfwnerId>
    </records>
    <records xsi:type="sf:Contact" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
     <sf:CreatedDate>2004-01-22T21:43:13.000Z</sf:CreatedDate>
     <sf:Email>harmonch@pacbell.net</sf:Email>
     <sf:FirstName>Chuck</sf:FirstName>
     <sf:Id>00330000002DX1mAAG</sf:Id>
     <sf:LastName>Harmon</sf:LastName>
     <sfwnerId>00530000000cJ4KAAU</sfwnerId>
    </records>
    <size>21883</size>
   </result>
  </queryResponse>
 </soapenv:Body>
</soapenv:Envelope>
$

adamgadamg
Ah. Good catch - working with the partner API is tricky like that.

Re: sorts, you should try using the system modify timestamp to retrieve only the
records that are new/changed within a certain time - should greatly limit the scope of your query.