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
sfdc007sfdc007 

Test class apex help needed

Hi,

I have a apex class for which i have a test class which covers 57% right now , i need help to cover certain methods which i am not able to cover


Kindly help me on this regard


Method need to cover

 public boolean getteamFormStatus() {        
        boolean blStatus = false;
        System.debug('TeamFormparaId:'+paraId);
        gpsquoteobj = [select GPSTeamForm__r.Status__c,GPSTeamForm__r.Engagement_Script__c,GPSTeamForm__r.Engagement_Team__c,Quote_Status__c,Quote_Comments__c,LastModifiedBy.name,LastModifiedDate,Name,PremiSys_Quote_Id__c,GPSTeamForm__c,Quote_Version__c,CreatedDate,GPSTeamForm__r.Name from GPS_PremiSys_Quote__c
                       where id =:paraId order by CreatedDate desc];
        if(gpsquoteobj.GPSTeamForm__r.Status__c == 'Won')
        {
            blStatus = true;
            return blStatus;
        }
        
        return blStatus;        
    }


MY TEST CLASS :
 
@isTest(seeallData = true)
public class GpsPremiSysQuoteRLController_test {
    static testmethod void GpsPremiSysQuoteRLTestMethod(){
        string strUsr;
        User usr = GPSTestUtilities.createStandardUser(strUsr);
        System.runAs(usr){               
            Account acct = GPSTestUtilities.createTestAccount();
            Pricebook2 pb = GPSTestUtilities.getTestPriceBook();            
            product2 pr = GPSTestUtilities.createproduct();
            test.startTest(); 
            Product_Designator__c pd = GPSTestUtilities.createprodDesignator();            
            Opportunity op = GPSTestUtilities.createTestOpportunity(acct.Id);
            OpportunityLineItem opline = GPSTestUtilities.createTestOpportunityLineItem(op.Id);
            //list<OpportunityLineItem>lstopplt = [select ];
            GPS_PRx__c prx = GPSTestUtilities.createGPSPRX(pd.Id);
            test.stopTest();
            system.debug('OpptyID=>'+op.Id);            
                       
            Engagement_Script__c EP = GPSTestUtilities.createEngagementScript(acct.Id,op.Id);
            system.debug('EP=>'+EP);            
            Team_Form__c TF = GPSTestUtilities.createTeamForm(EP.Id);            
            GPS_TF_Product_Line_Item__c prlitem = GPSTestUtilities.createGPSLineitms(prx.Id, EP.Id, TF.Id);
            GPS_PremiSys_Quote__c Quote = GPSTestUtilities.createPremisysQuote(EP.Id, TF.Id);
           //set up GPS Premisys Quote 
            GPS_PremiSys_Quote__c sdquote = new GPS_PremiSys_Quote__c();
            sdquote.Quote_Status__c='New';
            sdquote.GPSTeamForm__c =TF.Id;
            sdquote.Engagement_Script_Id__c=EP.Id;
            sdquote.Quote_Comments__c='Test';
            insert sdquote;
            
            
            ApexPages.currentPage().getParameters().put('id', TF.Id);
           // Apexpages.StandardController  sc = new Apexpages.StandardController (TF);
            GpsPremiSysQuoteRLController objquoteRLcon = new GpsPremiSysQuoteRLController();
            //
            objquoteRLcon.getGpsPremiSysQuoteList();
            objquoteRLcon.Custsave();
        }
    }
    static testmethod void GpsPremiSysQuoteRLTestMethodNoES(){
        string strUsr;
        User usr = GPSTestUtilities.createStandardUser(strUsr);
        System.runAs(usr){            
            Account acct = GPSTestUtilities.createTestAccount();
            Pricebook2 pb = GPSTestUtilities.getTestPriceBook();            
            product2 pr = GPSTestUtilities.createproduct();
            Product_Designator__c pd = GPSTestUtilities.createprodDesignator();            
            Opportunity op = GPSTestUtilities.createTestOpportunity(acct.Id);
            test.startTest(); 
            OpportunityLineItem opline = GPSTestUtilities.createTestOpportunityLineItem(op.Id);
            //list<OpportunityLineItem>lstopplt = [select ];
            GPS_PRx__c prx = GPSTestUtilities.createGPSPRX(pd.Id);
            
            system.debug('OpptyID=>'+op.Id);            
                       
            Engagement_Script__c EP = GPSTestUtilities.createEngagementScript(acct.Id,op.Id);
            system.debug('EP=>'+EP);            
            Team_Form__c TF = GPSTestUtilities.createTeamForm(EP.Id);            
            GPS_TF_Product_Line_Item__c prlitem = GPSTestUtilities.createGPSLineitms(prx.Id, EP.Id, TF.Id);
            //GPS_PremiSys_Quote__c Quote = GPSTestUtilities.createPremisysQuote(EP.Id, TF.Id);
            test.stopTest();
            ApexPages.currentPage().getParameters().put('id', TF.Id);
            //Apexpages.StandardController  sc = new Apexpages.StandardController (TF);
            GpsPremiSysQuoteRLController objquoteRLcon = new GpsPremiSysQuoteRLController();
            //
            objquoteRLcon.getGpsPremiSysQuoteList();
            objquoteRLcon.getteamFormStatus =true;
        }
    }    
}


 When i  write objinstance.methodname() dirctly i am getting list has no rows error

