2

I use Ruby on Rails 4.2.5 with the Restforce gem for Salesforce API. I create a Contact in my controller :

class CandidateFormController < ApplicationController


  def index
    client = Restforce.new(
      :username => ENV['SALESFORCE_USERNAME'],
      :password       => ENV['SALESFORCE_MDP'],
      :security_token => ENV['SALESFORCE_TOKEN'],
      :client_id      => ENV['SALESFORCE_APIKEY'],
      :client_secret  => ENV['SALESFORCE_SECRET'],
    )

    new_client = client.create('Contact', FirstName: @first_name,
      LastName: @last_name,
      Email: @email,
      MobilePhone: @telephone,
      Description: @champ_libre,
      Profil_LinkedIN__c: @linkedin
     )

  end

end

I have a relationship between two of my tables. Candidate is associated to Opportunity (a job offer if you prefer), and the restforce documentation doesn't explain how to create a new entry with a relation between two elements, or if it does I am not enough experimented to have understand how am I supposed to do so.

I have not enough credit to post screenshots, but if this is necesseray I can use imgur or something like that.

P.S : I already see this post on the subject, but that didn't help me at all.

scoudert
  • 189
  • 2
  • 9

1 Answers1

2

Well, after another hour of research I finally find how to create relationship in salesforce.

My code looks like this now :

    class CandidateFormController < ApplicationController


  def index
    client = Restforce.new(
      :username => ENV['SALESFORCE_USERNAME'],
      :password       => ENV['SALESFORCE_MDP'],
      :security_token => ENV['SALESFORCE_TOKEN'],
      :client_id      => ENV['SALESFORCE_APIKEY'],
      :client_secret  => ENV['SALESFORCE_SECRET'],
    )

    new_client = client.create('Contact', FirstName: @first_name,
      LastName: @last_name,
      Email: @email,
      MobilePhone: @telephone,
      Description: @champ_libre,
      Profil_LinkedIN__c: @linkedin
     )

  new_candidature = client.create(
    'Candidatures__c',
    Candidats__c: "someId",
    Offredemploi__c: new_client
 )       

  end

end

In my case, I wanted to create a relationship between an Opportunity and a Contact (A job offer and a Candidate). I look more into fields that already was created and filled for Opportunity and Contact in my salesforce account, and find out that there were no field that was corresponding to the relationship I was looking for.

I discover than in salesforce, there are objects that exist just for the junction between two objects, and they are called "Junction Object" (pretty obvious, but not easy to find).

You just have to create a new salesforce object with create() after the creation of your first element (a Contact for me) and create the junction object with the good type (for me it was Candidatures__c), and specify the two relationships.

In my own code I create an new Candidature__c, I specify the Id of the job offer (the Candidats__c id) and the Id of the candidate in Offredemploi__c with the Id I create some lines above.

Hope it will helps.

scoudert
  • 189
  • 2
  • 9