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
Brian A. ChaseBrian A. Chase 

PHP Opportunity Updates

Does anyone have any sample code on updating or creating an opportunity?

I am able to do all of this based on the sample code:

  1. Login
  2. Query Leads and view all the fields
  3. Query all Opportunities and view all the fields
  4. Update various fields in the "Leads" section

When I try to update the "opportunity" section, it does not update and does not give me an error message.

Any help would be appreciated,

Brian

Brian A. ChaseBrian A. Chase

Here is the code that I am using.  If I use the "lead" type, this works.  It does not work for "opportunity" though.  It does display all the opportunities and the names change on my PHP screen but they do not change inside of Sforce web panel. 

When I use "lead" and change "AccountId" to "ID", I can update numerous fields within the Sforce web panel. 

I was thinking that it had something to do with the ID vs AccountId.  AccountId is not a unique field.

Does anyone know what field I am missing so that the database knows which record to update?  I don't see the unique field such as "ID" for the opportunity object.

Has anyone successfully updated an opportunity and could you paste a sample code?

Also, this does not work:

$client = new SalesforceClient($SESSION);
$FIELDS = array('type'=>'opportunity','AccountId'=>'00130000002Dhp3AAC','Name'=>'test');
$client->update($FIELDS);

Thanks,

 Brian


if (!isset($_COOKIE['sf_session'])) {
        header("Location: login.php");
        exit;
} else {
        $SESSION  = $_COOKIE['sf_session'];
}
$DATATYPE = 'opportunity';

$LIMIT = 'ALL';

$COLUMNS = 'AccountId,Amount,Name';


$client = new SalesforceClient($SESSION);
$client->_endpoint = $_COOKIE['sf_endpoint'];

$query_str = "select $COLUMNS from $DATATYPE";
$result = $client->query($query_str,$LIMIT);

include("header.inc");
?>

<table width="100%" cellspacing="0" cellpadding="2" border="0">
  <tr bgcolor="#CCCCCC">
    <td></td>
<?php
$cols = split(',',$COLUMNS);
while (list($key, $val) = each($cols)) {
    print "<td><b>$val</b></td>";
}
print "  </tr>";

if (PEAR::isError($result)) {
    print "<p><span style=\"color:#FF0000\">".$result->getMessage()."<br />";
    print "$query_str</span></p>";
} else {
    $records = $result->records;
    while (list($k1, $record) = each($records)) {
        print "<tr".($i % 2 == 0 ? " bgcolor=\"#EEEEEE\"" : "").">";
        printf("<td>%d.</td>",++$i);
        reset($cols);
        while (list($k2, $col) = each($cols)) {
            printf("<td>%s</td>",$record->{$col});
            if($record->{'Name'} == 'Edge Emergency Generator')
  $record->{'Name'}='Freddy';
                $result = $client->update($record);
                if (PEAR::isError($result)) {
                    print "<p><span style=\"color:#FF0000\">".$result->getMessage()."<br />";
                    }
            }
        }
        print "</tr>\n";
    }
}

?>
</table>

 

Brian A. ChaseBrian A. Chase

Here are the latest developments:

  1. $client->__get_wire() does not return the outgoing portion
  2. Here is the return from $client->__get_wire():

    Get Wire = OUTGOING: INCOMING HTTP/1.1 200 OK Server: sfdc Content-Type: text/xml; charset=utf-8 Transfer-Encoding: chunked Date: Sat, 10 Jul 2004 14:32:32 GMT Id not specified MISSING_ARGUMENT false
  3. I cannot find an "Id" field in the API for the "Opportunity" object
  4. Without an "Id" field, how does Sforce know which record to update?
  5. The message in item 2 does not generate an error in the PEAR test for errors

     if (PEAR::isError($result)) {

 

Has anyone successfully updated a field in the "Opportunity" section?  Do you have any code you would be willing to share?

adamgadamg
> I cannot find an "Id" field in the API for the "Opportunity" object

? Every sforce Object has an ID. (Unless you are calling create, in which case the ID is returned...)

I'm not sure how PEAR makes the ID field available, but its worth looking at carefully as ID is a bit of a special case. One way of thinking about it is that ID is part of the abstract definition of SObject, and defined by the Partner WSDL, as every SObject regardless of type has an ID; other object specific fields are not part of the abstract definition, and not defined by the Partner WSDL.
Brian A. ChaseBrian A. Chase


adamg wrote:
> I cannot find an "Id" field in the API for the "Opportunity" object

? Every sforce Object has an ID. (Unless you are calling create, in which case the ID is returned...)

I'm not sure how PEAR makes the ID field available, but its worth looking at carefully as ID is a bit of a special case. One way of thinking about it is that ID is part of the abstract definition of SObject, and defined by the Partner WSDL, as every SObject regardless of type has an ID; other object specific fields are not part of the abstract definition, and not defined by the Partner WSDL.


Thank You.  That tip seems to have solved my problem.  I looked at the code for updating my "Lead" section and the only difference was that I was querying and displaying the "Id" field.  I changed the "Opportunity" code to do the same and it is working now.

I can only conclude that the "Id" section is not implicitly part of the record and only appears after you try and read that field.  Afterwards the object retains that "Id" field and allows an update to occur.

 

 

RYakerRYaker
I am having this same problem, but I am getting an error message.

Must send a concrete entity type