• Phuc Nguyen 18
  • SMARTIE
  • 500 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 80
    Questions
  • 113
    Replies
Having issue getting map value.  
Template is a lookup field.  If the lookfield has a value where Require_Num__c = true I want the same value on the Activity record to be true also.  There are several templates so I want to only update Activities where the template has the Require_Num__c = true.
I know I have the right map the map size is 1 since I have only set the field to True on one template.  Just not able to select it in the value.  Right now the activity record field is false when it should be true.
Thanks,
if (Trigger.isInsert){
            List<Id> activityIds = new List<Id>();
        
            for (Activity__c act :(List<Activity__c >) trigger.New)
                {
                    activityIds.add(act.Activity_Template__c);

                }

            if(activityIds.size() > 0){
                list<Activity_Template__c> activitytemplate = [Select Name,Id,Require_Num__c
                                    FROM Activity_Template__c 
                                    WHERE Name,Id,Require_Num__c = true
                                    AND Id in : activityIds]; 
                
                atMap = new Map<Boolean,Activity_Template__c>();
                
                for (Activity_Template__c acts : activitytemplate){
                    atMap.put(acts.Name,Id,Require_Num__c,acts);
                }
            }
            system.debug('map size' + atMap.size() );
            for (Activity__c activities : (List<Activity__c >) trigger.New){
                if (atMap.containsKey(activities.Activity_Template__r.Id)){
                    activities.Name,Id,Require_Num__c = true;
                }
            }
        }

 
Hello All,
I have a custom Lookup component  - LWC
I need to ge the filter information for any lookups that has an active filter
Tried using Schema.DescribeFieldResult but no luck.  Anyone know how I can return the filter information?
Thanks,
P
I have a couple questions regarding filtered lookups and LWC. I have a lightning component wrapped in a LWC. On a create page I have a couple filtered lookup fields that are filtered based on values selected on the lightning component create page. I read that filtered lookups are not supported in lightning components and you need a custom lookup component.

So My first question is can I use something like this to resolve my issue: https://sfcure.com/2019/07/06/showing-a-lookup-field-which-respects-with-lookup-filters/

Second. Do I need a separate custom lookup component for each filtered lookup field?
Thanks
P
Hello All,
Wil someone assist me on how to get test coverage for my class?  No coverage at all for 
if( Trigger.isInsert){
        List<String> zips = new List<String>();

        for (Site__c site :(List<Site__c >) trigger.New)
        {
            zips.add(site.Zip_Code__c);
        }
              List<AggregateResult> zipcodes = [SELECT count(Id) zipids,Zip_Code__c zips FROM Site__c where Zip_Code__c in : zips
              GROUP BY Zip_Code__c];
            
                for (Site__c newsite : (List<Site__c> ) trigger.New){

                string fieldtype = newsite.Site_Type__c == 'Field' ? 'F' : 'R';
                
                Map<String,Integer> mapzips = new Map<String,Integer>();

                for(AggregateResult aggResult : zipcodes)
                    {
                        mapzips.put((String)aggResult.get('zips'), (Integer)aggResult.get('zipids'));
                    }
                
                if(mapzips.size()>0){ 
                    for(AggregateResult result :zipcodes)
                        {
                            string sitename = fieldtype;
                            string postal  = newsite.Zip_Code__c;
                            integer sitenum = ((integer)result.get('zipids')) +1;
                            newsite.Name = fieldtype +'_'+ newsite.Zip_Code__c +'_'+ sitenum;  
                        }
                    }else
                        {
                            string sitename = fieldtype;
                            string postal  = newsite.Zip_Code__c;
                            integer sitenum = 1;
                            newsite.Name = fieldtype +'_'+ newsite.Zip_Code__c +'_'+ sitenum; 
                        }
                }
        }
 
static testMethod void TestBasicTriggerFunctions(){
       Site__c site = new Site__c(
                Name = 'Test Site',
               Type__c = 'COW',
               Site_Status__c = 'Archived'

        );
        insert site;

       Site__c site2 = new Site__c(
            Name = 'Test Site2',
           Site_Type__c = 'COW',
           Site_Status__c = 'Select One'

            );
        insert site2;

        List<Site__c> sites = [ SELECT Id,Site_Type__c,Name FROM Site__c ];
        System.assertEquals( 2, sites.size() );

        site.Site_Status__c = 'Backlog';
        update site;

        System.assertEquals( 'Backlog', [ SELECT Id, Site_Status__c FROM Site__c WHERE Id =: site.Id LIMIT 1 ].Site_Status__c );

        site.Site_Status__c = 'Active';
        update site;
        
        System.assertEquals( 'Active', [ SELECT Id, Site_Status__c FROM Site__c WHERE Id =: site.Id LIMIT 1 ].Site_Status__c );

        delete site;
        
        System.assertEquals( 0, [ SELECT COUNT() FROM Site__c WHERE Id =: site.Id ] );
    }
}

Thank you,
P
Hello All,'
Trying to get count of records that has the same matching field value as the record being saved.  Tried mapping but could never get teh correct value.  Will someone assist with geving an example of using the aggregate function to ge tthe count?  Example record being created has a text field Test__c and a value of dog.  Need to find all of the existing records with the value dog in the Test__c  field.
Thanks you for your time,
P
I am having an issue populating a map.  When a user saves a record it will have a postal code.  I am trying to determine if there are existing records with the same postal code.  'prod' is always.  How do I determine if other records have the same postal code?
thanks
P
if( Trigger.isInsert){
            Map<String, Product__c>  prodMap = new Map<String, Product__c>
            ([select id,Zip_Code__c,Type__c from Product__c]);
        
            for (Product__c newprod : (List<Product__c>) trigger.New)
            {
                Product__c prod= prodmap.containskey(newprod.Zip_Code__c) ? prodmap.get(newprod.Zip_Code__c) : null; 
                string fieldtype = newprod.Type__c == 'Field' ? 'F' : 'R';
            
                if(prod!= null){
                    string prodname = fieldtype;
                    string postal  = newprod.Zip_Code__c;
                    integer prodnum = prodMap.size()+1;
                    newprod.Name = fieldtype +'_'+ newprod.Zip_Code__c +'_'+ prodnum;  
                }
            }
        }

 
