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
Math110Math110 

Can anyone help me to get code coverage for the following code

public void createorderline()
    {
        if(orderid == '' && orderid == null)
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please save the Order to proceed..'));
        else {
          orderline__c ol =new orderline__c();
          ol.Status__c ='Pending Submission';
    if(ol.Order_Price__r.product__r.name!=null)
          oderlinelist.add(new neworderlist(ol,ol.Order_Price__r.product__r.name,0.0,0.0));
   else {
    system.debug('inside else*************');
string temp='';
     oderlinelist.add(new neworderlist(ol,temp,0.0,0.0));  
 }

          }
    }



Thanks much in advance...
hitesh90hitesh90

Hi,

 

try below test class.

 

@istest
public class Testclassconfirm{
    Private Static testmethod void Testclassconfirm(){
        classconfirm objclassconfirm = new classconfirm();
        objclassconfirm.createorderline();
    }
}

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

Sfd developerSfd developer

Hi,

 

 

Try the following test class 

 

@istest
public class Testclassconfirm{
    Private Static testmethod void Testclassconfirm(){
        classconfirm objclassconfirm = new classconfirm();
	System.Test.currentPageReference(new PageReference('/apex/x'));
		
	// Set orderid is null (believe order id is a global variable)
	objclassconfirm.orderid = null;
        objclassconfirm.createorderline();
		
	// Set order id is not null 
	Id orderId = Database.insert(new order__c(Name='test order')).getId();
	objclassconfirm.orderid = orderId;
	objclassconfirm.createorderline();
	
    }
}