+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14
This is a discussion on How do I select one record and display the result within the Salesforce Coding Discussions forums, part of the Salesforce category; Hi, I am familiar with php but new to salesforce and objects.
  1. #1
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7

    How do I select one record and display the result

    Hi, I am familiar with php but new to salesforce and objects.

    I am trying to display the information for an account.

    This is what I have so far:
    $query = "SELECT Id, FirstName, LastName from Contact WHERE AccountId = 'xxxxxxxxxxxxx' LIMIT 1";
    $response = $mySforceConnection->query($query);

    How do I say: echo 'First Name: ' . $response['FirstName']?

    Thank you in advaced,
    Eliana

  2. #2
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Quote Originally Posted by eliana View Post
    Hi, I am familiar with php but new to salesforce and objects.

    I am trying to display the information for an account.

    This is what I have so far:
    $query = "SELECT Id, FirstName, LastName from Contact WHERE AccountId = 'xxxxxxxxxxxxx' LIMIT 1";
    $response = $mySforceConnection->query($query);

    How do I say: echo 'First Name: ' . $response['FirstName']?

    Thank you in advaced,
    Eliana
    Eliana try this:


    PHP Code:
    <?php
    $wsdl 
    '/opt/lampp/htdocs/soapclient_new/partner.wsdl.xml';
    $userName "username";
    $password "password";

    ini_set("soap.wsdl_cache_enabled","0");


    require_once (
    '/opt/lampp/htdocs/soapclient_new/SforcePartnerClient.php');



    //setup connection
    $mySforceConnection = new SforcePartnerClient();
    $mySforceConnection->createConnection($wsdl);
    $loginResult $mySforceConnection->login($userName,$password);

    $query "SELECT Id, FirstName, LastName from Contact WHERE AccountId = '0014000000FJtt1AAD' LIMIT 1";
    $response $mySforceConnection->query($query);



    foreach (
    $response->records as $r)
    {   
       
    /* uncomment this to see the whole object */ 
       //echo '<pre>' . print_r($r,true) . '</pre>';
       
       
    echo $r->fields->FirstName ;
    }


    ?>

  3. #3
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7
    Thanks Mike!!!

    This works:
    echo $r->FirstName;

    You made my day!!
    Eliana

  4. #4
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Ahh are you using the enterprise wsdl?

    if you are then that would work!

    I am glad that you got it working


    ~Mike

  5. #5
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7
    Yes I am using enterprise.

    Now I am trying to insert a lead and it's not working.

    require_once ('soapclient/SforceEnterpriseClient.php');

    $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
    $mylogin = $mySforceConnection->login("xxx","xxx");

    $query = "INSERT INTO `Lead` (FirstName, LastName) VALUES ('test','test')";
    //$queryResult = $mySforceConnection->query($query);
    mysql_query($query);

    What am I doing wrong?

  6. #6
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    so are you trying to get a replication script setup to get your leads into MySQL?

    I have a simple solution for you:

    use this script:

    PHP Code:
     <?php
    ini_set
    ("soap.wsdl_cache_enabled","0");


    require_once (
    './includes/soapclient/SforcePartnerClient.php');

    /***************************************************************************** 
    *  This script uses ADODb, you must have ADOdb installed or in a common      *
    *  folder to run this script.  The best way to do this is to go to           *
    *  http://adodb.sourceforge.net/ and download the latest version and install *
    *  it in your include_path in the php.ini file.                              *
    ******************************************************************************/
    require_once ('./includes/adodb.inc.php'); 
     
    $db NewADOConnection('mysql');


    //MySQL database connection information
    $db->Connect("localhost","sfmysql","sfmysql","sf_live");

    //Truncate current database to establish a refresh
    $sql "TRUNCATE TABLE sf_lyris_live_account";
    if (
    $db->Execute($sql)) echo "<strong>Account Table Truncated</strong><br />";

    //Salesforce Connection information
    $wsdl './includes/soapclient/partner.wsdl.xml';
    $userName "myuser";
    $password "mypass";


    //setup connection
    $client = new SforcePartnerClient();
    $client->createConnection($wsdl);
    $loginResult $client->login($userName,$password);

    //SOQL query for Object in Salesforce


    $soql "Select Id, IsDeleted, MasterRecordId, Name, Type, ParentId, BillingStreet, BillingCity FROM Account";

    //Processes the query to get account information from Salesforce
    $records get_records($client,$soql,$db);

    if (
    $records === false)
    {
        
    //mail("mike.simonds@maxim-ic.com","PHP Product2 Script  Error","There has been an error in the product2 replication script\nPlease Check Script");
    }
    echo 
    '<p>There are currently '.$records.' products:</p>';

    $today date("F j, Y, g:i a");
    $end 'Product2 Import script ended at '.$today.' and inserted '.$records.' into the database';


    function 
    get_records($connection,$query,$db)
    {

        
    //Set this to the number of records to process per batch
        //200 is the minimum
        
    $queryOptions = new QueryOptions(200);
        
    $connection->setQueryOptions($queryOptions);

        
    $response $connection->query(($query),$queryOptions);

        
    //for debugging
        //echo '<pre>' . print_r($response,true) . '</pre>';
        //exit;

        
    if ($response->size 0)
        {
            
    $records $response->records;
            
    // Cycles through additional responses if the number of records// exceeds the batch size
            
    $count_records 0;
            while (!
    $response->done)
            {
                
    $records $response->records;
                
    set_time_limit(100);
                
    ini_set("memory_limit","512M");


                
    //Process curent $records
                
    $current_count store_in_db($records,$db);

                if (
    $current_count === false)
                {
                    return 
    false;
                }
                else
                {
                    
    $count_records += $current_count;
                }
                echo 
    "processed ".$count_records." records<br />";
                
    flush();

                
    $response $connection->queryMore($response->queryLocator,$queryOptions);


            }
            
    set_time_limit(100);
            
    $records $response->records;
            
    //Process curent $records

            //store the last set of records into the database
            
    $current_count store_in_db($records,$db);

            if (
    $current_count === false)
            {
                return 
    false;
            }
            else
            {
                
    $count_records += $current_count;
            }
        }

        return 
    $count_records;
    }

    /*Function to store records into
    * database in chunks of the $queryOptions = new QueryOptions(200);*/
    function store_in_db($records,$db)
    {
      
        
    $record_count count($records);
        
    //echo $record_count;
        
    $rows_loaded 0;

       foreach (
    $records as $r)
        {
            
            echo 
    '<pre>' print_r($r,true) . '</pre>'
            exit(); 
            
    $pass_this['id'] = $r->Id;

            
    //echo '<pre>' . print_r($pass_this,true) . '</pre>';  
            
    foreach ($r->fields as $key => $value)
            {
                
    $pass_this[$key] = addslashes($r->fields->$key);
            }


            
    $fields implode(",",array_keys($pass_this));
            
    $values implode("','",array_values($pass_this));
            
            
    $query "INSERT INTO sf_lyris_live_account (".$fields.") VALUES ('".$values."')";
            
            
            
    //executes and loads data coming from salesforce into table
            
    if ($db->Execute($query))
            {
                
    $rows_loaded++;
            }
            else
            {
                echo 
    $db->ErrorMsg()."<br />";
                return 
    false;
            }
            
    //exit;
        
    }
        return 
    $rows_loaded;

    }

    ?>
    download ADOdb PHP class from the link on my main menu

    Change the SOQL query, table names, paths to your phptoolkit and then also switch to the partner.wsdl file

    This will work for you!!


    ~Mike

  7. #7
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7
    Thanks.
    Do I need ADOdb if I am trying to insert just 1 lead, like the web-to-lead form?
    Last edited by eliana; 05-07-2009 at 04:39 PM.

  8. #8
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    What it looked like to me is that you were trying to take the data that you were rendering from Salesforce and you were then trying to insert it into MySQL. At least that is what it shows in your code.

    If you are trying to get a form on your website to insert data into the Lead object or table in Salesforce then that is a different thing.

    You would need to create a form using the php code from an example like this > http://www.mikesimonds.com/87-4-post.html

    I can help you get the code working, maybe I can even give you an short example of a form that will insert a lead into Salesforce

    Let me know if that is something that are looking for!


    ~Mike

  9. #9
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7
    Hi Mike,

    What I am trying to do is I am sending mass e-mails to my leads and personal accounts and asking them to click on a link in the e-mail that will open a form (for example: www.mywebsite.com/survey.php?leadid=xxxxxxxxx) where I will be asking them to enter more information (example: are you interested in this product, would you like to receive more information, etc), and when they click submit it updates that information into salesforce.

    So I am not inserting new leads or accounts, but editing some custom fields in salesforce

    What do you think? Is this possible?

  10. #10
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    It can be done, I will post something soon, give me about 20 min or so

+ Reply to Thread
Page 1 of 2 12 LastLast

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.2