title: How to insert data into a custom object with lookup field from apex controller
body: <p>I have a custom object <code>MyCustomObj__c</code> which has a field called "ContactData".</p>
  
  <p>I am trying to insert a record into the custom object with the following apex method. It gives an error:</p>
  
  <pre><code>Invalid ID
  </code></pre>
  
  <p>The value <code>Hari</code> already exists in the Contact list.</p>
  
  <p><strong>apex code:</strong></p>
  
  <pre><code>public static String saveData(){
      MyCustomObj__c newObj = new MyCustomObj__c(); 
      newObj.contactData__c = 'Hari';
      insert newObj;
      return "success";
  }
  </code></pre>
  
  <p>How do I insert a row?</p>