Guest User

Untitled

a guest
May 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. plat2--> no document access records --> I have to update operation delete
  2. plat3---> no document access --> operation new
  3.  
  4. plat2-->contains document access records --> Update operation delete
  5. plat3 -->contains document access records --> No Need to Update
  6.  
  7. There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger S360_JunctionplatformdocDATrigger caused an unexpected exception, contact your administrator: S360_JunctionplatformdocDATrigger: execution of BeforeDelete caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Class.S360_JunctionPlatformDocDetails.junctionDocDelete: line 157, column 1".
  8.  
  9. public static void junctionDocDelete(List<JunctionPlatformDoc__c> JunctionDocList){
  10. List<Document_Access__c> DocList=new List<Document_Access__c>();
  11. List<Document_Access__c> DocList1=new List<Document_Access__c>();
  12. set<id> documentset=new set<id>();
  13. set<id> platformset=new set<id>();
  14. set<id>pltIds=new set<id>();
  15.  
  16.  
  17. //Get Platform for Inserted records
  18. for(JunctionPlatformDoc__c junc:JunctionDocList){
  19. documentset.add(junc.Document__c);
  20. platformset.add(junc.Platform__c);
  21. }
  22. //for that document find the platform
  23. List<JunctionPlatformDoc__c> junctionList = [select Document__r.Name,Document__r.Description__c,Document__r.recordtypeId,Document__r.recordtype.name,Document__c,Platform__c,Platform__r.Name from JunctionPlatformDoc__c where Document__c in :documentset];
  24.  
  25.  
  26. //finding Platform
  27. map<id,id> platformDocmap=new map<id,id>();
  28. for(JunctionPlatformDoc__c junction :junctionList )
  29. {
  30.  
  31. pltIds.add(junction.Platform__c);
  32. platformDocmap.put(junction.Platform__c,junction.Document__c);
  33. }
  34.  
  35. system.debug('####pltIds'+pltIds);
  36. //Query document Access
  37.  
  38. List<Document_Access__c> documentList=[select id,Account__c,Processing__c,Updated_via__c,Operation__c,Platform__c from Document_Access__c];
  39. set<id>docmapId=new set<id>();
  40. for(Document_Access__c doc:documentList){
  41. docmapId.add(doc.Platform__c);
  42. }
  43. system.debug('docmapId@@@@@@@@'+docmapId);
  44.  
  45. //Get other platforms from Junction Platform Doc for that document
  46. list<Junction_Platform__c> junctionPlat=[select id,Account__c,Platform__c from Junction_Platform__c where Platform__c in:pltIds];
  47.  
  48. system.debug('###junction plat###'+junctionPlat);
  49. for(Junction_Platform__c junc:junctionPlat)
  50. {
  51.  
  52. if(docmapId.contains(junc.Platform__c) && platformset.contains(junc.Platform__c)){
  53. Document_Access__c doc=new Document_Access__c();
  54. doc.Account__c=junc.Account__c;
  55. doc.Document__c=platformDocmap.get(junc.Platform__c);
  56. doc.Platform__c=junc.Platform__c;
  57. doc.Processing__c=false;
  58. doc.Operation__c='New';
  59. doc.Junction_Platform__c=junc.id;
  60. doc.Updated_via__c='Junction Platform Doc';
  61. DocList1.add(doc);
  62. }
  63.  
  64. else if(!docmapId.contains(junc.Platform__c)&& platformset.contains(junc.Platform__c) ){
  65. Document_Access__c doc=new Document_Access__c();
  66. doc.Account__c=junc.Account__c;
  67. doc.Document__c=platformDocmap.get(junc.Platform__c);
  68. doc.Platform__c=junc.Platform__c;
  69. doc.Processing__c=false;
  70. doc.Operation__c='Delete';
  71. doc.Junction_Platform__c=junc.id;
  72. doc.Updated_via__c='Junction Platform Doc';
  73. DocList.add(doc);
  74.  
  75. }else if(!docmapId.contains(junc.Platform__c)){
  76. Document_Access__c doc=new Document_Access__c();
  77. doc.Account__c=junc.Account__c;
  78. doc.Platform__c=junc.Platform__c;
  79. doc.Processing__c=false;
  80. doc.Operation__c='New';
  81. doc.Junction_Platform__c=junc.id;
  82. doc.Updated_via__c='Junction Platform Doc';
  83. DocList.add(doc);
  84.  
  85. }
  86.  
  87. }
  88. if(!DocList.isEmpty()){
  89. Insert DocList;
  90. }
  91.  
  92. if(!DocList1.isEmpty()){
  93. Update DocList1;
  94. }
  95.  
  96. }
Add Comment
Please, Sign In to add comment