Go Back   Mike Simonds > Salesforce > Salesforce Coding Discussions

This is a discussion on Using update() within the Salesforce Coding Discussions forums, part of the Salesforce category; Hi Mike, great site. Very helpful! I used the thread at http://www.mikesimonds.com/update-co...ption-t89.html

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 07-08-2008, 11:03 AM
Junior Member
 
Join Date: Jul 2008
Posts: 3
Using update()

Hi Mike,
great site. Very helpful!
I used the thread at Update Contact Description
to help me run update commands, with a few minor modifications.

Here's what I am running:
PHP Code:
ini_set("soap.wsdl_cache_enabled","0");
$username 'my@email.com';
$password 'mypassword';
$date date("m/d/y");

require_once (
'../includes/soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient $mySforceConnection->createConnection("../includes/soapclient/enterprise.wsdl.xml");
$mylogin $mySforceConnection->login($username,$password);

try
{
    if (
$mylogin) {
        
$query "select Id";
        
$query .= " from Account";
        
$query .= " where Account.WebID__pc=22";

        
$queryResult $mySforceConnection->query($query);
        
$records $queryResult->records;

        foreach (
$records as $record)
        {
            echo 
'<pre>' print_r($record,true) . '</pre>';
            
//$sObjectContact = new sObject();
            
$sObjectContact->type 'Account';
            
$sObjectContact->Id $record->Id;
            
$sObjectContact->fields = array('FirstName' => 'Shano');
            
print_r($sObjectContact);
            
$result $mySforceConnection->update(array($sObjectContact));
            
// print_r($result);
            
if ($result->success)
            {
                echo 
"good";
            }
            else
            {
                echo 
"bad";
            }
        }


    }
    else
    {
        echo 
"crap, something is wrong";
    }
}
catch (
exception $e)
{
    echo 
$mySforceConnection->getLastRequest();
    echo 
$mySforceConnection->getLastRequestHeaders();
    echo 
'<pre>' print_r($e,true) . '</pre>';

and when I do I get the following error to my browser. Can you help me work out what needs to be done to overcome this?

Warning: Missing argument 2 for SforceEnterpriseClient::update(), called in /mounted-storage/home94a/sub004/sc49409-VDPR/www/member/member4.php on line 30 and defined in /mounted-storage/home94a/sub004/sc49409-VDPR/www/includes/soapclient/SforceEnterpriseClient.php on line 68
462200D70000000Ij6O!AQkAQN31N.N3Gevi0l18_N8u3NY1pK GBi4JvGiePTVyZzvzBEuJr0WUAaXDQj.Va0AaxO8rohbTOBWMH k7Ij9jdCNIBGdmT8Contact0017000000NqhHZAAZFirstName Shano POST /services/Soap/c/13.0/462200D70000000Ij6O HTTP/1.1 Host: na5-api.salesforce.com Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.3 Accept-Encoding: gzip, deflate Content-Type: text/xml; charset=utf-8 SOAPAction: "" Content-Length: 604
Thanks
Count Rugen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2  
Old 07-08-2008, 02:31 PM
Administrator
 
Join Date: May 2007
Posts: 273
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Quote:
Originally Posted by CountRugen View Post
Hi Mike,
great site. Very helpful!
I used the thread at Update Contact Description
to help me run update commands, with a few minor modifications.

Here's what I am running:
PHP Code:
ini_set("soap.wsdl_cache_enabled","0");
$username 'my@email.com';
$password 'mypassword';
$date date("m/d/y");

require_once (
'../includes/soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient $mySforceConnection->createConnection("../includes/soapclient/enterprise.wsdl.xml");
$mylogin $mySforceConnection->login($username,$password);

try
{
    if (
$mylogin) {
        
$query "select Id";
        
$query .= " from Account";
        
$query .= " where Account.WebID__pc=22";

        
$queryResult $mySforceConnection->query($query);
        
$records $queryResult->records;

        foreach (
$records as $record)
        {
            echo 
'<pre>' print_r($record,true) . '</pre>';
            
//$sObjectContact = new sObject();
            
$sObjectContact->type 'Account';
            
$sObjectContact->Id $record->Id;
            
$sObjectContact->fields = array('FirstName' => 'Shano');
            
print_r($sObjectContact);
            
$result $mySforceConnection->update(array($sObjectContact));
            
// print_r($result);
            
if ($result->success)
            {
                echo 
"good";
            }
            else
            {
                echo 
"bad";
            }
        }


    }
    else
    {
        echo 
"crap, something is wrong";
    }
}
catch (
exception $e)
{
    echo 
$mySforceConnection->getLastRequest();
    echo 
$mySforceConnection->getLastRequestHeaders();
    echo 
'<pre>' print_r($e,true) . '</pre>';

and when I do I get the following error to my browser. Can you help me work out what needs to be done to overcome this?

Warning: Missing argument 2 for SforceEnterpriseClient::update(), called in /mounted-storage/home94a/sub004/sc49409-VDPR/www/member/member4.php on line 30 and defined in /mounted-storage/home94a/sub004/sc49409-VDPR/www/includes/soapclient/SforceEnterpriseClient.php on line 68
462200D70000000Ij6O!AQkAQN31N.N3Gevi0l18_N8u3NY1pK GBi4JvGiePTVyZzvzBEuJr0WUAaXDQj.Va0AaxO8rohbTOBWMH k7Ij9jdCNIBGdmT8Contact0017000000NqhHZAAZFirstName Shano POST /services/Soap/c/13.0/462200D70000000Ij6O HTTP/1.1 Host: na5-api.salesforce.com Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.3 Accept-Encoding: gzip, deflate Content-Type: text/xml; charset=utf-8 SOAPAction: "" Content-Length: 604
Thanks
Count Rugen
Well let me see where I can begin:

First off thanks for joining the site and thanks for the comments. I hope you find the information here helpful

There are a few things that need to be tweaked in your code


First off look at your query:

PHP Code:
$query "select Id";
$query .= " from Account";
$query .= " where Account.WebID__pc=22"
If this is a custom field, it has to end in a "__c" NOT "__pc", as you have.

I changed it to
PHP Code:
$query "select Id";
$query .= " from Account";
$query .= " where Account.WebID__c = '22'"
Second I do not use the Enterprise Client, I only use the Partner Client... As you will see in that post that I helped the other member on


Also

there is no field on the Account object > FirstName, that is only in the contacts and user objects

I added a field WebID__c to my developers org and ran the following script, once I updated the new field with a value of '22'

PHP Code:
<?php

ini_set
("soap.wsdl_cache_enabled","0");
$username 'masimonds@gmail.com';
$password 'mas4155yrQkDd4rzC3qZE8cydu6goAHe';


$date date("m/d/y");

require_once (
'./soapclient/SforcePartnerClient.php');
$mySforceConnection = new SforcePartnerClient();
$mySoapClient $mySforceConnection->createConnection("./soapclient/partner.wsdl.xml");
$mylogin $mySforceConnection->login($username,$password);

try
{
    if (
$mylogin)
    {
        
$query "select Id";
        
$query .= " from Account";
        
$query .= " where Account.WebID__c = '22'";

        
$response $mySforceConnection->query($query);
        
$queryResult = new QueryResult($response);

        foreach (
$queryResult->records as $record)
        {
            echo 
'<pre>'.print_r($record,true).'</pre>';
            
$sObjectContact = new sObject();
            
$sObjectContact->type 'Account';
            
$sObjectContact->Id $record->Id;
            
$sObjectContact->fields = array('maxim_id__c' => '987654321');

            
$result $mySforceConnection->update(array($sObjectContact));

            if (
$result->success)
            {
                echo 
"good";
            }
            else
            {
                echo 
"bad";
            }
        }


    }
    else
    {
        echo 
"crap, something is wrong";
    }
}
catch (
exception $e)
{
    echo 
$mySforceConnection->getLastRequest();
    echo 
$mySforceConnection->getLastRequestHeaders();
    echo 
'<pre>'.print_r($e,true).'</pre>';
}
?>
and ran it, you can too, I will leave my login information in there for you to mess around with.

Since you are asking for only one item in Salesforce, You needed to change your foreach loop, since it is only one record:

PHP Code:
$queryResult = new QueryResult($response);

foreach (
$queryResult->records as $record)

try the whole script as I posted it and tell me if that works for you, I hope it does and try the Partner client to see if it fits your needs. I am sure it will

I really do not see why anyone would need to use the Enterprise client when everything can be done with the partner


Anyway I hope that helps


~Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 07-08-2008, 07:31 PM
Junior Member
 
Join Date: Jul 2008
Posts: 3

Hi Mike.
Thanks for your quick reply! I am now having success updating my records in SalesForce. A few things though...

Quote:
If this is a custom field, it has to end in a "__c" NOT "__pc", as you have.
Yes, the WebID field is a custom field, but the WDSL lists it as appended with a '__pc'. I have changed it back and it works. Some of my custom fields are appended with '__c', and some with '__pc' too. Also, Account object > FirstName does exist for me so i kept is as that.

Also, I tried it as you suggested:
PHP Code:
$query .= " where Account.WebID__c = '22'"
and the resulting error message asked me to remove the quotes from around the 22, which I did and it worked fine.

I tested it then using the partner client and it has worked. We have signed up to the Enterprise Edition so why not use that instead of the Partner Client?

Thank you for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 07-08-2008, 10:51 PM
Administrator
 
Join Date: May 2007
Posts: 273
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Hmm that is new to me on the __pc fields, I have never seen that before

Maybe it is something new

I think that the connection settings using the Enterprise are harder to learn and have never had use for it. My company also has the enterprise version

If you have it working then stick with it

The partner client can pick up all your custom fields and field types.... try this simple script on your localhost or server and let me know if it works okay

I will list out all your objects and fields, no matter if they are custom or not
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 07-09-2008, 03:37 AM
Junior Member
 
Join Date: Jul 2008
Posts: 3

Hi Mike
Everything is working using the Partner client. I think I will stick with that one! Thank you for your help. I'm sure I will have more queries for you as my SF journey continues!
All the best
Shane
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 07-09-2008, 07:39 AM
Administrator
 
Join Date: May 2007
Posts: 273
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike
Glad to help!

I am glad that it works and that you are on your way

Let me know if you have any other questions

~Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:11 PM.



Powered by vBulletin


SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.

1 2 3 4 5