+ Start a Discussion

15 Digit Id issue

I have an s-control that I'm using to override the New button for a custom object.  When I hit that New button from the parent object (Contact), I pull the Contact Id from the URL and then use that Id to create a new record (via javascript).  I'm receiving an INVALID_CROSS_REFERENCE_KEY error message when trying to create the new record.  After fighting with it for awhile, I realized that if I hard-code the18-digit Id, the record is created with no error.  So, how do I either do the create with just the 15-digit Id OR convert the 15-digit Id to an 18-digit Id.  I found a couple scripts out there to do the conversion, and none have returned the correct 3-digit suffix.  When I try to do a SoQL query to get the id ("Select Id from Contact where Id='" +part+"'"), it's coming back as 15 digits, even though other queries return the 18-digit Id. 

This is the offending code, the "part" variable is what I'm having issues with. Is there another way to do this that will help me?  I'm at my wits end fighting with this.

var part = getURLParam("CF00N50000001YtHY_lkid");
          var sm = new sforce.SObject("Status_Milestone__c");
          sm.RecordTypeId = RT;
          sm.Category__c = selCat.options[selCat.selectedIndex].value;
          sm.Sub_Category__c = selSubCat.options[selSubCat.selectedIndex].value;
          sm.Status_Milestone__c = selStatus.options[selStatus.selectedIndex].value;
          sm.Comment__c = selComment.value;
          sm.Effective_Date__c = eff_date;

          sm.Participant__c = part;
          var SaveResult = sforce.connection.create([sm ]);


Message Edited by jgrenfell on 10-04-2007 04:48 PM

Turns out the 15 digit Id thing was a red-herring.  The java getURLParam function returned the Id with all lower-case letters, which is why it was rejected being rejected.  So I found a case-sensitive java function that returned the URL and all is well.