Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
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", "XXXX@XXXXXXXX.com"); 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; }
In Salesforce, for the junction record, let's call it Course_Registration__c.
Course_Registration__c
For each course registration (Contact : Course), you will need to insert a Course_Registration__cwith these fields filled in:
Both Course_Registration__c.Course__c and Course_Registration__c.Contact__c are ID fields. The values to set will be the IDs returned after you insert the Course__c and Contact SObjects, respectively.
Course_Registration__c.Course__c
Course_Registration__c.Contact__c
Course__c
Contact
That is, the inserts to the two master SObjects need to happen first, you grab the IDs of these upon return from the insert call to the SFDC API, and you use them to populate a junction record via another insert (or bulk insert for all registrations per Contact)
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.