function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ssousanssousan 

Error saving a new record to Contract?

I am trying to save a new record in Contract,

I have required fields like Account name and Contact name,

 

Here is part of the code:

 

         Account[] aa = [SELECT Id, Name FROM Account WHERE Name = :inquery.Institution__c];
          Contact[] ac = [Select AccountId From Contact Where Email =:inquery.email__c]; 


          contract = new Contract();
          contract.Volume_Serial_Number__c  = record.Volume_Serial_Number__c;
          contract.Host_Name__c             = record.Host_Name__c;
          contract.Physical_Address__c      = record.Physical_Address__c;
          contract.License_Type__c          =  'Temporary';
          contract.CustomerSignedId         = ac.get(0).AccountId;
          contract.AccountId                = aa.get(0).Id;
          insert contract;

 

So the contact and account fields are linked to Contract [look up fields]

When I run the code I get the following error:

 

 Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Institution Contact: id value of incorrect type: 001J0000015XCOKIA4: [CustomerSignedId]

 

Does anyone know why?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
kevin lamkevin lam

You are assigning an Account Id to contract.CustomerSignedId and it's expecting a Contact Id.