So I'm getting the following erre:
FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
For this code snippet -
public object__c j{get; set;}
public newcustomController(ApexPages.StandardController stdController){
j = (object__c)stdController.getRecord();
}
public PageReference save() {
upsert j;
EntitySubscription e = new EntitySubscription();
e.SubscriberId = j.iMedia_Lead__c;
e.parentID = j.id;
insert e;
PageReference jobPage = new ApexPages.StandardController(j).view();
jobPage.setRedirect(true);
return jobPage;
}
The idea is that the field iMedia_Lead__c is a user lookup. When someone edits a record and adds a value to the lookup field, the associated user then autofollows the record.
Any ideas what could be causing this error?
EDIT Just ot make sure I was referencing an ID object, I added the following:
public PageReference save() {
upsert j;
ID d = j.iMedia_Lead__c;
EntitySubscription e = new EntitySubscription();
e.SubscriberId = d;
e.parentID = j.id;
insert e;
PageReference jobPage = new ApexPages.StandardController(j).view();
jobPage.setRedirect(true);
return jobPage;
}
Still no dice, but I'm pretty sure I'm passing in the ID value correctly.
EDIT 2 So after some manipulation, I am now getting this error -
Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: duplicates value on record with id: : []
with this code snippet:
public PageReference save() {
upsert j;
if(j.iMediaLead__c != null)
{
EntitySubscription e = new EntitySubscription();
e.SubscriberId = j.iMediaLead__c;
e.parentID = j.id;
insert e;
}
}
And the error is occuring at insert e
. Any insights into this?