On creation of a record I need to update its name based on a value on existing records.
For example a new record is created and the code Id is 12345
If a record exist with this value I need to set the new record code Id to 12345_001.  This will continue so if the latestcode ID value is 12345_054 the new code Id needs to be 12345_055
So how do I search for this value and set the new one?   Will this be an issue on data loads?
Thanks,
P​​​​​​​  
Hello All,
Need some help creating a process for creating an object name.  So the name will be a text value plus an auto incremetnted value.
For example Opportunity created would be 'Test_001 '
But what if the count is up to Test_089 and they need to delete 5 opportunities and the opportunities are in different sequences?  So they need to delete Test_055 and Test_041 and Test_020.  The naming needs to stay in sequencial order.  Is this possible?
How do I handle the naming when they do a data load?   
Thanks,
P
Having an issue getting coverage for mapping
global class Clarke_AttachmentTriggerHandler {
    
    Map<Id, List<ContentDocumentLink>> linkMap = new Map<Id, List<ContentDocumentLink>>();
    Map<String, Directory__c> directoryMap = new Map<String, Directory__c>();
    List<ContentDocumentLink> cdl_List = new List<ContentDocumentLink>();
    public ContentDocumentLink cdl = New ContentDocumentLink();

    global override void bulkBeforeExtended() {
        if( Trigger.isUpdate ){
            List<Id> docIds = new List<Id>();
            List<String> parentIds = new List<String>();
            List<String> categoryvals = new List<String>();

            for( Attachment__c record : ( List<Attachment__c> ) Trigger.new ){
                Id docId = record.ContentDocumentId__c;
                    String parentId = record.Parent_ID__c ;
                    Id recId = Id.valueOf(record.Parent_ID__c ); 
                    String parentObjectType = String.valueOf( recId.getSObjectType() );
                    if( parentObjectType == 'Activity__c' ){
                        parentId = record.Proj__c;
                    }
                    if( docId != null ){    
                        docIds.add( docId );
                    }
                    if( parentId != null ){    
                        parentIds.add( parentId );
                    }    
            }

            list<Directory__c> dirs = [
                SELECT id,Directory_Template__c,Name,ParentId__c,Sobject__c,
                    (Select Id,Name, Directory__c, Folder_Template__c,Parent_File_Folder__c FROM File_Folders__r ORDER BY Name)
                FROM Directory__c 
                WHERE ParentId__c IN: parentIds
            ];

            if( !dirs.isEmpty() ){
                for( Directory__c dir : dirs ){
                    this.directoryMap.put( dir.ParentId__c, dir );
                }
            }

            List<ContentDocumentLink> linkList = [ SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: docIds ];
            if( !linkList.isEmpty() ){
                for( ContentDocumentLink link : linkList ){
                    List<ContentDocumentLink> links = this.linkMap.containsKey( link.ContentDocumentId )
                        ? this.linkMap.get( link.ContentDocumentId ) : new List<ContentDocumentLink>();
                    links.add( link );
                    this.linkMap.put( link.ContentDocumentId, links );
                }
            }
        }
    }
    global override void bulkAfterExtended() {}

    global override void beforeInsertExtended(SObject so) {
       Attachment__c newAttachment = ( Attachment__c ) so;

        if( this.linkMap.containsKey( newAttachment.ContentDocumentId__c ) ){
            List<ContentDocumentLink> links = this.linkMap.get( newAttachment.ContentDocumentId__c );
            if( !links.isEmpty() ){
                for( ContentDocumentLink link : links ){
                    String objectType = String.valueOf( link.LinkedEntityId.getSObjectType() );
                    Directory__c dir = this.directoryMap.containsKey( link.LinkedEntityId )
                        ? this.directoryMap.get( link.LinkedEntityId ) : null;
                    if( dir != null ){
                        switch on ( objectType ){
                            when 'Site__c' {
                                newAttachment.Site__c = link.LinkedEntityId;
                            }
                            when 'Programme__c' {
                                newAttachment.Programme__c = link.LinkedEntityId;
                            }
                            when 'Activity__c' {
                               newAttachment.Activity__c= link.LinkedEntityId;
                            }
                            when 'Project__c' {
                                newAttachment.Proj__c = link.LinkedEntityId;
                            }
                        }
                    }
                }
            }
        }
    }
    global override void beforeUpdateExtended(SObject oldso, SObject newso) {
        Attachment__c newAttachment = ( Attachment__c ) newSo;
        String folderparentId = newAttachment.Parent_Id__c;
        Id recId = Id.valueOf(newAttachment.Parent_ID__c );
        String parentObjectType = String.valueOf( recId.getSObjectType() );

        if( parentObjectType == 'Activity__c' ){
            folderparentId = newAttachment.Proj__c;
        }

        if( directoryMap.containsKey( folderparentId)){           
            Directory__c dir = this.directoryMap.get( folderparentId );
            List<File_Folder__c> folders = dir.File_Folders__r;
            List<ContentDocumentLink> links = this.linkMap.get( newAttachment.ContentDocumentId__c );

            for (ContentDocumentLink cont : links ){
                for (File_Folder__c folder: folders ){
                    if(newattachment.Document_Type__c == folder.name ){
                        ContentDocumentLink cdl = new ContentDocumentLink();
                        cdl.LinkedEntityId = folder.Id;
                        cdl.ContentDocumentId = cont.ContentDocumentId;
                        cdl.ShareType = 'V';
                        cdl.Visibility = 'AllUsers';

                        newAttachment.File_Folder__c = folder.Id;
                        cdl_List.add(cdl);
                        break;
                    }
                }
            }
        }
    }
    global override void afterUpdateExtended(SObject oldso, SObject newso) {}
    global override void afterInsertExtended(SObject newso) {} 
    global override void andFinallyExtended() {
    
      if (!Trigger.isDelete) {
            if (Trigger.isUpdate) {
                try {
                    if (cdl_List.size() > 0) {
                        insert cdl_List;
                    }
                } catch (Exception e) {
                    System.debug('Error: ' + e.getMessage());
                }
            }
        }
    }
}

Test Class
@isTest
private class Clarke_AttachmentTriggerHandlerTest {
     @TestSetup
    static void CreateTestData() {
        
        Site__c site = new Site__c(Name = 'Test Site');
        insert site;

        System.assert(site.Id != null);

        Project_Template__c newTemplate = new Project_Template__c(
            Name = 'test template'
        );
        insert newTemplate;

        Project__c proj = new Project__c(
           Site__c = site.id
          
        );
        insert proj;

        Activity__c activity = new Activity__c(
            Project__c = proj.Id
        );
        insert activity;

        Programme__c programme = new Programme__c(Name = 'Test Program');
        insert programme;

        List<Attachment__c> attachments = new List<Attachment__c>{
            new Attachment__c(Parent_ID__c = site.Id),
            new Attachment__c(Parent_ID__c = proj.Id),
            new Attachment__c(Parent_ID__c = programme.Id),
            new Attachment__c()
        };
        insert attachments;

        attachments = [SELECT Id,Document_Type__c,Name FROM Attachment__c WHERE Site__r.Name = 'Test Site'];
        System.assertEquals(1, attachments.size(), 'Site attachment records');
        
         Directory_Template__c dt = new Directory_Template__c(
            Name = 'Test Directory Template'
        );
        insert dt;

        //dt.Active__c = true;
        //update dt;

        File_Folder_Template__c ft = new File_Folder_Template__c(
            Name = 'Test Folder Template',
            Directory_Template__c = dt.Id
        );
        insert ft;

        File_Folder_Template__c ftc = new File_Folder_Template__c(
            Name = 'Test Folder Template Child',
            Directory_Template__c = dt.Id,
            Parent_Folder_Template__c = ft.id
        );
        insert ftc; 
    }
    
    @isTest
    private static void TestFunction(){
    
     Test.startTest();
     List<Project_Template__c> templates = [
              SELECT Id FROM Project_Template__c
                ];
    
      List<Site__c> sites = [SELECT Id FROM Site__c];
                System.assertEquals( 1, sites.size(), '1 site found' );
                
            Project__c proj = new Project__c(
           Site__c =  sites[ 0 ].Id
           
        );
        insert proj;

        ContentVersion ContentDoc = new ContentVersion();
        ContentDoc.Title = 'Test Title';
        ContentDoc.ContentUrl= 'test.com';
        Insert ContentDoc;
    
            ContentVersion contentVersion = new ContentVersion(
                    Title          = 'a picture',
                    PathOnClient   = 'Pic.jpg',
                    VersionData    = Blob.valueOf('Test Content'),
                    IsMajorVersion = true);
            insert contentVersion;

            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

            ContentDocumentLink cdl = new ContentDocumentLink();
            cdl.LinkedEntityId = proj.Id;
            cdl.ContentDocumentId = documents[0].Id;
            cdl.ShareType = 'V';
            cdl.Visibility = 'AllUsers';
            insert cdl;
            
            List<ContentDocument> cdList = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            List<ContentDocumentLink> files=[SELECT Id, ContentDocumentId, ContentDocument.LatestPublishedVersionId, LinkedEntityId, ContentDocument.Title 
                                         from ContentDocumentLink where ContentDocumentId =: documents[0].Id]; 
     Test.stopTest();

    }
}

I am having an issue with the mapping/containsKey
Never goes past:
if( this.linkMap.containsKey( newAttachment.ContentDocumentId__c ) ){
or 
if( directoryMap.containsKey( folderparentId)){
Any suggestion is appreciated.
Thanks 
P
 
Hello,
Does anyone have any ideas on how to prepopulete a look up field on a create page in communities?  A contact is associated to an Account and I need to prepopulte the account field on the create record page.  
Thanks,
P
Hello All,
Looking for ieas on how to have an uploaded file in 2 locations.
So I am going to upload a file on a related record.  During upload there will be a picklist with set vlaues.  Thes evalues will have teh same name of other related records on teh same parent.  I was thinking :
  • Could  the file be uploaded and moved to the new location and then place a hyperlink on teh original record as a placeholder. 
Is that a good approach and is it even feasible?  Open to other ideas.  So need to be able to 1 file uploaded but accessible in 2 locations.

Thanks,
P
Hello,
Need some helkp with communities hyperrlink.  How do I create a hyperlink in communities that wil take the user to the record create page?  Is this possible? 
Thanks,
P
Hello,
I have a LWC tree grid that shows the aprent and child records.  How can I expand this to the grandchild records?
Thanks,
Hello All,
I need to query a parent(contractors)/Child(subcontractors) records/grand child records(attachments). Will someone help me with the query traversing up from the attachment?
Thanks,
P

 
Hello,
I am having an issue where I am adding a quickaction to create a child record but the record type selector is not popping up.  The Action is a lightning component.  profile has access to record type.  Was working before I added componet.
Thanks,

Hello,
I have a LWC wrapped inside an aura component.  Works great except it flashes a bief error message.  But still saves new record and navigates to new record.  Is there a way to suppress the error message?  Not sure if its in the LWC or aura component though.  Error message references google map api but see this in other org but no error message.  Error message is in a scratch org.
Thanks
P

I am overriding a new button on a custom object with an  aura component(LWC wrapped inside Aura).  How do I get the record Type  that the user has selected and pass it to the LWC?  The reason I need this is that the picklist values are based on the record type.
 
Thanks
P
Need help counting the number of files atatched to a custom object.
Should I be looking at ContentDocumentLinks
 
if ( Trigger.isInsert || Trigger.isDelete ){
            Set<Id> FileCount = new Set<Id>();

            for(SObject cdl : Trigger.new){
                ContentDocumentLink cdls = ( ContentDocumentLink ) cdl;

                FileCount.add(cdls.LinkedEntityId);
            }

            List<File_c> fileList = [SELECT Id, (SELECT Id FROM ContentDocumentLinks) 
            FROM File_c WHERE Id IN :FileCount];

            for(File_c fl : fileList){

                fl.Number_of_Files__c = fileList.size();

            }
        }

 
Hello All,
I have a LWC wrapped inside an aura component.
This is used in a Quick action.
I am trying to redirect to the newly created child record but the page save but does not redirect.  It stays on the parent record.
Code is called on success:
import {CurrentPageReference,NavigationMixin} from 'lightning/navigation'   

export default class GetValueInLWC extends NavigationMixin (LightningElement)  {

this[NavigationMixin.Navigate]({
                type: 'standard__recordPage',
                attributes: { 
                     recordId: event.detail.id,
                     objectApiName: 'Payment_Term__c', 
                     actionName: 'view'
                } 
            });
I know I am getting the new record id but it does not redirect.  Is it becuase the LWC is wrapped in an aura component?  What are my options?
Thanks,
P
 
Currently have an aura component where the Salesforce object is hard coded in the cmp and design file.

Is there a way to use a CMT set by the user to determine object?  So if the cmt value is Contact pass in Contact or if Account pass in Account and so on.

I know I can create a controller to query the cmt but now sure how to utilize it in the component
 
@AuraEnabled
        public static List < File_Object__mdt > fetchObject() {
            return [ SELECT object__c FROM file_Object__mdt ];
        }

 
Hello All,
I have a custom Lookup component  - LWC
I need to ge the filter information for any lookups that has an active filter
Tried using Schema.DescribeFieldResult but no luck.  Anyone know how I can return the filter information?
Thanks,
P
I have a couple questions regarding filtered lookups and LWC. I have a lightning component wrapped in a LWC. On a create page I have a couple filtered lookup fields that are filtered based on values selected on the lightning component create page. I read that filtered lookups are not supported in lightning components and you need a custom lookup component.

So My first question is can I use something like this to resolve my issue: https://sfcure.com/2019/07/06/showing-a-lookup-field-which-respects-with-lookup-filters/

Second. Do I need a separate custom lookup component for each filtered lookup field?
Thanks
P
I am having an issue populating a map.  When a user saves a record it will have a postal code.  I am trying to determine if there are existing records with the same postal code.  'prod' is always.  How do I determine if other records have the same postal code?
thanks
P
if( Trigger.isInsert){
            Map<String, Product__c>  prodMap = new Map<String, Product__c>
            ([select id,Zip_Code__c,Type__c from Product__c]);
        
            for (Product__c newprod : (List<Product__c>) trigger.New)
            {
                Product__c prod= prodmap.containskey(newprod.Zip_Code__c) ? prodmap.get(newprod.Zip_Code__c) : null; 
                string fieldtype = newprod.Type__c == 'Field' ? 'F' : 'R';
            
                if(prod!= null){
                    string prodname = fieldtype;
                    string postal  = newprod.Zip_Code__c;
                    integer prodnum = prodMap.size()+1;
                    newprod.Name = fieldtype +'_'+ newprod.Zip_Code__c +'_'+ prodnum;  
                }
            }
        }

 
On creation of a record I need to update its name based on a value on existing records.
For example a new record is created and the code Id is 12345
If a record exist with this value I need to set the new record code Id to 12345_001.  This will continue so if the latestcode ID value is 12345_054 the new code Id needs to be 12345_055
So how do I search for this value and set the new one?   Will this be an issue on data loads?
Thanks,
P​​​​​​​  
Hello All,
Need some help creating a process for creating an object name.  So the name will be a text value plus an auto incremetnted value.
For example Opportunity created would be 'Test_001 '
But what if the count is up to Test_089 and they need to delete 5 opportunities and the opportunities are in different sequences?  So they need to delete Test_055 and Test_041 and Test_020.  The naming needs to stay in sequencial order.  Is this possible?
How do I handle the naming when they do a data load?   
Thanks,
P
Having an issue getting coverage for mapping
global class Clarke_AttachmentTriggerHandler {
    
    Map<Id, List<ContentDocumentLink>> linkMap = new Map<Id, List<ContentDocumentLink>>();
    Map<String, Directory__c> directoryMap = new Map<String, Directory__c>();
    List<ContentDocumentLink> cdl_List = new List<ContentDocumentLink>();
    public ContentDocumentLink cdl = New ContentDocumentLink();

    global override void bulkBeforeExtended() {
        if( Trigger.isUpdate ){
            List<Id> docIds = new List<Id>();
            List<String> parentIds = new List<String>();
            List<String> categoryvals = new List<String>();

            for( Attachment__c record : ( List<Attachment__c> ) Trigger.new ){
                Id docId = record.ContentDocumentId__c;
                    String parentId = record.Parent_ID__c ;
                    Id recId = Id.valueOf(record.Parent_ID__c ); 
                    String parentObjectType = String.valueOf( recId.getSObjectType() );
                    if( parentObjectType == 'Activity__c' ){
                        parentId = record.Proj__c;
                    }
                    if( docId != null ){    
                        docIds.add( docId );
                    }
                    if( parentId != null ){    
                        parentIds.add( parentId );
                    }    
            }

            list<Directory__c> dirs = [
                SELECT id,Directory_Template__c,Name,ParentId__c,Sobject__c,
                    (Select Id,Name, Directory__c, Folder_Template__c,Parent_File_Folder__c FROM File_Folders__r ORDER BY Name)
                FROM Directory__c 
                WHERE ParentId__c IN: parentIds
            ];

            if( !dirs.isEmpty() ){
                for( Directory__c dir : dirs ){
                    this.directoryMap.put( dir.ParentId__c, dir );
                }
            }

            List<ContentDocumentLink> linkList = [ SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: docIds ];
            if( !linkList.isEmpty() ){
                for( ContentDocumentLink link : linkList ){
                    List<ContentDocumentLink> links = this.linkMap.containsKey( link.ContentDocumentId )
                        ? this.linkMap.get( link.ContentDocumentId ) : new List<ContentDocumentLink>();
                    links.add( link );
                    this.linkMap.put( link.ContentDocumentId, links );
                }
            }
        }
    }
    global override void bulkAfterExtended() {}

    global override void beforeInsertExtended(SObject so) {
       Attachment__c newAttachment = ( Attachment__c ) so;

        if( this.linkMap.containsKey( newAttachment.ContentDocumentId__c ) ){
            List<ContentDocumentLink> links = this.linkMap.get( newAttachment.ContentDocumentId__c );
            if( !links.isEmpty() ){
                for( ContentDocumentLink link : links ){
                    String objectType = String.valueOf( link.LinkedEntityId.getSObjectType() );
                    Directory__c dir = this.directoryMap.containsKey( link.LinkedEntityId )
                        ? this.directoryMap.get( link.LinkedEntityId ) : null;
                    if( dir != null ){
                        switch on ( objectType ){
                            when 'Site__c' {
                                newAttachment.Site__c = link.LinkedEntityId;
                            }
                            when 'Programme__c' {
                                newAttachment.Programme__c = link.LinkedEntityId;
                            }
                            when 'Activity__c' {
                               newAttachment.Activity__c= link.LinkedEntityId;
                            }
                            when 'Project__c' {
                                newAttachment.Proj__c = link.LinkedEntityId;
                            }
                        }
                    }
                }
            }
        }
    }
    global override void beforeUpdateExtended(SObject oldso, SObject newso) {
        Attachment__c newAttachment = ( Attachment__c ) newSo;
        String folderparentId = newAttachment.Parent_Id__c;
        Id recId = Id.valueOf(newAttachment.Parent_ID__c );
        String parentObjectType = String.valueOf( recId.getSObjectType() );

        if( parentObjectType == 'Activity__c' ){
            folderparentId = newAttachment.Proj__c;
        }

        if( directoryMap.containsKey( folderparentId)){           
            Directory__c dir = this.directoryMap.get( folderparentId );
            List<File_Folder__c> folders = dir.File_Folders__r;
            List<ContentDocumentLink> links = this.linkMap.get( newAttachment.ContentDocumentId__c );

            for (ContentDocumentLink cont : links ){
                for (File_Folder__c folder: folders ){
                    if(newattachment.Document_Type__c == folder.name ){
                        ContentDocumentLink cdl = new ContentDocumentLink();
                        cdl.LinkedEntityId = folder.Id;
                        cdl.ContentDocumentId = cont.ContentDocumentId;
                        cdl.ShareType = 'V';
                        cdl.Visibility = 'AllUsers';

                        newAttachment.File_Folder__c = folder.Id;
                        cdl_List.add(cdl);
                        break;
                    }
                }
            }
        }
    }
    global override void afterUpdateExtended(SObject oldso, SObject newso) {}
    global override void afterInsertExtended(SObject newso) {} 
    global override void andFinallyExtended() {
    
      if (!Trigger.isDelete) {
            if (Trigger.isUpdate) {
                try {
                    if (cdl_List.size() > 0) {
                        insert cdl_List;
                    }
                } catch (Exception e) {
                    System.debug('Error: ' + e.getMessage());
                }
            }
        }
    }
}

Test Class
@isTest
private class Clarke_AttachmentTriggerHandlerTest {
     @TestSetup
    static void CreateTestData() {
        
        Site__c site = new Site__c(Name = 'Test Site');
        insert site;

        System.assert(site.Id != null);

        Project_Template__c newTemplate = new Project_Template__c(
            Name = 'test template'
        );
        insert newTemplate;

        Project__c proj = new Project__c(
           Site__c = site.id
          
        );
        insert proj;

        Activity__c activity = new Activity__c(
            Project__c = proj.Id
        );
        insert activity;

        Programme__c programme = new Programme__c(Name = 'Test Program');
        insert programme;

        List<Attachment__c> attachments = new List<Attachment__c>{
            new Attachment__c(Parent_ID__c = site.Id),
            new Attachment__c(Parent_ID__c = proj.Id),
            new Attachment__c(Parent_ID__c = programme.Id),
            new Attachment__c()
        };
        insert attachments;

        attachments = [SELECT Id,Document_Type__c,Name FROM Attachment__c WHERE Site__r.Name = 'Test Site'];
        System.assertEquals(1, attachments.size(), 'Site attachment records');
        
         Directory_Template__c dt = new Directory_Template__c(
            Name = 'Test Directory Template'
        );
        insert dt;

        //dt.Active__c = true;
        //update dt;

        File_Folder_Template__c ft = new File_Folder_Template__c(
            Name = 'Test Folder Template',
            Directory_Template__c = dt.Id
        );
        insert ft;

        File_Folder_Template__c ftc = new File_Folder_Template__c(
            Name = 'Test Folder Template Child',
            Directory_Template__c = dt.Id,
            Parent_Folder_Template__c = ft.id
        );
        insert ftc; 
    }
    
    @isTest
    private static void TestFunction(){
    
     Test.startTest();
     List<Project_Template__c> templates = [
              SELECT Id FROM Project_Template__c
                ];
    
      List<Site__c> sites = [SELECT Id FROM Site__c];
                System.assertEquals( 1, sites.size(), '1 site found' );
                
            Project__c proj = new Project__c(
           Site__c =  sites[ 0 ].Id
           
        );
        insert proj;

        ContentVersion ContentDoc = new ContentVersion();
        ContentDoc.Title = 'Test Title';
        ContentDoc.ContentUrl= 'test.com';
        Insert ContentDoc;
    
            ContentVersion contentVersion = new ContentVersion(
                    Title          = 'a picture',
                    PathOnClient   = 'Pic.jpg',
                    VersionData    = Blob.valueOf('Test Content'),
                    IsMajorVersion = true);
            insert contentVersion;

            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

            ContentDocumentLink cdl = new ContentDocumentLink();
            cdl.LinkedEntityId = proj.Id;
            cdl.ContentDocumentId = documents[0].Id;
            cdl.ShareType = 'V';
            cdl.Visibility = 'AllUsers';
            insert cdl;
            
            List<ContentDocument> cdList = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            List<ContentDocumentLink> files=[SELECT Id, ContentDocumentId, ContentDocument.LatestPublishedVersionId, LinkedEntityId, ContentDocument.Title 
                                         from ContentDocumentLink where ContentDocumentId =: documents[0].Id]; 
     Test.stopTest();

    }
}

I am having an issue with the mapping/containsKey
Never goes past:
if( this.linkMap.containsKey( newAttachment.ContentDocumentId__c ) ){
or 
if( directoryMap.containsKey( folderparentId)){
Any suggestion is appreciated.
Thanks 
P
 
Hello All,
Looking for ieas on how to have an uploaded file in 2 locations.
So I am going to upload a file on a related record.  During upload there will be a picklist with set vlaues.  Thes evalues will have teh same name of other related records on teh same parent.  I was thinking :
  • Could  the file be uploaded and moved to the new location and then place a hyperlink on teh original record as a placeholder. 
Is that a good approach and is it even feasible?  Open to other ideas.  So need to be able to 1 file uploaded but accessible in 2 locations.

Thanks,
P
Hello,
Need some helkp with communities hyperrlink.  How do I create a hyperlink in communities that wil take the user to the record create page?  Is this possible? 
Thanks,
P
Hello,
I have a LWC tree grid that shows the aprent and child records.  How can I expand this to the grandchild records?
Thanks,
I am overriding a new button on a custom object with an  aura component(LWC wrapped inside Aura).  How do I get the record Type  that the user has selected and pass it to the LWC?  The reason I need this is that the picklist values are based on the record type.
 
Thanks
P
Need help counting the number of files atatched to a custom object.
Should I be looking at ContentDocumentLinks
 
if ( Trigger.isInsert || Trigger.isDelete ){
            Set<Id> FileCount = new Set<Id>();

            for(SObject cdl : Trigger.new){
                ContentDocumentLink cdls = ( ContentDocumentLink ) cdl;

                FileCount.add(cdls.LinkedEntityId);
            }

            List<File_c> fileList = [SELECT Id, (SELECT Id FROM ContentDocumentLinks) 
            FROM File_c WHERE Id IN :FileCount];

            for(File_c fl : fileList){

                fl.Number_of_Files__c = fileList.size();

            }
        }

 
Currently have an aura component where the Salesforce object is hard coded in the cmp and design file.

Is there a way to use a CMT set by the user to determine object?  So if the cmt value is Contact pass in Contact or if Account pass in Account and so on.

I know I can create a controller to query the cmt but now sure how to utilize it in the component
 
@AuraEnabled
        public static List < File_Object__mdt > fetchObject() {
            return [ SELECT object__c FROM file_Object__mdt ];
        }

 
Hello All,
I am using an aura compone to override a new button.  But the cancel does not have any effect and the window does not close after save.
If I stick the aura in a quick action it works but not when I use it to override the 'new' button.  Any thoughts? 
Hello All,
I have a VF page where I need to show the parent lookup field on the vf page. 
This page is the creation page of the child record.  
I have an extension but not able to grab the parent Id.
Extension is on the child object
Parent is AutoM__c
Child is Rental__c
Able to get fileds for child record but not parent.

Thanks,
P