You need to sign in to do that
Don't have an account?
Apex Trigger to copy Encrypted field from Std Obj to Custom Obj
I am working on creating an Apex Trigger to copy the SSN from Contact to a Custom Object. The Custom Object has the ID of the Contact Record. It is not copying the data. I only want this if the SSN field on the Custom Object is blank and only when a new Custom Object Record is created. I have tried a couple of different ways based on some searches for how to write a trigger.
Here is my current Trigger:
trigger Set_SSN_Registration on Registration__c (before insert)
{
Set<Id> IndId = new Set<Id>();
for (Registration__c reg : Trigger.new)
IndId.add(reg.Individual__c);
//Contact ssn = [
// SELECT SSN_Tax_ID__c from Contact
// WHERE ID = :IndId
// ];
Map<Id, Contact> entries = new Map<Id, Contact>(
[select SSN_Tax_ID__c from Contact
where id in :IndId]);
for (Registration__c reg :trigger.new){
if(reg.SSN_Tax_ID__c == null){
reg.SSN_Tax_ID__c = entries.get(reg.Individual__c).SSN_Tax_ID__c;
}
}
}