+ Start a Discussion
BobHBobH 

Insert Contact not working

Hi all,

This is my first post here.  I am also brand new to SalesForce.  I just started messing with the SalesForce web services.  I can login and run some simple queries with no problems.  Now, I want to insert a new contact into my salesforce database.  I am using vb.net.  Here is my code:

 

Private Sub InsertNewContact()

Try

If Not login() Then

Return

End If

Dim cons(1) As sforce.sObject

Dim contact As New sforce.Contact

Dim j As Integer

For j = 0 To cons.GetUpperBound(0)

Next

If Not accounts Is Nothing Then

contact.AccountId = accounts(0)

End If

contact.AssistantName = "Jane"

contact.AssistantPhone = "777.777.7777"

contact.Department = "IT"

contact.Description = "Software Developer"

contact.Email = "bh0526@netzero.com"

contact.Fax = "555.555.5555"

contact.MailingCity = "Boca Raton"

contact.MailingCountry = "US"

contact.MailingState = "FL"

contact.MailingStreet = "1907 NE 2nd St"

contact.MailingPostalCode = "33441"

contact.MobilePhone = "888.888.8888"

contact.FirstName = "Bob"

contact.LastName = "Herrmann"

contact.Salutation = "Mr."

contact.Phone = "999.999.9999"

contact.Title = "Software Developer"

cons(1) = contact

Dim sr() As sforce.SaveResult = binding.create(cons)

Catch Ex As Exception

Response.Write(Ex.Message)

End Try

End Sub

I never get an error.  But if I go into salesforce.com I do not see this new contact.  Can anyone tell me what I'm doing wrong?

 

Thanks,

Bob

SuperfellSuperfell
You need to examine the SaveResult array values to determine why the insert failed. SaveResult has a success flag along with an array of errors.
BobHBobH

Thanks for the reply Simon.  I checked the success code like you suggested and it came back true.  But I do not see my contact in SalesForce. 

 

Thanks,

Bob

SuperfellSuperfell
Do you get an Id in the SaveResults ? what happens when you try and view that id ? e.g. https://na1.salesforce.com/{newId} ?
BobHBobH

Oh yeah, I did.  I forgot to mention that.  It was a long value with a mixture of letters and numbers.

 

Thanks,

Bob

SuperfellSuperfell
So, can you view the contact directly ? http://na1.salesforce.com/{newId}
BobHBobH

Simon,

 

I'm a little confused.  I did a response.write for these values after I save.  Here is my code for this:

 

Response.Write(sr(0).success.ToString & " " & sr(0).id & "<br>")

This returns:  True 00330000006Er2TAAS

So what is this url you want me to check?  Do I plug in my returned value in place of newid?

 

Thanks,

Bob

 

SuperfellSuperfell
yes https://na1.salesforce.com/00330000006Er2TAAS
BobHBobH

Sorry, I was using http: instead of https:.  So this is what I get when I go to this site with my newid:

 

Data not available.

The data you were trying to access could not be found. It may be due to another user deleting the data or a system error. If you know the data is not deleted but cannot access it, please look at our support page.

 

I first get the login screen and then a page with the above error appears.

SuperfellSuperfell
And you login with the same credentials that your API code is using ?
BobHBobH
Yes.  But for fun I tried it again and this time I did get to see my contact.  Is there a delay maybe, before I can see the contact? 
SuperfellSuperfell
There should be no delay, its a syncronous API.
BobHBobH

I may have mistyped it.  But now I can see my contact.  In fact, I see about 10 of them since they were posting over and over as I was testing.  I like this web service.  I can now create a web page that lists our accounts and contacts from our legacy app and allow the users to update our SalesForce data.  Another question: our users use www.salesforce.com.  I notice my insert went to na1.salesforce.com.  Is this just for testing?

 

Thanks,

Bob

BobHBobH

Everything is ok now.  Please disregard my last post.  What happenend was that I registered as system admin in sales force using .com on my email and then registered using .net on my email for a developer.  I made them both the same and now I can see my new contact.  Thanks for all your help!!

Bob

SuperfellSuperfell
you login via www.salesforce.com and are then directed to a particular service. You'll noticed that once you're logged in you're actually viewing na1.salesforce.com even though you started at www.salesforce.com