Skip to content

Instantly share code, notes, and snippets.

@brianmfear
Created July 31, 2016 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianmfear/9e4ba169b87d6a17b31a834714c4704d to your computer and use it in GitHub Desktop.
Save brianmfear/9e4ba169b87d6a17b31a834714c4704d to your computer and use it in GitHub Desktop.
trigger updateContatoPonto on Ponto__c (before insert, before update) {
Map<Integer, Id> contactsByNumber = new Map<Integer, Id>();
for(Ponto__c record: Trigger.new) {
if(record.Inscricao_Number__c != null) {
contactsByNumber.put(record.Inscricao_Numero__c.intValue(), null);
}
}
// Ignore null
contactsByNumber.remove(null);
for(Contact record: [SELECT Inscricao_Numero__c FROM Contact WHERE Inscricao_Numero__c IN :contactsByNumber.keySet()]) {
contactsByNumber.put(record.Inscricao_Numero__c.intValue(), record.Id);
}
for(Ponto__c record: Trigger.new) {
record.Contato__c = contactsByNumber.get(record.Inscricao_Numero__c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment