• Paul 32
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi I have the following trigger that sits on leads, what it does is clones a files and attaches it to the lead. I need to write a test class, but I can only cover 45%, the part that isnt covered is the ContentVersion insert. Any help would be appreciated. 

trigger copyFiles on Lead (after insert) {       
    
    Lead lead = [Select AttachmentId__c From Lead where Id IN : Trigger.new];
    
    if(lead.AttachmentId__c == Null){ 
        //Do Nothing         
    } else { 
        
        Lead l = [Select Id, Patient_Referral_Id__c, AttachmentId__c From Lead where Id IN : Trigger.new];          
        
        ContentVersion  cont = [SELECT Checksum,ContentDocumentId,ContentLocation,ContentSize,ContentUrl,
                                Description,FileExtension,FileType,FirstPublishLocationId,Id,IsAssetEnabled,
                                IsDeleted,Origin,OwnerId,PathOnClient,PublishStatus,RatingCount,ReasonForChange,
                                SharingOption,Title,VersionData,VersionNumber 
                                FROM ContentVersion Where ContentDocumentId =: l.AttachmentId__c];          
        
            ContentVersion newcont = new ContentVersion();
            newcont.Title  = cont.Title;
            newcont.PathOnClient  = cont.PathOnClient;
            newcont.VersionData = cont.VersionData;
            newcont.FirstPublishLocationId  = l.Id;            
            insert newcont;      
    } 
}
I need help writing a test that contains Schema.PicklistEntry I have looked everywhere and cant figure this out, i am new to Apex so any help would be greatly appreciated. below is the method, which returns all picklists and values on the specifed object.

   
    public static List <String> getselectOptions(sObject objObject, string fld) {
        system.debug('objObject --->' + objObject);
        system.debug('fld --->' + fld);
        List < String > allOpts = new list < String > ();

        Schema.sObjectType objType = objObject.getSObjectType();        
   
        Schema.DescribeSObjectResult objDescribe = objType.getDescribe();        
    
        map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();        
      
        list < Schema.PicklistEntry > values =
            fieldMap.get(fld).getDescribe().getPickListValues();        
     
        for (Schema.PicklistEntry a: values) {
            allOpts.add(a.getValue());
        }
        system.debug('allOpts ---->' + allOpts);
        allOpts.sort();
        return allOpts;
    } 
Hi, I am trying to return the picklist values from 3 picklists from a custom object. So far i can return the values from 1 picklist which i use to populate a lightning:select field in my component, but can i get the other 2 picklists in the same call, or do i have to get them seperatly?
Hi I have the following trigger that sits on leads, what it does is clones a files and attaches it to the lead. I need to write a test class, but I can only cover 45%, the part that isnt covered is the ContentVersion insert. Any help would be appreciated. 

trigger copyFiles on Lead (after insert) {       
    
    Lead lead = [Select AttachmentId__c From Lead where Id IN : Trigger.new];
    
    if(lead.AttachmentId__c == Null){ 
        //Do Nothing         
    } else { 
        
        Lead l = [Select Id, Patient_Referral_Id__c, AttachmentId__c From Lead where Id IN : Trigger.new];          
        
        ContentVersion  cont = [SELECT Checksum,ContentDocumentId,ContentLocation,ContentSize,ContentUrl,
                                Description,FileExtension,FileType,FirstPublishLocationId,Id,IsAssetEnabled,
                                IsDeleted,Origin,OwnerId,PathOnClient,PublishStatus,RatingCount,ReasonForChange,
                                SharingOption,Title,VersionData,VersionNumber 
                                FROM ContentVersion Where ContentDocumentId =: l.AttachmentId__c];          
        
            ContentVersion newcont = new ContentVersion();
            newcont.Title  = cont.Title;
            newcont.PathOnClient  = cont.PathOnClient;
            newcont.VersionData = cont.VersionData;
            newcont.FirstPublishLocationId  = l.Id;            
            insert newcont;      
    } 
}
I need help writing a test that contains Schema.PicklistEntry I have looked everywhere and cant figure this out, i am new to Apex so any help would be greatly appreciated. below is the method, which returns all picklists and values on the specifed object.

   
    public static List <String> getselectOptions(sObject objObject, string fld) {
        system.debug('objObject --->' + objObject);
        system.debug('fld --->' + fld);
        List < String > allOpts = new list < String > ();

        Schema.sObjectType objType = objObject.getSObjectType();        
   
        Schema.DescribeSObjectResult objDescribe = objType.getDescribe();        
    
        map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();        
      
        list < Schema.PicklistEntry > values =
            fieldMap.get(fld).getDescribe().getPickListValues();        
     
        for (Schema.PicklistEntry a: values) {
            allOpts.add(a.getValue());
        }
        system.debug('allOpts ---->' + allOpts);
        allOpts.sort();
        return allOpts;
    } 
Hi, I am trying to return the picklist values from 3 picklists from a custom object. So far i can return the values from 1 picklist which i use to populate a lightning:select field in my component, but can i get the other 2 picklists in the same call, or do i have to get them seperatly?