Created
July 31, 2016 06:06
-
-
Save brianmfear/9e4ba169b87d6a17b31a834714c4704d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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