Guest User

Untitled

a guest
Aug 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. trigger BIIB_GenerateSOB_Autoclosure on Attachment (after insert) {
  2.     
  3. String wi_Item='Generate SOB';
  4. String sr_type='Benefit Investigation';
  5. Set<Id> attachIds = new Set<Id>(); 
  6. List<Attachment> sr_attachment = new List<Attachment>();
  7. List<BIIB_Work__c> updateSOB_WI = new List<BIIB_Work__c>();
  8.  
  9.     for(Attachment atc: Trigger.new){
  10.         if(atc.ParentId.getSobjectType() == Case.SobjectType)
  11.             attachIds.add(atc.ParentId);
  12.     }
  13.     
  14. List<BIIB_Work__c> sobWI = [select id,Name,BIIB_Case__r.Id,BIIB_Case__r.BIIB_SR_Type__c from BIIB_Work__c where BIIB_Case__r.Id IN :attachIds and Name=:wi_Item and BIIB_Case__r.BIIB_SR_Type__c =:sr_type limit 49999];
  15.     if(sobWI.size()>0)
  16.     {
  17.         sr_attachment = [select id from Attachment where ParentId=: sobWI[0].BIIB_Case__r.Id];
  18.     }
  19.     if(!sr_attachment.isEmpty()){
  20.         for (BIIB_Work__c work: sobWI){
  21.              work.BIIB_Result__c = 'BI Complete' ;
  22.              work.BIIB_Status__c = 'Closed' ;
  23.              updateSOB_WI.add(work);
  24.         }
  25.       }
  26.     if(!updateSOB_WI.isEmpty())
  27.         Database.update(updateSOB_WI, false);  
  28.     
  29. }
Add Comment
Please, Sign In to add comment