2

Hi guys i have been using salesforce Rest Api for logging and now i wanted to create lead using access token that is returned to me by the Login call. But when i try to create the lead using the access token it isn't created and the response i get doesn't contain a Lead id.

I have been stuck on this for days and after a lot of Googling i couldn't find an answer.

I want to implement this functionality in android but for now i am using Google chrome Plugin Advance Rest Client for Testing.

Create Lead URL--> https://na14.salesforce.com/services/data/v21.0/sobjects/Lead

Header -->

Authorization: OAuth 00Di0000000Y4be!AR8AQHCnNzqTM1tItXuwTRdXfRmn7JbZlneSA3pMjmrw.5aZqz0JecaTj2coEXHbEi61iQEhHWg0lTc0BZ0k4U_1BccJvFaZ

Payload or Body -->

{"Phone":"789452",    

"Company":"Test Company",   

"Fax":"1238356"
,"LastName":"Micheal"

}

Content-Type: application/json

I am using a post Request. And the Response i am getting is

    {
objectDescribe: {
name: "Lead"
label: "Lead"
keyPrefix: "00Q"
custom: false
labelPlural: "Leads"
layoutable: true
activateable: false
urls: {
sobject: "/services/data/v21.0/sobjects/Lead"
describe: "/services/data/v21.0/sobjects/Lead/describe"
rowTemplate: "/services/data/v21.0/sobjects/Lead/{ID}"
}-
searchable: true
deprecatedAndHidden: false
createable: true
updateable: true
deletable: true
customSetting: false
feedEnabled: true
mergeable: true
queryable: true
replicateable: true
retrieveable: true
undeletable: true
triggerable: true
}-
recentItems: [8]
0:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "Luna, Wilredo"
}-
1:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "Rannga, Lite"
}-
2:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "Sith, Aro"
}-
3:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "Smith, Aberen"
}-
4:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "RANAHAN, MICHAEL"
}-
5:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "RABADI, RAED"
}-
6:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "A., Christopher"
}-
7:  {
attributes: {
type: "Lead"
url: "/services/data/v21.0/sobjects/Lead/--SomeId---"
}-
Id: "--SomeId---"
Name: "Ratnayake, Sam"
}-
-
}
2

I have fixed the issue.I am posting the answer so that it may help those of you who are facing the same problem

What i was doing was that i was sending a login request as described in this screenshot. And i was getting the following response.

{"id":"https://login.salesforce.com/id/00Di00000Y4EAC/005i0000000kAAA",
    "issued_at":"13756912686",
    "instance_url":"https://company.my.salesforce.com",
    "signature":"UAcaAbSj7vClbc/yAURGkT/7Hkjq6sllhcGvASs=",
 "access_token":"00Di0000000Y4befdjBiSvJ7RfW1s1fmUsLCf6UAQCgtmD.biS7T5rSOxyvtniyLeLN"}

I just changed the creating lead Url from

https://na14.salesforce.com/services/data/v21.0/sobjects/Lead

to

Format: instance_url+/services/data/v21.0/sobjects/Lead/

Actual Url: https://company.my.salesforce.com/services/data/v21.0/sobjects/Lead/

Now everything works.The problem was that i had to concatenate the instance_url with the lead Url. I dont think i can create lead unless i know the instance to which API calls should be sent.

As mentioned in the Salesforce Rest API documentation

instance_url: Identifies the Salesforce instance to which API calls should be sent

3
  • Even if it expects some domain name then it should error out.But you got wrong response .Still cant believe why this happens . Aug 4 '13 at 11:34
  • I still suspect you used GET earlier than POST request Aug 7 '13 at 19:28
  • No i used post the problem was with the URL Aug 15 '13 at 9:23
0

I just used the Create Call for my instance with the same code that you have and works perfectly fine

workbench.developerforce.com

enter image description here

Please try using workbench and see if it works .I feel that you are definately missing and making a different API call(I suspect you are debugging a GET CALL request)

Also i suspect after creation you are redirecting to different GET request.

7
  • I am using Authorization: OAuth 00Di0000000Y4be!AR8AQHCnNzqTM1tItXuwTRdXfRmn7JbZlneSA3pMjmrw.5aZqz0JecaTj2coEXHbEi61iQEhHWg0lTc0BZ0k4U_1BccJvFaZ in the header. I am not logging into salesforce but using the above access token when sending create lead request. Why is it not creating lead this way? Aug 4 '13 at 10:18
  • How are you getting oauth token in advanced REST client? Aug 4 '13 at 10:20
  • here is a screenshot img94.imageshack.us/img94/2131/fsso.png Sending this request returns me the access token. Which i use for further calls Aug 4 '13 at 10:38
  • ok did you try with workbench to see how service responds ? Aug 4 '13 at 10:42
  • yes using workbench I can create a lead. But the above access token method was working a few days back and now its not working :( Aug 4 '13 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.