0

Requirement is:

In case of Junction platform Doc delete.I have to update Junction platform Doc delete operation in document Access.

These are the few scenarios:

In doccument Access Object,


Below Scenario is working

Plat2 delete

 plat2--> no document access records --> I have to update operation delete 
 plat3---> no document access --> operation  new

This is not working:

plat2 delete

 plat2-->contains document access records --> Update operation delete
 plat3 -->contains document access records --> No Need to Update

Problem facing:

    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;
    }

}
4
  • You're updating Document_Access__c list but you need to specifically assign the Id to the Document_Access__c object while adding that to the list. If you're not assigning any Id on what basis it will update the Document_Access__c records. – RCS May 23 '18 at 7:04
  • ya got that. but i specified document access Id. but still its not working as expected. – Annappa May 23 '18 at 7:29
  • I cannot find you specified Id for Document_Access__c instance. Please post the updated code. – Reshma May 23 '18 at 8:54
  • ya.I have done some chnages in trigger it works for me. @RCS please make it comment as answer I will close the question. It helps me – Annappa May 23 '18 at 9:05
1

You're updating Document_Access__c list but you need to specifically assign the Id to the Document_Access__c object while adding that to the list. If you're not assigning any Id on what basis it will update the Document_Access__c records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.