You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Iterating over same list twice
I think I am iterating ov erht same list twice. Will someone help me streamline the code. Can I get the second for loop inside the first and be efficient?
Attachment__c newAttachment = (Attachment__c ) so; String objectType; List<Plan__c > palnId = new List<Plan__c>(); Map<String,String> planMap = new Map<String,String>(); if( this.linkMap.containsKey( newAttachment.ContentDocumentId__c ) ){ List<ContentDocumentLink> links = this.linkMap.get( newAttachment.ContentDocumentId__c ); if( !links.isEmpty() ){ for( ContentDocumentLink link : links ){ objectType = String.valueOf( link.LinkedEntityId.getSObjectType() ); switch on ( objectType ){ when 'Activity__c' { newAttachment.Activity__c= link.LinkedEntityId; } when 'Project__c' { newAttachment.Proj__c= link.LinkedEntityId; } } } } List<Plan__c> plans= new List<Plan__c>(); for (ContentDocumentLink cont : links ){ if(newAttachment.Activity__c != null || newAttachment.Proj__c != null){ ContentDocumentLink cdl = new ContentDocumentLink(); cdl.LinkedEntityId = parentId; cdl.ContentDocumentId = cont.ContentDocumentId; cdl.ShareType = 'V'; cdl.Visibility = 'AllUsers'; cdl_List.add(cdl); break; } } }
this part: I would have the method accept the List of CDL and the whatever parameters are required to create the record. From the snippet, it's hard to be clear by probably
then in your first loop I think that should point you in the right direction
regards
Andrew