Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- plat2--> no document access records --> I have to update operation delete
- plat3---> no document access --> operation new
- plat2-->contains document access records --> Update operation delete
- plat3 -->contains document access records --> No Need to Update
- 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".
- public static void junctionDocDelete(List<JunctionPlatformDoc__c> JunctionDocList){
- List<Document_Access__c> DocList=new List<Document_Access__c>();
- List<Document_Access__c> DocList1=new List<Document_Access__c>();
- set<id> documentset=new set<id>();
- set<id> platformset=new set<id>();
- set<id>pltIds=new set<id>();
- //Get Platform for Inserted records
- for(JunctionPlatformDoc__c junc:JunctionDocList){
- documentset.add(junc.Document__c);
- platformset.add(junc.Platform__c);
- }
- //for that document find the platform
- 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];
- //finding Platform
- map<id,id> platformDocmap=new map<id,id>();
- for(JunctionPlatformDoc__c junction :junctionList )
- {
- pltIds.add(junction.Platform__c);
- platformDocmap.put(junction.Platform__c,junction.Document__c);
- }
- system.debug('####pltIds'+pltIds);
- //Query document Access
- List<Document_Access__c> documentList=[select id,Account__c,Processing__c,Updated_via__c,Operation__c,Platform__c from Document_Access__c];
- set<id>docmapId=new set<id>();
- for(Document_Access__c doc:documentList){
- docmapId.add(doc.Platform__c);
- }
- system.debug('docmapId@@@@@@@@'+docmapId);
- //Get other platforms from Junction Platform Doc for that document
- list<Junction_Platform__c> junctionPlat=[select id,Account__c,Platform__c from Junction_Platform__c where Platform__c in:pltIds];
- system.debug('###junction plat###'+junctionPlat);
- for(Junction_Platform__c junc:junctionPlat)
- {
- if(docmapId.contains(junc.Platform__c) && platformset.contains(junc.Platform__c)){
- Document_Access__c doc=new Document_Access__c();
- doc.Account__c=junc.Account__c;
- doc.Document__c=platformDocmap.get(junc.Platform__c);
- doc.Platform__c=junc.Platform__c;
- doc.Processing__c=false;
- doc.Operation__c='New';
- doc.Junction_Platform__c=junc.id;
- doc.Updated_via__c='Junction Platform Doc';
- DocList1.add(doc);
- }
- else if(!docmapId.contains(junc.Platform__c)&& platformset.contains(junc.Platform__c) ){
- Document_Access__c doc=new Document_Access__c();
- doc.Account__c=junc.Account__c;
- doc.Document__c=platformDocmap.get(junc.Platform__c);
- doc.Platform__c=junc.Platform__c;
- doc.Processing__c=false;
- doc.Operation__c='Delete';
- doc.Junction_Platform__c=junc.id;
- doc.Updated_via__c='Junction Platform Doc';
- DocList.add(doc);
- }else if(!docmapId.contains(junc.Platform__c)){
- Document_Access__c doc=new Document_Access__c();
- doc.Account__c=junc.Account__c;
- doc.Platform__c=junc.Platform__c;
- doc.Processing__c=false;
- doc.Operation__c='New';
- doc.Junction_Platform__c=junc.id;
- doc.Updated_via__c='Junction Platform Doc';
- DocList.add(doc);
- }
- }
- if(!DocList.isEmpty()){
- Insert DocList;
- }
- if(!DocList1.isEmpty()){
- Update DocList1;
- }
- }
Add Comment
Please, Sign In to add comment