Kindly help me pls

Thanks in Advance
 
Best Answer chosen by sfdc007
Shailendra Singh ParmarShailendra Singh Parmar
I think, this is because you have filter in your orginal code that is where id =:paraId order but we haven't set paraId variable. Please try to add one more statement as "objquoteRLcon.paraId = sdquote.id" before system.debug(objquoteRLcon.getteamFormStatus());

 

All Answers

Shailendra Singh ParmarShailendra Singh Parmar
Hi ,
I think, you will be fine if you change line no. 68 (objquoteRLcon.getteamFormStatus =true;) to system.debug(objquoteRLcon.getteamFormStatus());

suggestion :- remove @isTest(seeallData = true) anotation.

Thanks!
sfdc007sfdc007
I am getting this error

System.QueryException: List has no rows for assignment to SObject


 public boolean getteamFormStatus() {        
        boolean blStatus = false;
        System.debug('TeamFormparaId:'+paraId);
        gpsquoteobj = [select GPSTeamForm__r.Status__c,GPSTeamForm__r.Engagement_Script__c,GPSTeamForm__r.Engagement_Team__c,Quote_Status__c,Quote_Comments__c,LastModifiedBy.name,LastModifiedDate,Name,PremiSys_Quote_Id__c,GPSTeamForm__c,Quote_Version__c,CreatedDate,GPSTeamForm__r.Name from GPS_PremiSys_Quote__c
                       where id =:paraId order by CreatedDate desc];
        if(gpsquoteobj.GPSTeamForm__r.Status__c == 'Won')
        {
            blStatus = true;
            return blStatus;
        }
        
        return blStatus;        
    }
Shailendra Singh ParmarShailendra Singh Parmar
I think, this is because you have filter in your orginal code that is where id =:paraId order but we haven't set paraId variable. Please try to add one more statement as "objquoteRLcon.paraId = sdquote.id" before system.debug(objquoteRLcon.getteamFormStatus());

 
This was selected as the best answer
sfdc007sfdc007
thanks i got that

i need help for the below condition too
 
gpsquoteobj = GpsPremiSysQuoteList[0];
            string strProfileName = [select u.Id,u.Profile.Name from User u where u.id = :UserId].Profile.Name;
            if(Label.GPS_Admin_Users.contains(strProfileName)){
                lstUser.add(UserId);
                system.debug('Label.GPS_Admin_Users.contains(strProfileName)'+Label.GPS_Admin_Users.contains(strProfileName));
            }
            
            ES=gpsquoteobj.GPSTeamForm__r.Engagement_Script__c != null ? gpsquoteobj.GPSTeamForm__r.Engagement_Script__c : null; 
            string strEngagementTeamId = gpsquoteobj.GPSTeamForm__r.Engagement_Team__c;
            system.debug('strEngagementTeamId'+strEngagementTeamId);
            for(Team_Group_Member__c TeamGroupMem: [select User__c,Engagement_Team__c,User_Role__c,Id from Team_Group_Member__c where Engagement_Team__c =: strEngagementTeamId and (User_Role__c =: 'Super User' or User_Role__c =: 'Sales Support' or  User_Role__c =:'PA Manager' or  User_Role__c =:'Scoping Resource') and User__c =:UserId]){
                lstUser.add(TeamGroupMem.User__c);


kindly help me how to cover the above condition also pls
 
Shailendra Singh ParmarShailendra Singh Parmar
I think, you need to create User in test class which satisfy your requirment. Here is reference how to create user in test class
http://salesforce.stackexchange.com/questions/38753/apex-test-user-creation
sfdc007sfdc007
i am creating user in my test class

        User usr = GPSTestUtilities.createStandardUser(strUsr);

 
Shailendra Singh ParmarShailendra Singh Parmar
I think.. should be easy enough then.. make sure that profile name of user that you are creating is same as in custom label. Thanks!
sfdc007sfdc007
thanks dude , i will check it