1

I have following code which I am trying to execute in Console but failing with error below.

CODE:

Implementation__C I = New Implementation__C();
I =[select Account__c,ID, Name from Implementation__C where ID = 'Record ID'];
I.Account__c = 'Account record ID';
update I;

ERROR:

Line: 4, Column: 1
System.DmlException: Update failed. First exception on row 0 with id a0j0V00000NaBYgQAN; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

4
  • 1
    Are you using that literal string? Then of course it would fail...you're supposed to replace with a real value. – Adrian Larson Jun 29 '17 at 16:27
  • No it would be actual record ID. Like this: Implementation__C I = New Implementation__C(); I =[select Account__c,ID, Name from Implementation__C where ID = 'a0j0V00000NaBYgQAN']; I.Account__c = '001d000001quQPCAA2'; update I; – sfdchelper Jun 29 '17 at 16:28
  • 1
    are you pointing to correct org where AccountId exists? – Santanu Boral Jun 29 '17 at 16:35
  • ID and Console running above code is from same org. – sfdchelper Jun 29 '17 at 16:43
1

Can you run this code at your console

Account acct = [SELECT Id, Name FROM Account WHERE Id='Account record ID'];
Implementation__C Impl = [select Account__c,ID, Name from Implementation__C where ID = 'Record ID'];
Impl.Account__c = acct.Id;
update Impl;
1
  • Thank you I think it was issue with record. tried both original and suggested code in console is working fine. Thank you Santanu and Andrian for your quick responses. – sfdchelper Jun 29 '17 at 17:34
0

Account Ids all start with the prefix '001' the Id that you have listed in the error message is not an account Id 'a0j0V00000NaBYgQAN'. Are you sure you are not populating the account__c with the Implementation__c.Id instead of the account?

1
  • The id given in the error is for the record being update not the reference. – Eric Jun 30 '17 at 4:31
0

for what it's worth, no need to query anything to perform an update

update new Implementation__c(Id = 'record id', Account__c = 'account id');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.