function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Wajeed Khan HbWajeed Khan Hb 

can anyone give testcode coverage for below code

https://ap4lc-dev-ed.my.salesforce.com/_ui/common/apex/debug/ApexCSIPage
Shubham NandwanaShubham Nandwana
Hi Wajeed,
We can not access your link, you need to provide login id/pwd for this OR you can paste your code here.

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts
Wajeed Khan HbWajeed Khan Hb
public with sharing  class Call_Controller {
    public apexpages.StandardController stdctrl{get;set;}
    public Call__c call{get;set;}
   // public List<Account> acc{get;set;}
    public List<Account_Affiliation__c> accAf{get;Set;}
    public List<wrapperClass> wrapClassList{get;set;}
    public wrapperClass wc{get;set;}
    
    public Call_Controller(ApexPages.StandardController ctrl)
    {
        wrapClassList = new List<wrapperClass>();
        accAf = new List<Account_Affiliation__c>();  
        call=[Select Id,Status__c,Created__c,Account__c,Account__r.Name,Call_Date__c,Comments__c,Out_of_Office__c from Call__c where Account__c=:ApexPages.currentPage().getparameters().get('accId')][0];
        accAf=[Select Status__c,To__r.name,From__c,To__c From Account_Affiliation__c where From__c=:ApexPages.currentPage().getparameters().get('accId')];
        
        for(Account_Affiliation__c af:accAf)
        {
            wc = new wrapperClass(af.To__r.Name);
            wc.flag=false;
            wc.accWrap=af;
            wrapClassList.add(wc);            
        }
        stdctrl=ctrl;
    }
    
    public class wrapperClass
    {
        public boolean flag{get;set;}
        public Account_Affiliation__c accWrap{get;set;}
        public String accName{get;set;}
        
        public wrapperClass(String Name)
        {
            accName=Name;
            flag=false;
        }
    }
    
    //Record Creation for Related Records on Save
    public void createRelRecordOnSave()
    {
        for(wrapperClass wc:wrapClassList)
        {
            if(wc.flag==true )
            {
                Call__c Rcl =new Call__c();   
                Rcl.Account__c=wc.accWrap.To__c;
                Rcl.Call_Date__c=call.Call_Date__c;
                Rcl.Comments__c=call.Comments__c;
                Rcl.Out_of_office__c=call.Out_of_office__c;
                Rcl.Status__c='Draft';
                upsert rcl;
            }
        }
    }
    
    //Record Creation for Related Records on Submit
    public void createRelRecordOnSubmit()
    {
        for(wrapperClass wc:wrapClassList)
        {
            if(wc.flag==true )
            {
                Call__c Rcl =new Call__c();   
                Rcl.Account__c=wc.accWrap.To__c;
                Rcl.Call_Date__c=call.Call_Date__c;
                Rcl.Comments__c=call.Comments__c;
                Rcl.Out_of_office__c=call.Out_of_office__c;
                Rcl.Status__c='Submitted';
                upsert rcl;
            }
        }
    }
    //Validation on EditButton 
   /** public PageReference validate()
    {
        
        PageReference pgectrl=new PageReference('/a0B?fcf');
        
        
        if(call.Status__c=='Submitted')
        {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'You Cannot Edit the Submitted Record'));
            return null;
        }
        
        return null;
    }**/
    
    /** public PageReference relRecordOnSave()
{        
for(Account_Affiliation__c Af: accAf)
{   
Call__c Rcl =new Call__c();
Rcl.Account__c= Af.To__c;
Rcl.Call_Date__c=call.Call_Date__c;
Rcl.Comments__c=call.Comments__c;
Rcl.Out_of_office__c=call.Out_of_office__c;
rcl.Status__c='Draft';
upsert rcl;   
}

PageReference reRend = new PageReference('/a0B?fcf');
reRend.setRedirect(true);
return reRend;
}

public PageReference relRecordOnSubmit()
{

for(Account_Affiliation__c Af: accAf)
{
Call__c Rcl =new Call__c();
Rcl.Account__c= Af.To__c;
Rcl.Call_Date__c=call.Call_Date__c;
Rcl.Comments__c=call.Comments__c;
Rcl.Out_of_office__c=call.Out_of_office__c;
rcl.Status__c='Submitted';
upsert rcl;   
}

PageReference reRend = new PageReference('/a0B?fcf');
reRend.setRedirect(true);
return reRend;
}**/
    
    //Save Button 
    public PageReference Save()
    {   
        if(call.Call_Date__c>System.today() )
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You Cannot Enter A future Date'));
            return null;
        }
      /**  else if(call.Status__c=='Submitted')
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You Cannot Edit which is alredy Submitted'));
            return null;
        }**/
        else
        {
            try{
                
                Call__c Call1=New Call__C(); 
                call1.Account__c=call.Account__c;
                call1.Call_Date__c=call.Call_Date__c;
                call1.Comments__c=call.Comments__c;
                call1.Out_of_office__c=call.Out_of_office__c;
                call1.Status__c='Draft';
                upsert call1;
                createRelRecordOnSave();
            }
            
            catch(Exception ex)
            {
                ApexPages.addMessages(ex);
            }
        }
        PageReference reRend = new PageReference('/a0B?fcf');
        reRend.setRedirect(true);
        return reRend;
    }
    
    //Submit Button
    public PageReference Submit()
    {      
        if(call.Call_Date__c>system.today())
        {
            call.Call_Date__c.addError('The Date Should not be Future Date');
        }
        try{
            
            Call__c Call1=New Call__C(); 
            call1.Account__c=call.Account__c;
            call1.Call_Date__c=call.Call_Date__c;
            call1.Comments__c=call.Comments__c;
            call1.Out_of_office__c=call.Out_of_office__c;
            call1.Status__c='Submitted';
            upsert call1;
            createRelRecordOnSubmit();
            
        }
        catch(Exception ex)
        {
            ApexPages.addMessages(ex);
        }
        PageReference reRend = new PageReference('/a0B?fcf');
        reRend.setRedirect(true);
        return reRend;
    }  
}

 
Shubham NandwanaShubham Nandwana
Hi Wajeed,
You can use the below code to start with and add/customize according to you.
@isTest
public class Call_Controller Test {
    Static TestMethod void testSave() {
        Test.startTest();
        Account acc = new Account();
        acc.Name = 'test account';
        insert acc;

        ApexPages.currentPage().getParameters().put('accId', acc.Id);

	Call__c call=new Call__c();
	call.Account__c=acc.Id;
	insert call;

	Account_Affiliation__c accf=new Account_Affiliation__c();
	accf.From__c=acc.Id;
	insert accf;	

        //assuming your visualforce page has account standard controller
        Account con = new Account();
        ApexPages.StandardController ctrl = new ApexPages.StandardController(con);

        Call_Controller callObj = new Call_Controller(ctrl);
        callObj. createRelRecordOnSave();
	callObj. createRelRecordOnSubmit();

        Test.stopTest();
    }
}

For reference use the below links.
http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
https://www.linkedin.com/pulse/test-class-visual-force-controller-maneesh-gupta

Select it as best answer if it helps.

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts