Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:24:28+00:00 2026-05-29T13:24:28+00:00

I am new to using the salesforce api. I have downloaded the saleforce/php toolkit

  • 0

I am new to using the salesforce api. I have downloaded the saleforce/php toolkit and am able to successfully create contacts and accounts from a webform on my server.

To create a contact I am doing the following:

    $records[0] = new stdclass();
    $records[0]->FirstName = $FirstName;
    $records[0]->LastName = $LastName;
    $records[0]->Email = $Email;
    $records[0]->Phone = $Phone;
    $records[0]->MailingStreet = $MailingStreet;
    $records[0]->MailingCity = $MailingCity;
    $records[0]->MailingState = $MailingState;
    $records[0]->MailingPostalCode = $MailingPostalCode;
    $records[0]->MailingCountry = $MailingCountry;
    $records[0]->LeadSource = $LeadSource;

    $create = $mySforceConnection->create($records, 'Contact');

To create an account I am doing the following

    $records[0] = new stdclass();
    $records[0]->Name = $Name

    $create = $mySforceConnection->create($records, 'Account');

Can anyone give me a simple example of how I would associate a contact with an account?

I have a check-box on the form that asks if this is an organization. If the user checks this box I would like to create an organization account with some of the data and create a contact with some of the data and associate the two.

I am not looking for a full blown working example but more just somthing pointing me in the right direction.

Lets say I have an account with the id of 001Z0000004XeWfIAK

I have tried

    $records[0] = new stdclass();
    $records[0]->FirstName = $FirstName;
    $records[0]->LastName = $LastName;
    $records[0]->Email = $Email;
    $records[0]->Phone = $Phone;
    $records[0]->MailingStreet = $MailingStreet;
    $records[0]->MailingCity = $MailingCity;
    $records[0]->MailingState = $MailingState;
    $records[0]->MailingPostalCode = $MailingPostalCode;
    $records[0]->MailingCountry = $MailingCountry;
    $records[0]->LeadSource = $LeadSource;
    $records[0]->AccountId = '001Z0000004XeWfIAK';

    $create = $mySforceConnection->create($records, 'Contact');

@ superfell

it returns this:

Array
(
    [0] => stdClass Object
        (
            [errors] => Array
                (
                    [0] => stdClass Object
                        (
                            [message] =>  A Household Contact's account must be a household.
                            [statusCode] => FIELD_CUSTOM_VALIDATION_EXCEPTION
                        )

                )

            [id] => 
            [success] => 
        )

)

But I am trying to associate a contact with an orginization

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:24:28+00:00Added an answer on May 29, 2026 at 1:24 pm

    Ok, I am answering this myself because I cant mark Superfell comment as the answer. But his comment

    “When you create the account, you need to set the recordTypeId to a record type that’s not the household recordtype. – superfell”

    helped me get the answer.

    Here is my final code to create a account and then a contact of that account.

        //First I create a simple account
        //With no recordTypeId specified it defaults to the the type I want
    
        $records[0] = new stdclass();
        $records[0]->Name = $Name;
    
        //Create a new orginization account
        $org = $mySforceConnection->create($records, 'Account');
    

    After creating the Account, Salesforce returns a success message with the new AccountId

    Array
    (
        [0] => stdClass Object
            (
                [id] => 001Z0000004XfXcIAK
                [success] => 1
            )
    
    )
    

    Then I am able to create a contact and associate it with my new account

        $contact[0] = new stdclass();
        $contact[0]->FirstName = $FirstName;
        $contact[0]->LastName = $LastName;
        $contact[0]->Email = $Email;
        $contact[0]->Phone = $Phone;
        $contact[0]->MailingStreet = $MailingStreet;
        $contact[0]->MailingCity = $MailingCity;
        $contact[0]->MailingState = $MailingState;
        $contact[0]->MailingPostalCode = $MailingPostalCode;
        $contact[0]->MailingCountry = $MailingCountry;
        $contact[0]->LeadSource = $LeadSource;
    
        //This is where my problem was, Thanks again superfell
        //$organization_contact = My custom Salesforce contact type ID, E.G. recordTypeId
        $contact[0]->recordTypeId = $orginization_contact;
    
        //The AccountId is the account I want to associate this contact with.
        //AccountId was returned by Salesforce upon the creation of the account (See above)  
        $contact[0]->AccountId = $org[0]->id;
    
        $contact = $mySforceConnection->create($contact, 'Contact');
    

    Thank you again to Jeremey and Superfell. Saved me hours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script which fetches data from Salesforce via the Salesforce API
I'm new to using the Google Calendar API. I can create .ics calendars using
I still very new using Subversion. Is it possible to have a working copy
I'm attempting to Create a Job and Add a Batch using the Salesforce Bulk
Im new using Python, now I have a problem using ElementTree and read out
I am developing a salesforce app and using OAuth 2.0 to login. I have
i'm new using jquery, and developing for web, and i have this doubt, i
I am new using spring 3 and have been stuck for a while on
When using the Salesforce Partner API (version 21.0), how can I determine if the
Maybe this is a very silly question but I'm new using django. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.