Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Trigger updateContatoPonto on Ponto__c (before insert, before update) {
- // build a set of receivable Inscricao_Numero__c
- Set <Decimal> receberInscricaoNumero = new Set <Decimal> ();
- for(Ponto__c pontos : trigger.New)
- {
- receberInscricaoNumero.add(pontos.Inscricao_Numero__c);
- }
- // Map the contacts Inscricao_Numero__c and the actual contacts records based on the receivable Inscricao_Numero__c
- Map <Decimal, Contact> matchingcontactsMap = new Map <Decimal, Contact> ();
- for (Contact contacts : [Select Id, Inscricao_Numero__c From Contact Where Inscricao_Numero__c IN :receberInscricaoNumero])
- {
- matchingcontactsMap.put(contacts.Inscricao_Numero__c, contacts);
- }
- List <Ponto__c> receivablesToUpdate = new List <Ponto__c> ();
- for(Ponto__c pontos : trigger.New)
- {
- if (matchingcontactsMap.get(pontos.Inscricao_Numero__c) != null)
- {
- pontos.Contato__c = matchingcontactsMap.get(pontos.Inscricao_Numero__c).Id;
- }
- else {
- pontos.Contato__c = null;
- }
- }
- update receivablesToUpdate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement