+ Start a Discussion
Pawan RaiPawan Rai 

How to write Test class for this Controller

 

public class Activity 
{

public Activity(ApexPages.StandardController controller) 
{
    }
List<Task> tsk = new List<Task>();
public List<Task> getactivit()
    { 
     tsk = [select Subject, Assign_To__c,Status, ActivityDate, Description, Action_Item__c from Task where WhatId =:ApexPages.CurrentPage().getParameters().get('id')];
         return tsk;
     }
skodisanaskodisana

Hi,

 

Please use the below code in side your test class.

 

Task t = new Task(assignedTo='',DueDate=12/1/2010);
insert t;
ApexPages.StandardController c = new ApexPages.StandardController(t);
             Activity act = new Activity(c);
test pawantest pawan

Thanks a lot, it  given good startup for me. :smileyvery-happy:

milansanghani19milansanghani19

public class ExtFmController {

   
    public List<Interface__c> interfaceList{get; set;}
    public List<Interface__c> interfaceDispList{get; set;}
    public String rowNo{get; set;}
    public Boolean showhide{get;set;}
    public Boolean showCoDoc{get;set;}
    public Boolean showLink{get; set;}
    public List<InterfaceRecList> intfcRecList{get; set;}
    public String linkManType{get;set;}
    public String url{get; set;}
    public String intrFcId{get; set;}
    public ExtFmController(){
       interfaceList = [SELECT Id,  IsDeleted, Name, Link__c, Description__c, Link_Location__c, DocDelStatus__c, ConDelStatus__c, LinkedTold__c, Path__c, IsLinkDeleted__c, DocId__c, ContentId__c From Interface__c where (DocId__c ='' OR ContentId__c ='') and DocDelStatus__c = false and ConDelStatus__c = false];
       // DocmentList();
       // interfaceList();
        showhide=true;
        intfcRecList = new List<InterfaceRecList>();
        showLink=false;
        
        User u=[SELECT Id, Username, UserPermissionsSFContentUser from User where Id=:UserInfo.getUserId() limit 1];
        if(u.UserPermissionsSFContentUser)
            showCoDoc=false;
        else
            showCoDoc = true;
        System.debug(' User is a salesforce content user'+u.UserPermissionsSFContentUser);
       
    }
   
 
    public List<SelectOption> getRadioButtonOption(){
        List<SelectOption> opt = new List<SelectOption>();
        opt.add(new SelectOption('UnLinked', 'UnLinked'));
        opt.add(new SelectOption('Document', 'Document'));
        opt.add(new SelectOption('Content', 'Content'));
        return opt;
    }
    
    
    public void syncDoctoInterface(){
        List<Document> docmentList =[SELECT Id, FolderId, Name,  ContentType, Type, BodyLength, url,LastModifiedDate, Description, AuthorId, Author.Name  from Document];
        List<Interface__c> interfaceList =[SELECT Id, IsDeleted, Name,Link__c, Description__c, Link_Location__c, LinkedTold__c, Path__c, IsLinkDeleted__c, DocId__c, ContentId__c from interface__c];
        System.debug('interface list '+interfaceList );
        for(Document d: docmentList){
            //System.debug('document Name '+ d.Name);
            for(Interface__c i: interfaceList){
               //System.debug('Interface name '+i.Name);
               if(d.url == i.Link__c && i.DocId__c == null){
                   System.debug('valid  doc Id ------'+d.Id);
                   i.DocId__c = d.id;
                   System.debug('interface document id '+i.DocId__c);
                   update i;
               }
               
            }
        }
    }
    
    
    
    public PageReference linkToContent(){
        PageReference pr=new PageReference('/sfc/#workspaces');
        pr.setRedirect(true);
        return  pr;
    }
    
    
    
    //Edit replace and delete operation
    public void checkId(){
        System.debug('SelectedRecordId---------'+intfcRecList[Integer.valueOf(rowNo)-1].intf.id);
        intrFcId=intfcRecList[Integer.valueOf(rowNo)-1].intf.id;
        String docLinkBtn='';
        //System.debug('docLinkBtn -----------'+docLinkBtn);
        if(intrFcId != null){
            showLink = false;
            
            Interface__c i=[SELECT Id, Link__c from interface__c where Id=:intrFcId];
            url = i.Link__c;
            System.debug('url-----------'+url);
            System.debug('interface List : '+intfcRecList);
            
        }
        
    }
    public void deleteDocInterface(){
        System.debug('inside the delete interface -----'+intrFcId);
        if(intrFcId != null){
            for(Interface__c i : interfaceList){
                if(i.id == intrFcId){
                    i.DocDelStatus__c = true;
                    update i;
                    for(InterfaceRecList ircList: intfcRecList){
                        if(ircList.intf.id==intrFcId){
                            System.debug( 'ircList intf id ----------'+ircList.intf.id);
                        }
                    }
                    
                }
            
            }
        }
        
       
    }
    
    public PageReference linkToDocument(){
        PageReference pr=new PageReference('/p/doc/DocumentUploadUi?retURL=%2F015%2FoZ&docURL='+url);
        pr.setRedirect(true);
        return  pr;
    }
    
    public PageReference documentEdit(){
        System.debug('inside the delete interface -----'+intrFcId);
        if(intrFcId != null){
            Interface__c i=[SELECT Id, Link__c, DocId__c, ContentId__c from interface__c where Id=:intrFcId limit 1];
            System.debug('document Id '+i.DocId__c);
            String editUrl='';
            if(linkManType == 'Document'){
                editUrl ='/'+i.DocId__c+'/e?retURL='+i.DocId__c;
                System.debug('edit url --------'+editUrl);
            }else if(linkManType == 'Content')
                editUrl = '/'+i.ContentId__c;
                System.debug('edit url ----content----'+editUrl);
            PageReference pr=new PageReference(editUrl);
            System.debug('value of pr ------------'+pr);
            pr.setRedirect(true);
            return  pr;
        }
        return null;
    }
    
    public void interfaceList(){
        System.debug('value of radio button' +linkManType);  
        
        interfaceDispList = new List<Interface__c>();
        intfcRecList = new List<InterfaceRecList>();
            for(Interface__c i : interfaceList){
                if(linkManType == 'UnLinked'){
                    if(i.DocId__c == null && i.ContentId__c == null){
                        //interfaceDispList.add(i);
                        
                        intfcRecList.add(new InterfaceRecList(i, i.Id));
                        showhide = false;
                        showLink = false;
                        showCoDoc = false;
                    }
                
                }else if(linkManType == 'Document'){
                    System.debug('inside document ---------');
                    if(i.LinkedTold__c == 'Document' && i.DocId__c != null){
                        //interfaceDispList.add(i);
                        intfcRecList.add(new InterfaceRecList(i , i.id));
                        showhide = true;
                        showLink = true;
                        showCoDoc = false;
                    }
                }else if(linkManType == 'Content' ){
                    if(i.ContentId__c != null){
                       // interfaceDispList.add(i);
                        intfcRecList.add(new InterfaceRecList(i, i.id));
                        showhide = true;
                        showLink = false;
                        showCoDoc = true;
                    }
                    System.debug('inside content ---------');
                    
                }
            }
            
    }
    
    class InterfaceRecList{
        public Boolean intfcId{get; set;}
        public String infId{get; set;}
        public Interface__c intf{get;set;}
        public InterfaceRecList(Interface__c inf, String id){
            intf=inf;
            infId= id;
        }
        
    }
    
    public PageReference doReplace(){
        PageReference pr=new PageReference('/apex/ExtFMHtmlPage');
        pr.setRedirect(true);
        return pr;
    }
    
}