I am attempting to build an integration between Salesforce and an external system.

I am NOT a Salesforce administrator, but rather the developer / administrator of the system I'm attempting to integrate with Salesforce; I'm attempting to get a good hold of what needs to be done on the salesforce side of things as far as integrations go to make sure things go smoothly.

The problem I'm running into / question I have, is how to assign a value to a Lookup field for a related object, for example, Contact.

On a Case object, I have a few fields related to Contact, and I'm trying to set the field 'Contact Name', which really apparently has a field name of 'Contact', and is a lookup type to the Contact Object, via the REST API and a custom APEX class.

I'm running into the following error:

Error: Compile Error: Illegal assignment from String to Contact at line 53 column 9 

This is my code within the APEX class:


global static String doPost(String Status,
    String Contact_ID,

    String CaseDescription) {

    Case case1 = new Case();

    case1.Status = Status;

    case1.Contact = Contact_ID;

    case1.Description = CaseDescription;

    insert case1;

    return case1.Id;


Specifically, my question is how can I assign a Contact on a Case for a field like this, using a 15 or 18 character Salesforce ID of the contact record?

What data type does my parameter need to be set as within this class, and is there any special way that I need to send it?

1 Answer 1


Please make the changes in code as :

case1.ContactId = Contact_ID;

sfdc automatically takes care of 15 or 18 digit id.

  • mark this as correct answer. :D Commented Feb 26, 2017 at 7:59
  • Haha, I tried to do that immediately, but it told me to wait X minutes first. As someone with ADD, naturally, I forgot to come back to it until you placed your comment :)
    – schizoid04
    Commented Feb 26, 2017 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .