Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. public class TempDeleteOpplgtwithnoOpp {
  2. Public void getalltodeleterecords()
  3. {
  4.  
  5. //*Map<ID, Opportunity> Oppmap = new map<id, Opportunity>([SELECT ID, NAME FROM Opportunity LIMIT 10]);
  6. Set<id> oppidlist = new Set<id>();
  7.  
  8. for(Opportunity opp : [SELECT ID FROM Opportunity])
  9. {
  10. oppidlist.add(opp.id);
  11. }
  12.  
  13. string OpplgtDelNoOppStringFinal =
  14.  
  15. 'ID'+','+'Name'+','+'CreatedDate'+','+'LastModifiedDate'+','+'Opportunity_Lgt_Name'+','+' Opportunity_id_txt __c'+'n';
  16.  
  17.  
  18. List<id> opplgttoDelIdSet = new List<ID>();
  19.  
  20. for(Opportunity_LGT__C opplgt : [SELECT ID, Name, CreatedDate, LastModifiedDate, Account_Code__c,
  21. Opportunity_Lgt_Name__c, Opportunity_id_txt __c FROM Opportunity_LGT__C] )
  22. {
  23. IF (!Oppidlist.contains(opplgt.id))
  24. {
  25. opplgttoDelIdSet.add(opplgt.id);
  26. String OpplgtDelNoOppString = opplgt.id +','+opplgt.name+','+opplgt.CreatedDate+','+opplgt.LastModifiedDate+','+opplgt.Opportunity_Lgt_Name__c+','+opplgt.Opportunity_Record_Id__c +'n';
  27. OpplgtDelNoOppStringFinal = OpplgtDelNoOppStringFinal+ OpplgtDelNoOppString ;
  28. }
  29. }
  30.  
  31. system.debug('Opplgtlist.size: ' + Oppidlist.size());
  32. system.debug('opplgttoDelIdSet.size:' + opplgttoDelIdSet.size());
  33.  
  34. Messaging.EmailFileAttachment DelOLNoOpp = new Messaging.EmailFileAttachment();
  35. Blob DelOLNoOppcsvBlob = Blob.valueof(OpplgtDelNoOppStringFinal);
  36. String DelOLNoOppcsvname = 'DelOLNoOppOL.csv';
  37. DelOLNoOpp.setFileName(DelOLNoOppcsvname);
  38. DelOLNoOpp.setBody(DelOLNoOppcsvBlob);
  39.  
  40.  
  41. Messaging.singleEmailMessage ademail = new Messaging.singleEmailMessage();
  42. List<String> toAddress = new List<String>{'raghavendra.shettigar@inventivHealth.com'};
  43. ademail.setSubject('OppLightDeleteFiles');
  44. ademail.setToAddresses(toAddress);
  45. ademail.setPlainTextBody('Opportunity Light Delete');
  46. ademail.setFileAttachments( new messaging.emailFileAttachment[]{DelOLNoOpp });
  47. Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.singleEmailMessage[]{ademail});
  48.  
  49. set<Id> accIds=new set<Id>();
  50. for(Opportunity opp:[Select AccountId from Opportunity where ID in :setoppIds]){
  51. accIds.add(opp.AccountId);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement