• sneha gowder
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
please help me to do the code coverage for below 2 methods.
1.compareTo( Object obj)
2.getAttachmentSize()
 

public class AttachmentListController {
       public List<AttachmentDetails> allAttachments {get;set;}
        public Map<string , List<AttachmentDetails> > allAttachmentsMap {get; set;}
        
         public void allAttachmentsMapEntry(){
        
        allAttachmentsMap =  new Map<string , List<AttachmentDetails> >();
        List<AttachmentDetails> tempAttachmentList;
       // allAttachments.sort();
        for(AttachmentDetails detail: allAttachments){
            
            if(allAttachmentsMap.containsKey(detail.docName)){
                tempAttachmentList = allAttachmentsMap.get(detail.docName);
               
            }
            else{
                tempAttachmentList = new List<AttachmentDetails> ();
            }
            tempAttachmentList.add(detail);
            
            allAttachmentsMap.put(detail.docName ,tempAttachmentList );
            
            
        }
        
        system.debug('allAttachmentsMapEntry execution ended: '+allAttachmentsMap);
         for(AttachmentDetails detail: allAttachments){
              detail.countOfGrouping = allAttachmentsMap.get(detail.docName).size() ;
              if(detail.countOfGrouping > 1){
              detail.isRendered =false;
               tempAttachmentList = allAttachmentsMap.get(detail.docName);
               system.debug('Before Sort'+tempAttachmentList);
               tempAttachmentList.sort();
               system.debug('After Sort'+tempAttachmentList);
              allAttachmentsMap.put(detail.docName , tempAttachmentList);
                hasSec = true;
              }
             
         }
         results = json.serialize(allAttachmentsMap);
         
    }
  public class AttachmentDetails implements Comparable{
      
       public Id id{get;private set;}
        public String parentType {get; private set;}
        public String parent {get;private set;}
        public String parentId {get; private set;}
        public String styleClass {get;private set;}
        public String docName{get
        {
        return docName.abbreviate(integer.valueOf(Label.ESC_FilenameSize));

        }private set;}
         public String docTitleFull{get;private set;}
        public String type{get;private set;}
        public String Downloadlink{get;private set;}
        public String attachmentSizeF{get;private set;}
         public String uploadedDateF{get;private set;}
        public Integer countOfGrouping{get; set;} 
        public Boolean isRendered {get; set;}
        public String getUploadedDate(){
            return formatDate(createdDate);
        }
       
        public Long sortByDate{get; private set;}
        
        private Integer length{get;private set;}
        public DateTime createdDate{get; set;}

        public AttachmentDetails(Attachment attach){
            initialize(attach);
        }
        public AttachmentDetails(Attachment attach, Boolean isEmailinbound){
            initialize(attach);
            this.styleClass  = isEmailinbound? 'inb' : 'otb' ;
             
        }
      
      public void initialize(Attachment attach){
            this.Id = attach.Id;
            this.parent = attach.parent.name;
            this.parentId = attach.parentId;
            this.docName = attach.name;
            this.docTitleFull = attach.name;
            this.createdDate = attach.createdDate;
            this.type = String.isBlank(attach.contentType)?'':((attach.contentType.contains('.'))?attach.contentType.substringAfterLast('.'):((attach.contentType.contains('/'))?attach.contentType.substringAfterLast('/'):attach.contentType));
            this.length = attach.bodyLength;
            this.parentType = attach.parentId.getSobjectType().getDescribe().getLabel();
            this.Downloadlink= '/servlet/servlet.FileDownload?file='+attach.Id;
            this.countOfGrouping =0;
             this.isRendered = true;
             this.attachmentSizeF = getAttachmentSize();
            this.uploadedDateF = getUploadedDate();
            this.sortByDate = Long.valueOf(formatDate());
        }
      
  
  public Integer compareTo( Object obj)
        {
            
            AttachmentDetails sfw = (AttachmentDetails ) obj;
            if(this.sortByDate < sfw.sortByDate)
                return 1;
            else if(this.sortByDate > sfw.sortByDate)
                return -1;
            return 0;
        }
        
        public String getAttachmentSize()
        {
            Decimal size;
            if(!Test.IsRunningTest()){
            size = ((Decimal)this.length).setScale(2);
            
            if(this.length <1024)
                return this.length+' bytes';
            size = (size/1024).setScale(2);
            if(size < 1024)
                return size+' Kb';
            size = (size/1024).setScale(2);
            if(size < 1024)
                return size+' Mb';
            else
                return (size/1024).setScale(2) +' Gb';
            }
            else{
                return '0 Mb';
                }
        }
  }
How to set a value for user.accountid ( User Object) from Account Object ?   Error recieved: User.accountid is not writable in Apex code
I have a class if ,else if condition , and the test class is not getting covered for ELSE IF condition. please help me.


CLASS:

String cNumber=contact.tocContact_ID__c;
                                List<tocSubscriber__c> ListtocSubscriber=[Select Id,Account_Number__c,Billing_Contact_Payer__c,Billing_Contact_Viewer__c from tocSubscriber__c where Billing_Contact_Payer__c=:cNumber OR Billing_Contact_Viewer__c LIKE :('%'+cNumber+'%')];
                                for(tocSubscriber__c billAddress :ListtocSubscriber)
                                {
                                   if(billAddress.Billing_Contact_Payer__c==cNumber)
                                   {
                                     listBillingAddress.add(new BillingAddress(billAddress.Account_Number__c,Label.MyTR_Billing_Contact_Payer_c));
                                   }
                                   else if(billAddress.Billing_Contact_Viewer__c.contains(cNumber))
                                   {
                                     listBillingAddress.add(new BillingAddress(billAddress.Account_Number__c,Label.MyTR_Billing_Contact_Viewer_c));
                                   }
                                }


TEST CLASS:
Contact C1 = TestDataUtility.getContactDetails (at.id);
            C1.tocContact_ID__c='C-TR678798';
            insert c1;  
            
                    
            tocSubscriber__c subsc1 = MyTRGenericTestDataUtility.getToSubcriber(at.Id);
            subsc1.Billing_Contact_Payer__c =C1.tocContact_ID__c;
            subsc1.Billing_Contact_Viewer__c = C1.tocContact_ID__c;
            insert subsc1;
 
Please help me to refresh my custom visualforce page(VIEW FILES) in console


whenever i try to upload the document from FILE feed Item for perticular CASE from console, That document details should get listed in my Custom Visualforce page.

In this case i can see the uploaded document whenever i refresh the entire URL link.
please help me to refresh this automatically without refreshing the URL. User-added imageUser-added image
How to calculate the Odd sum in collection in apex ? can some help me with sample code
Please help me to refresh my custom visualforce page(VIEW FILES) in console


whenever i try to upload the document from FILE feed Item for perticular CASE from console, That document details should get listed in my Custom Visualforce page.

In this case i can see the uploaded document whenever i refresh the entire URL link.
please help me to refresh this automatically without refreshing the URL. User-added imageUser-added image