Essentially what I'm looking for is the Apex equivalent of the javascript delete operator
The reason I want to do this is that I want to store data in the standard Contact.Email
field, but I need to handle the possibility that the data coming in could cause a save error with a INVALID_EMAIL_ADDRESS status code. I want to be able to detect the error, and retry the upsert with the value provided for the email address being stored into a new custom text field instead. To do this, I need to clear the value in the object's Email
field. Since this is an upsert operation, I don't want to set the value of the field to NULL
since that will clear the value in the database, which I would want to leave intact if it is already present.
Basically, what I'm looking for is the easiest way to get from:
Contact:{LastName=LastName, Email=FirstName.LastName@@Company.com, Id=003p000000LO97zAAD, ...}
to:
Contact:{LastName=LastName, Email__c=FirstName.LastName@@Company.com, Id=003p000000LO97zAAD, ...}
and specifically not:
Contact:{LastName=LastName, Email=null, Email__c=FirstName.LastName@@Company.com, Id=003p000000LO97zAAD, ....}
object
I thought you meant needing to use metadata api to physical alter the structure of the object/table, not your apex variable. Or re-phrase as "object variable"? Thanks! – Doug Ayers Nov 23 '17 at 5:28sObject
does give you more to work with, and I was specifically concerned about the effects on DML operations, so I'd be willing to update the question. – martin Nov 23 '17 at 6:34