Before I begin my question, I'd just like to give a brief background on what I am doing and what I am looking to achieve.
FYI: I am a newbie with this Salesforce stuff.
I have connected my site with salesforce successfully via the Force.com PHP Toolkit.
VIA the PHP toolkit I am able to successfully upsert a contact when a new user is registered on my site.
I have created a custom object called "Courses".
VIA the PHP toolkit I am able to successfully upsert a "course" into the custom object "courses".
I am looking at creating a relationship between the 2 objects. The relationship will be contacts (students) assigned to (courses). A contact can be in many courses and a course can have many students.
So after some research I have found a way to create this many-to-many relationship via creating a junction object which will serve to connect the 2 other objects via the "Master-Detail Relationship" fields.
This is working fine as I want it. If I go into a contact I can see a section where I can assign a course to the contact.
I need the last step to be done via the PHP Toolkit.
This is where I do not know what to do or how to write the function. Because it is a many-to-many relationship, Im guessing that the object I build in php has to contain an array of courses that I am assigning to the contact.
Is there a particular field I need to target and if so what are the params I need to pass to it?
define("USERNAME", "[email protected]");
define("PASSWORD", "XXXXXXXX");
define("SECURITY_TOKEN", "XXXXXXXXXXXXXXXXX");
define("SOAP_CLIENT_BASEDIR", trailingslashit( ABSPATH ) . "../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
$sObject = new stdclass();
$sObject->FirstName = $first_name;
$sObject->LastName = $last_name;
// INSERT SOME FIELD HERE TO ATTACH AN ARRAY OF COURSES THE USER IS ATTACHED TO
$createResponse = $mySforceConnection->upsert("Email", array($sObject), 'Contact');
} catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;
}