You are viewing limited content. For full access, please sign in.

Question

Question

salesforce integration

asked on January 29, 2016

Im working with a Workflow that was built by a former employee and he wrote a custom script to push metadata to salesforce. It seamed like it was working but my client that's using it is now telling me that some fields are not mapping correctly. The first one is birth date on new contacts. Everything in the code looks good to me but I also did not write it or for that fact have much experience with API's. Has anyone else done anything like this before and if yes, could you tell me what to try with this code.

s = GetTokenValue("RetrieveFieldValues_Birthdate").ToString();
            if (string.IsNullOrEmpty(s) == false)
            {
            string date = s;
            DateTime dt = Convert.ToDateTime(date);
            contact.Birthdate = dt;
            }

 

Thank you.

 

 

0 0

Replies

replied on February 4, 2016

Just wanted to let you know I found the solution. actually the guy wrote wrote the original code found it. 

here is what we had to do. 

           { 
            string date = s;
            DateTime dt = Convert.ToDateTime(date);
            contact.BirthdateSpecified = true;

            contact.Birthdate = dt;
            }

I have no idea why we had to add that. He said it was something to do with Salesforces fucnky API but now it works. Thanks for the help. 

1 0
replied on January 29, 2016 Show version history

Lucas - You could do several things to clean up the code but my guess is the issue is with the string variable named 'date'.  The name 'date' is a reserved word and using it as a variable will lead to problems.  I would change the variable to something like 'birthDate' and see if that fixes the issue.

s = GetTokenValue("RetrieveFieldValues_Birthdate").ToString();
if (string.IsNullOrEmpty(s) == false) {
	string birthDate = s;
	DateTime dt = Convert.ToDateTime(birthDate);
	contact.Birthdate = dt;
}

 

0 0
replied on January 29, 2016

A cleaner version of the same code might look something like this;

s = GetTokenValue("RetrieveFieldValues_Birthdate").ToString();
if (!string.IsNullOrEmpty(s)) {
	contact.Birthdate = Convert.ToDateTime(s);
}

 

0 0
replied on January 29, 2016

awesome, thanks. Ill give it a try and see what happens. 

0 0
replied on January 29, 2016

Dang, no-luck. Its still not updating that field. I even tried both of your codes. You have any other ideas? Is there a way to to find out what exactly could be the issue? Like a debug error code or something. I have posted on the Salesforce boards but they are not as responsive as here. Thanks for the help. 

0 0
replied on January 29, 2016 Show version history

Are we confident the issue is in this section of the code?  How about hard-coding a good DateTime value like DateTime.Today  (Skip the If section and just use this line of code.  It should write today's date into the contact.Birthdate field)

            contact.Birthdate = DateTime.Today;

 

0 0
replied on January 29, 2016

OK, Ill try that, because I'm not confident where the issue is at all. I'm jumping on to this project and writing code is not my strong suit. Thank for the help. 

0 0
replied on January 29, 2016

Well adding that in there also did not add a date. I wonder if it could be the formatting of the metadata or if its the script. just seams weird that all these fields are moving over fine, just not the date. What else could we try?

0 0
replied on January 29, 2016

So my guess at this point is that the value that we are assigning to the contact.Birthdate property is not what it is expecting.  Perhaps because we are passing it a datetime value and it is looking for a date only value?  Can you verify what type of data the Birthdate property is expecting?

0 0
replied on January 29, 2016

That's kinda what I was thinking. I have this tool called data loader. The guy that was working on this showed it to me as a way to find out what the field names are. The customer has a couple of custom fields that I needed to check the naming on. The input value for birthday just date. 

The field in Laserfiche is a date field. I can try to change it to text and see what it does. 

0 0
replied on January 29, 2016

This is a long shot but how about hard coding a 'date only' string and seeing if the API will convert that to a date only?

contact.Birthdate = "01/29/2016";

 

0 0
replied on January 29, 2016

Workflow give me this when i tried that;

Error    1    Cannot implicitly convert type 'string' to 'System.DateTime?'    \Script2\Script 1.cs    90    33    Incoming Intake Forms - Update SF
 

0 0
replied on January 29, 2016

Can you share the section of code where the contact object is being instantiated?

0 0
replied on January 29, 2016

 //Change the binding to the new endpoint
           SfdcBinding.Url = CurrentLoginResult.serverUrl;

            //Create a new session header object and set the session id to that returned by the login
           SfdcBinding.SessionHeaderValue = new SessionHeader();
           SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;

            Contact contact = new Contact();

            contact.Id = "";


            //string
            string s = null;

            s = GetTokenValue("RetrieveFieldValues_First Name").ToString();
            if (string.IsNullOrEmpty(s) == false)
            {
            contact.FirstName = s;
            }
            s = GetTokenValue("RetrieveFieldValues_Middle Name").ToString();
            if (string.IsNullOrEmpty(s) == false)
            {
            contact.Middle_Name__c = s;
            }
            s = GetTokenValue("RetrieveFieldValues_Last Name").ToString();
            if (string.IsNullOrEmpty(s) == false)
            {
            contact.LastName = s;
            }


            s = GetTokenValue("RetrieveFieldValues_Birthdate").ToString();
            if (string.IsNullOrEmpty(s) == false)
            {
            string date = s;
            DateTime dt = Convert.ToDateTime(date);
            contact.Birthdate = dt;
            }

0 0
replied on January 29, 2016

From the code it looks like the contact object is an external object so disregard being able to change the Birthdate property type to a string to see if the SalesForce API would convert it to a date only value. 

At this point I would suggest the SalesForce API help forum.  Perhaps there are code samples that you can review while you wait for a response?

0 0
replied on January 29, 2016

Yeah, that's where i started. they are not as responsive as here. Thanks for the help though. 

0 0
replied on January 30, 2016

Good luck!  One final thought if you continue to have trouble finding an answer; how about adding a custom field to the contact object, maybe something like 'DateOfBirth' and make that custom field type a datetime?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.