• arun kumar.ax887
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 6
    Replies

Hi,

 

    I have a requirement, where in I need to assign the text that is present in Comments field of Steps in ProcessInstance to Approved Comments field of Opportunity.  So, kindly suggest a solution to the above mentioned problems.  

 

 

Trigger:


trigger ApprTrigger on Opportunity (after insert,before update) {
Opportunity [] o = Trigger.new;
ApprProcess.ProcessInst(o);
}

 

 

 

Apex Class: 

 

 

 

public class ApprProcess

{
public static void ProcessInst(Opportunity [] o1)
{
for(Opportunity  o2:o1)
{
ProcessInstance [] op = [SELECT Id,Status,(SELECT Id, StepStatus, Comments FROM Steps)FROM ProcessInstance limit 1];
for (ProcessInstance op1 : op)
{
if(op1.Status == 'Approved')
{
o2.Approved_Comments__c = op1.ProcessInstanceStep.comments;
}
}
}  
}

 

 


 

The reference site that I have used is http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_process.htm

 

 

When I am saving the above class I am getting the following error.

ErrorError: Compile Error: Invalid foreign key relationship: ProcessInstance.ProcessInstanceStep at line 12 column 27

 

 

So, can anyone suggest a solution for the above mentioned problem.

 

 

Regards

 

Arun


 


 

Hi All,

 

    I have a requirement, where in I need to delete all the Invoice Payment Line Items which has a specific record type.  For which I have written a class.  The class is working properly and we are getting the desired output, but when I am writing the test case the test case is failing and the code coverage is 54%.  

 

 

  Therefore I request you people to kindly suggest a solution such that the test case is successful and code coverage is above 75% as I need to migrate the code.

 

 

I am sending the code of  both Apex class and as well as TestCase.  Kindly look into the code and provide an appropriate solution.

 

Apex Class

 

 

public with sharing class Dev_ControlDeleteon_INV {
 String recordId;
 
    public Dev_ControlDeleteon_INV (ApexPages.StandardController controller) {recordId = controller.getId();}
    
public PageReference redirect() {
Invoice_Payment_Line_Item__c jkl;
 RecordType[] rt = [select Id,Name from RecordType];
Invoice_Payment_Line_Item__c dr=[select id,name,recordtypeId,Invoice_Number__c from Invoice_Payment_Line_Item__c where id =:recordId];
for(RecordType yt :rt){
if(dr.recordtypeId !='01290000000Kex7'){
delete dr;
  
  
  return new PageReference('/'+dr.Invoice_Number__c +'/d?retURL=%2F'+dr.Invoice_Number__c);
}
}
return null;
}
}
TestCase
@istest
private class Dev_ControlDeleteon_INVTestCase {
     static testMethod void testMyController() 
     {
   
      ApexPages.StandardController con = new ApexPages.StandardController(new Invoice_Payment_Line_Item__c());
      
      Dev_ControlDeleteon_INV  dc = new Dev_ControlDeleteon_INV(con);
      
      PageReference pr1 = dc.redirect();
      
      
       }
}

 
Regards

Arun

 

Hi All,

 

    I have a requirement wherein, I need to create the packages in the Invoice, when the record type of the Items is 'package' in the Invoice_Line_Item, then the required number of packages are to be created.

 

   I am getting the desired output, but when I have written the TestCase, the code coverage is 42%.   But, in order to migrate the code on to Live, we need a minimum code coverage of 75%.  

 

  So, could anyone suggest a solution for the above mentioned problem.  I am posting both the Class and TestCase, do suggest a solution.

 

Apex Class

 

 

public class MyClass
{
    
      public static void createPackage(Invoice__c [] inv)
      {
       
         
       for(Invoice__c i : inv)
       {
           Invoice_Line_Item__c[] a1;
           a1 = [select id,name,Item__r.RecordTypeId  from Invoice_Line_Item__c  where invoice_number__c =:i.id and Item__r.RecordTypeId='01290000000K8Ba'];
           Integer j=a1.size();
           for(Invoice_Line_Item__c a2 : a1)
           {
            
            if((i.Create_Package__c==true)||(i.Status__c=='FULLY PAID'))
            {
                 for(Integer k=1;k<=j;k++)
                 {
                 if(i.Package_Status__c!='Package Created')
                  {
                   
                  Package__c p1 = new Package__c();
                  p1.RecordTypeId='01290000000Xn01';
                  p1.invoice__c = i.id;
                  p1.Invoice_Line_Item__c = a2.id;
                  p1.patient__c= i.Patient__c;
                 
                   insert p1;
                 }
                 }
                 
                  i.Package_Status__c='Package Created';
             }
             
            }  
               
             
        }        
                
      }
    }
   
Test Case
@isTest
private class MyClassTestCase {
static testMethod void createPackage() {
item__c v =[select id,name from item__c limit 1];
// invoice__c i = [select id,name, Patient__c from invoice__c limit 1];
               
invoice__c i = [select id,name,Create_Package__c, Status__c, Patient__c, 
                Package_Status__c from invoice__c limit 1];
Invoice_Line_Item__c il = new Invoice_Line_Item__c ();
il.invoice_number__c = i.id;
il.item__c = v.id;
insert il;
if((i.Create_Package__c==true)||(i.Status__c=='FULLY PAID'))
{
         
   if(i.Package_Status__c!='Package Created')
   {
    Package__c p1 = new Package__c();
    p1.RecordTypeId='01290000000Xn01';
    p1.invoice__c = i.id;
    p1.Invoice_Line_Item__c = il.id;
    p1.patient__c= i.Patient__c;
               
    insert p1;
    
    }
    
   i.Package_Status__c='Package Created';
  }
}
}
           
Do suggest a solution and guide me in the right path.
Thanks and Regards
Arun
           
           
           
           
       
       
      

 

Hi All,

 

     I have a requirement where in I have to get the report in matrix format for which I have written a controller and a Visual force page.  I am able to retrieve all the values, but there is alignment problem and column names are appearing repeatedly.  All the values are printed under a single column.  I tried using Group by function,  but it is not working.  I have tried to use Distrinct function, but it is not supported in SOQL. So could any one suggest a solution for this problem.

 

The code for the Controller and Visual force page are written below:

 

 

Controller Class:

 

 

public class Appointment
{
public PageReference save()
{
return null;
}
public Appointment(ApexPages.StandardController controller)
{
}
public  Appointment__c[] App;
public Appointment()
{
 
App=[select id,Name,Appt_Time__c,Appt_Date__c,Branch__r.Name,Doctor__r.Name ,Account__r.Name,Account__r.Phone,
Check_In__c,Check_Out__c,Cancelled__c,New_Request__c,Chiropractic__c,Shockwave__c,DTS__c,
Knee_Brace_Fitting__c,Spine_Cor_Bracing__c,Spine_Cor_Review__c,Physiotherapy__c,
Orthopedic_Consultation__c,Others__c From Appointment__c];
}
public String getname()
{
return 'Appointment';
}
public Appointment__c[] getApp()
{
return App;
}
}

 

 

 

Visual Force Page:

 

 

 

<apex:page controller="Appointment">

<html>

<head>

 

</head>

 

<body>

<table cellpadding="0" cellspacing="0" width="100%" border="1 #000000 solid">

    <th/>

    <apex:repeat value="{!app}" var="a">

 

    <th align="left" valign="top" style="border:1px #000000 solid;height:20px; width : 180px;">

    <font style="font-size: 13px;" color="#000000 " face="Calibri"><b><center><h3> {!a.Doctor__r.Name} </h3></center></b></font><br/></th>

 

 

    </apex:repeat>

 

<apex:repeat value="{!app}" var="a" rendered="true">

<tr>

 

    <td style="border: 1px #000000 solid ;">{!a.Appt_Time__c}</td>

    <td style="border: 1px #000000 solid ;">

    {!a.Account__r.Name}

    <br/>

 

{!IF (a.New_Request__c == true, "New Request",

     (IF(a.Chiropractic__c==true, "Chiropractic",

     (IF(a.Shockwave__c==true, "Shockwave",

     (IF(a.DTS__c==true, "DTS",

     (IF(a.Knee_Brace_Fitting__c==true, "Knee Brace Fitting",

     (IF(a.Spine_Cor_Bracing__c==true, "Spine Cor Bracing",

     (IF(a.Spine_Cor_Review__c==true, "Spine Cor Review",

     (IF(a.Physiotherapy__c==true, "Physiotherapy",

     (IF(a.Orthopedic_Consultation__c==true, "Orthopedic Consultation",

     (IF(a.Others__c==true, "Others",null 

)))))))))))))))))))}

<br/>

{!a.Account__r.Phone}

      <br/>

     {!IF( a.Check_In__c == true, "Check In",

     (IF(a.Check_Out__c==true, "Check Out",

     (IF(a.Cancelled__c==true, "Cancelled",null )))))}

 

    </td>

  </tr> 

   </apex:repeat>

 

</table>

</body>

</html>

</apex:page>

 

 

 

Thanks and Regards

 

Arun


 

Hi All,

 

     We have written a Custom controller in order to implement Multiple Invoice Line Items.  The code is working properly, but  when I am trying to write a test case for  the above mentioned controller,  I am getting errors.  Could any one please correct the errors.  I am posting both Apex class and Test Case.  So kindly go through the code and provide a better solution.

 

 

Apex Class:

 

 

 

public class DEV_MULTIPLE_InvoiceLineEntry {
    public List<Invoice_Line_Item__c> ords {get; set;}
    private final Invoice__c parOrd;
    public DEV_MULTIPLE_InvoiceLineEntry(ApexPages.StandardController myController) {
        parOrd=(Invoice__c)myController.getrecord();
        
        ords = new List<Invoice_Line_Item__c>();
         // Get the Current User
     user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];
     invoice__c pa =[select id,name, doctor__c from Invoice__c where id=:parOrd.id];
     
     // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL 
        if(u1.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.staff__c = pa.Doctor__c;
        LitOrd.quantity__c=1;
       
        ords.add(LitOrd);
         
        } 
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups) 
        else if(u1.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
         LitOrd.staff__c = pa.Doctor__c;
        LitOrd.Item_Warehouse__c =w1[0].id;
        ords.add(LitOrd);
        }
        }
        
       
    public void addrow() {
    
        // Get the Current User
     user u =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w =[select id,name from Warehouse__c where name =: u.Formula_Warehouse__c];
     
     invoice__c pa =[select id,name, doctor__c from Invoice__c where id=:parOrd.id];
         // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL 
     if(u.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        
        LitOrd.staff__c = pa.Doctor__c;
        LitOrd.Quantity__c=1;
       
        ords.add(LitOrd);
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups) 
                
        else if(u.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
         LitOrd.staff__c = pa.Doctor__c;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w[0].id;
        ords.add(LitOrd);
        
        }   
           
        }  
           
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
    public PageReference save() {
        insert ords;
       // PageReference home = new PageReference('/home/home.jsp');
        return(new ApexPages.StandardController(parOrd)).view();
       // home.setRedirect(true);
       // return home;
         }
        
        }

 

 

 

TestCase:

 

 

 

@isTest

private class MyTestClass1

{

 

 static testmethod void TestController()

 {

 

      ApexPages.StandardController con = new ApexPages.StandardController(new Invoice__c());

 

      Invoice__c parOrd = (Invoice__c)con.getRecord();

 

      DEV_MULTIPLE_InvoiceLineEntry dc = new DEV_MULTIPLE_InvoiceLineEntry(con);

 

      List<Invoice_Line_Item__c> ords = new List<Invoice_Line_Item__c>();

 

      user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];

 

      Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];

 

      invoice__c pa =[select id,name, doctor__c from Invoice__c where id=:parOrd.id];

 

      if(u1.Formula_Warehouse__c ==null)

      {

        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();

        LitOrd.Invoice_Number__c = parOrd.id;

        LitOrd.staff__c = pa.Doctor__c;

        LitOrd.quantity__c=1;

        ords.add(LitOrd);

 

        }

 

       else if(u1.Formula_Warehouse__c !=null)

       {

 

        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();

        LitOrd.Invoice_Number__c = parOrd.id;

        LitOrd.quantity__c=1;

        LitOrd.staff__c = pa.Doctor__c;

        LitOrd.Item_Warehouse__c =w1[0].id;

        ords.add(LitOrd);

        } 

 

 

        dc.addrow();

        dc.removerow();

        dc.save();

 

}     

 

 }

 

 

 

I am getting the following Error Messages,  so could any one please correct them, so that the test case is successful.

 

Error Messages:

 




System.QueryException: List has no rows for assignment to SObjectClass.DEV_MULTIPLE_InvoiceLineEntry.<init>: line 13, column 21 Class.MyTestClass1.TestController: line 12, column 42 External entry point

 

 

 

 

Thanks and Regards

 

 

Arun

 

I have a requirement, where in I need to write a controller for generating PDFs using Visualforce page.   I have written the controller and the Visualforce page for generating pdf,  both are working properly, but I am unable to write the test class for the controller, could any one suggest how to write a test class.    

 

 

Apex Custom Controller 

 

public class Dev_DR_Controller
{
     public Dev_DR_Controller(ApexPages.StandardSetController controller)
   {
   
     }

 

 
    Private DR__c dr;
    Private DR_Payment_Line_Item__c[] dpli;
    

//public final DR__c dr;


public Dev_DR_Controller()
{

 dr = [select Id, name, Patient__c, Patient__r.Name ,
 Branch__r.Name , Workflow_Branch_Address_1__c,
 Workflow_Branch_Address_2__c, Workflow_Branch_City__c,
 Workflow_Branch_Fax__c, Workflow_Branch_Name__c,
 Workflow_Branch_Phone__c, Workflow_Branch_Postcode__c,
 Dev_DR_Day__c,Dev_DR_Month__c,Dev_DR_Year__c,
 Workflow_Branch_State__c,Amount_Paid__c,Rep__c,
 Amount__c,Item_Code__c,Item__c,
 balance_Due__c,Item__r.Item_Code__c,Item__r.Name,  
 Bill_to__c, Date__c,
 Patient_Identification__c,Patient__r.Workflow_Patient_Identification__c
 from DR__c where id = :ApexPages.currentPage().getParameters().get('id')];

 

 DPLI = [select Id,name, Amount__c,  Dev_DR_PLI_Record_Type__c,Dev_DR_PLI_Day__c,Dev_DR_PLI_Month__c,Dev_DR_PLI_Year__c,  
             Bank_Terminal__c,Credit_Card__c, Date__c, Deposit_Receipt_Number__c, Payment_Description__c,
             Payment_Reference__c, Remarks__c from DR_Payment_Line_Item__c where Deposit_Receipt_Number__c =:dr.id];

 

}


public void setDR(DR__c dr)
{
  this.dr=dr;
}

public void setDPLI(DR_Payment_Line_Item__c[] dpli)
{
    this.dpli=dpli;
}

public DR__c getDR()
{
    return this.dr;
}

public DR_Payment_Line_Item__c[] getDPLI()
{
    return this.DPLI;
}

}

 

 

 

Kindly suggest a better solution for writing TestCase to a Custom Controller.

 

 

 

Best Regards

 

Arun

 

 

 

Hi,

 

    I have a requirement, where in I need to generate a PDF in A5 size using the Visual Force Page,  could any  one suggest how to set the page size to A5 in Visual Force.

 

 

 

Regards

 

Arun

Hi,

 

I have written an Apex class and a Trigger associated with it, to get the user defined Auto Number in string format.  I have got the desired output, but when I am writing the Test Cases, I am getting the Code Coverage as 0%.  In order to place the application to the production mode we are suppose to get a minimum of  75 % code coverage.  I am posting the Trigger,  Apex class and the Test Case.   So could any one please suggest a solution for the this problem so that code coverage percentage is greater than 75 %.

 

 

Trigger


 

trigger DRTrigger on DR__c (before insert) 
{
    DR__c [] dr =  Trigger.new;
    DRNumber.getDRNum(dr);
}

 


 

 

 

Apex Class

 

 

public class DRNumber
{
    public static String ToString(Decimal Value)
     {
         
            return Value.format();
     } 

     
    public static void getDRNum(DR__c [] dr)
    {
       Integer m;
       
       
       for(DR__c i : dr)
       {
                        
                Branch__c b =[select id, Name, Branch_Code__c, DRAutoNumber__c  from Branch__c              
                                                                                                                             where id =:i.Branch__c];          
                   
                m=b.DRAutoNumber__c.intValue();                            
                m=m+1;
                i.num1__c=m;
                b.DRAutoNumber__c=m;
                String s1 = ToString(i.num1__c);
    
                                         
                                                       
               i.DRNumber__c = 'DR'+'/'+b.Branch_Code__c+'-'+s1;
               i.Name =  i.DRNumber__c;
               update b; 
               }
        }
}

 

 

Test Case


@isTest
private class DRNumberTestCase
{
    public static String ToString(Decimal Value)
     {
         
            return Value.format();
     } 

     
    static testMethod void getDRNum()
    {
       Integer m;
       
      List<DR__c> dr = new List<DR__c>();
       for(DR__c i : dr)
       {
                        
                Test.startTest();          
                Branch__c b = [select id, Name, Branch_Code__c, DRAutoNumber__c  from Branch__c              
                                                                   where id =:i.Branch__c];                            
                m=b.DRAutoNumber__c.intValue();                            
                m=m+1;
                System.assertEquals(i.num1__c, m);
                System.assertEquals(b.DRAutoNumber__c, m);
                String s1 = ToString(i.num1__c);
     
                                                   
                i.DRNumber__c = 'DR'+'/'+b.Branch_Code__c+'-'+s1;
                System.assertEquals(i.Name, i.DRNumber__c);
                update b; 
              Test.stopTest();
                  
               }
        }
}



 


 


 

Hi,

 

    I have a requirement where in I need to make the Standard Field of Opportunity i.e., Opportunity Name as uneditable.

Can any one suggest a solution for this requirement using an Apex class or functionally.

 

 

 

 

Regards

 

Arun Kumar 

Hi,

 

     I have a requirement where in the default values have to be set for the Standard Field of Opportunity i.e. Opportunity Name, could any one suggest a solution for this. 

 

 

Thanks & Regards

 

Arun

 

Hi,

 

     I have requirement, where in I have 2 record types, Hardware Record Type and Software Record Type under Opporutnities,  I just want to generate two separate autonumbers for Hardware recordtype and Software recordtype.  I tried  to get this using functionality, but I am not getting the desired output.

 

 

Output

 

HW-0001

HW-0002

HW-0003

SW-0004

SW-0005

SW-0006

 

 

Desired Output

 

HW-0001

HW-0002

HW-0003

SW-0001

SW-0002

SW-0003

 

 

      For the above requirement, I want to generate autonumber in an Apex Class,  could any one please send the solution for the above mentioned requirement.

 

 

 

Regards

 

Arun

 

 

 

 

I have a requirement where in  I need to fetch the records from Opportunity standard object based on the closedate field (MM/DD/YYYY) criteria.  For that I have written a visualforce page which takes the close date in the search field which is accepted as a string.  But in the Apex class when I am executing the sql query, i am getting type mismatch error, date cannot be compated to string.   I tried many options to convert string to date, but its not working.   I am  postng  the code snippet.

 

 

Apex Class

 

 

public class OpportunitySearchController1 {

    public OpportunitySearchController1() {

    }

    
    private ApexPages.StandardController controller {get; set;}
  
      public List<opportunity> searchResults {get;set;}
    
          public string searchText {
        get {
            if (searchText == null) searchText = 'Test'; // prefill the serach box for ease of use
            return searchText;
        }
        set;
    }
  
    
 
    public OpportunitySearchController1(ApexPages.StandardController controller) {
 
               this.controller = controller;
       
    }
 
   
    public PageReference search() {
        if (searchResults == null) {
            searchResults = new List<opportunity>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
        }
        // Note: you could have achieved the same results as above by just using:
        // searchResults = new List<categoryWrapper>();
        String date_search= searchText;
 
        // use some dynamic soql to find the related opportunities by name
       
           String qry = 'Select o.Id, o.Name, o.StageName, o.CloseDate, o.Amount from Opportunity o  where  o.closedate LIKE \''+searchText+'%\' Order By o.Name';
      
        searchResults = Database.query(qry);
        return null;
    }
 }

 

 

VisualForce Page

-------------------------

<apex:page standardController="Opportunity" extensions="OpportunitySearchController1" sidebar="true" showHeader="true" >
<style type="text/css">
body {background: #F3F3EC; padding-top: 15px}
</style>
<!-- <b><apex:outputLink value="https://c.ap1.visual.force.com/apex/jeff"> Opportunities </apex:outputLink></b>&nbsp;&nbsp;
<b><apex:outputLink value="https://c.ap1.visual.force.com/apex/subhash"> Contacts </apex:outputLink></b>
-->
<apex:form >
<br/><br/><br/>
<b><apex:outputLink value="https://c.ap1.visual.force.com/apex/GeneralReport"> Opportunities </apex:outputLink></b>&nbsp;&nbsp;
<br/><br/> <b><apex:outputLink value="https://c.ap1.visual.force.com/apex/DisplayReport"> Tasks </apex:outputLink></b>
<br/><br/>
<apex:pageBlock title="Search for Opportunities by Keyword" id="block" mode="edit">
<apex:pageMessages />

<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Close Date</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="GO" action="{!search}" rerender="resultsBlock" status="status"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:actionStatus id="status" startText="Searching... please wait..."/>
<apex:pageBlockSection id="resultsBlock" columns="1">
<apex:pageBlockTable value="{!searchResults}" var="o" rendered="{!NOT(ISNULL(searchResults))}">
<apex:column headerValue="Name">
<apex:outputLink value="/{!o.Id}">{!o.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!o.StageName}"/>
<apex:column value="{!o.Amount}"/>
<apex:column value="{!o.CloseDate}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

If you have any  solution for the above mentioned code kindly post your suggestion. 

 

 

 

 

Regards

 

Arun

 

Hi All,

 

     We have written a Custom controller in order to implement Multiple Invoice Line Items.  The code is working properly, but  when I am trying to write a test case for  the above mentioned controller,  I am getting errors.  Could any one please correct the errors.  I am posting both Apex class and Test Case.  So kindly go through the code and provide a better solution.

 

 

Apex Class:

 

 

 

public class DEV_MULTIPLE_InvoiceLineEntry {
    public List<Invoice_Line_Item__c> ords {get; set;}
    private final Invoice__c parOrd;
    public DEV_MULTIPLE_InvoiceLineEntry(ApexPages.StandardController myController) {
        parOrd=(Invoice__c)myController.getrecord();
        
        ords = new List<Invoice_Line_Item__c>();
         // Get the Current User
     user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];
     invoice__c pa =[select id,name, doctor__c from Invoice__c where id=:parOrd.id];
     
     // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL 
        if(u1.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.staff__c = pa.Doctor__c;
        LitOrd.quantity__c=1;
       
        ords.add(LitOrd);
         
        } 
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups) 
        else if(u1.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
         LitOrd.staff__c = pa.Doctor__c;
        LitOrd.Item_Warehouse__c =w1[0].id;
        ords.add(LitOrd);
        }
        }
        
       
    public void addrow() {
    
        // Get the Current User
     user u =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w =[select id,name from Warehouse__c where name =: u.Formula_Warehouse__c];
     
     invoice__c pa =[select id,name, doctor__c from Invoice__c where id=:parOrd.id];
         // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL 
     if(u.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        
        LitOrd.staff__c = pa.Doctor__c;
        LitOrd.Quantity__c=1;
       
        ords.add(LitOrd);
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups) 
                
        else if(u.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
         LitOrd.staff__c = pa.Doctor__c;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w[0].id;
        ords.add(LitOrd);
        
        }   
           
        }  
           
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
    public PageReference save() {
        insert ords;
       // PageReference home = new PageReference('/home/home.jsp');
        return(new ApexPages.StandardController(parOrd)).view();
       // home.setRedirect(true);
       // return home;
         }
        
        }

 

 

 

TestCase:

 

 

 

@isTest

private class MyTestClass1

{

 

 static testmethod void TestController()

 {

 

      ApexPages.StandardController con = new ApexPages.StandardController(new Invoice__c());

 

      Invoice__c parOrd = (Invoice__c)con.getRecord();

 

      DEV_MULTIPLE_InvoiceLineEntry dc = new DEV_MULTIPLE_InvoiceLineEntry(con);

 

      List<Invoice_Line_Item__c> ords = new List<Invoice_Line_Item__c>();

 

      user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];

 

      Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];

 

      invoice__c pa =[select id,name, doctor__c from Invoice__c where id=:parOrd.id];

 

      if(u1.Formula_Warehouse__c ==null)

      {

        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();

        LitOrd.Invoice_Number__c = parOrd.id;

        LitOrd.staff__c = pa.Doctor__c;

        LitOrd.quantity__c=1;

        ords.add(LitOrd);

 

        }

 

       else if(u1.Formula_Warehouse__c !=null)

       {

 

        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();

        LitOrd.Invoice_Number__c = parOrd.id;

        LitOrd.quantity__c=1;

        LitOrd.staff__c = pa.Doctor__c;

        LitOrd.Item_Warehouse__c =w1[0].id;

        ords.add(LitOrd);

        } 

 

 

        dc.addrow();

        dc.removerow();

        dc.save();

 

}     

 

 }

 

 

 

I am getting the following Error Messages,  so could any one please correct them, so that the test case is successful.

 

Error Messages:

 




System.QueryException: List has no rows for assignment to SObjectClass.DEV_MULTIPLE_InvoiceLineEntry.<init>: line 13, column 21 Class.MyTestClass1.TestController: line 12, column 42 External entry point

 

 

 

 

Thanks and Regards

 

 

Arun

Hi All,

 

    We have written an apex class for multiple line items, but facing problem in writing the test case for the same.  So, could any one please suggest a solution to the making the test case successful. 

 

 

Apex Code:

 

 

public class DEV_MULTIPLE_InvoiceLineEntry {

    public List<Invoice_Line_Item__c> ords {get; set;}
    private final Invoice__c parOrd;
    public DEV_MULTIPLE_InvoiceLineEntry(ApexPages.StandardController myController) {
        parOrd=(Invoice__c)myController.getrecord();
        ords = new List<Invoice_Line_Item__c>();
         // Get the Current User
     user u1 =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w1 =[select id,name from Warehouse__c where name =: u1.Formula_Warehouse__c or name = null];
     
     // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL
        if(u1.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
       
        ords.add(LitOrd);
         
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups)
        else if(u1.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
      
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w1[0].id;
        ords.add(LitOrd);
        }
        }
        
       

    public void addrow() {
    
        // Get the Current User
     user u =[select id ,name,Formula_Warehouse__c from user where id=:UserInfo.getUserId()];
         //Get The DefaultwareHouse for the user
     Warehouse__c[] w =[select id,name from Warehouse__c where name =: u.Formula_Warehouse__c];
         // Condition to Check if Formula_Warehouse__c =null, if null Item_Warehouse__c on page is NULL
     if(u.Formula_Warehouse__c ==null){
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.Quantity__c=1;
       
        ords.add(LitOrd);
        }
        // Condition to Check if Formula_Warehouse__c !=null, if ! null Item_Warehouse__c on page is warehouse id(only ids display names in Lookups)
                
        else if(u.Formula_Warehouse__c !=null){
        
        Invoice_Line_Item__c LitOrd = new Invoice_Line_Item__c();
        LitOrd.Invoice_Number__c = parOrd.id;
        LitOrd.quantity__c=1;
        LitOrd.Item_Warehouse__c =w[0].id;
        ords.add(LitOrd);
        
        }   
           
        }  
           
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
    public PageReference save() {
        insert ords;
       // PageReference home = new PageReference('/home/home.jsp');
        return(new ApexPages.StandardController(parOrd)).view();
       // home.setRedirect(true);
       // return home;
         }
        
        }

 

 

 

Thanks and Regards

 

Arun

Hi All,

 

    I have a requirement where in I need to convert an AggregateResult to a String in Apex class, so that I can display it in the VisualForce page.  Could any one please suggest a solution for this problem.

 

 

 

 

Regards

 

Rahul

Hi,

 

     I have requirement, where in I have 2 record types, Hardware Record Type and Software Record Type under Opporutnities,  I just want to generate two separate autonumbers for Hardware recordtype and Software recordtype.  I tried  to get this using functionality, but I am not getting the desired output.

 

 

Output

 

HW-0001

HW-0002

HW-0003

SW-0004

SW-0005

SW-0006

 

 

Desired Output

 

HW-0001

HW-0002

HW-0003

SW-0001

SW-0002

SW-0003

 

 

      For the above requirement, I want to generate autonumber in an Apex Class,  could any one please send the solution for the above mentioned requirement.

 

 

 

Regards

 

Arun

 

 

 

 

I have a requirement where in  I need to fetch the records from Opportunity standard object based on the closedate field (MM/DD/YYYY) criteria.  For that I have written a visualforce page which takes the close date in the search field which is accepted as a string.  But in the Apex class when I am executing the sql query, i am getting type mismatch error, date cannot be compated to string.   I tried many options to convert string to date, but its not working.   I am  postng  the code snippet.

 

 

Apex Class

 

 

public class OpportunitySearchController1 {

    public OpportunitySearchController1() {

    }

    
    private ApexPages.StandardController controller {get; set;}
  
      public List<opportunity> searchResults {get;set;}
    
          public string searchText {
        get {
            if (searchText == null) searchText = 'Test'; // prefill the serach box for ease of use
            return searchText;
        }
        set;
    }
  
    
 
    public OpportunitySearchController1(ApexPages.StandardController controller) {
 
               this.controller = controller;
       
    }
 
   
    public PageReference search() {
        if (searchResults == null) {
            searchResults = new List<opportunity>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
        }
        // Note: you could have achieved the same results as above by just using:
        // searchResults = new List<categoryWrapper>();
        String date_search= searchText;
 
        // use some dynamic soql to find the related opportunities by name
       
           String qry = 'Select o.Id, o.Name, o.StageName, o.CloseDate, o.Amount from Opportunity o  where  o.closedate LIKE \''+searchText+'%\' Order By o.Name';
      
        searchResults = Database.query(qry);
        return null;
    }
 }

 

 

VisualForce Page

-------------------------

<apex:page standardController="Opportunity" extensions="OpportunitySearchController1" sidebar="true" showHeader="true" >
<style type="text/css">
body {background: #F3F3EC; padding-top: 15px}
</style>
<!-- <b><apex:outputLink value="https://c.ap1.visual.force.com/apex/jeff"> Opportunities </apex:outputLink></b>&nbsp;&nbsp;
<b><apex:outputLink value="https://c.ap1.visual.force.com/apex/subhash"> Contacts </apex:outputLink></b>
-->
<apex:form >
<br/><br/><br/>
<b><apex:outputLink value="https://c.ap1.visual.force.com/apex/GeneralReport"> Opportunities </apex:outputLink></b>&nbsp;&nbsp;
<br/><br/> <b><apex:outputLink value="https://c.ap1.visual.force.com/apex/DisplayReport"> Tasks </apex:outputLink></b>
<br/><br/>
<apex:pageBlock title="Search for Opportunities by Keyword" id="block" mode="edit">
<apex:pageMessages />

<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Close Date</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="GO" action="{!search}" rerender="resultsBlock" status="status"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:actionStatus id="status" startText="Searching... please wait..."/>
<apex:pageBlockSection id="resultsBlock" columns="1">
<apex:pageBlockTable value="{!searchResults}" var="o" rendered="{!NOT(ISNULL(searchResults))}">
<apex:column headerValue="Name">
<apex:outputLink value="/{!o.Id}">{!o.Name}</apex:outputLink>
</apex:column>
<apex:column value="{!o.StageName}"/>
<apex:column value="{!o.Amount}"/>
<apex:column value="{!o.CloseDate}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>

 

If you have any  solution for the above mentioned code kindly post your suggestion. 

 

 

 

 

Regards

 

Arun

 

We have ONE object with 3 different record types:

 

1. Purchase Orders (PO)

2. Invoices (Inv)

3. Official Receipts (OR)

 

There are three different operating branches that uses these, example as below:

 

1. New York

2. Sydney

3. Paris

 

We want to have different auto-numbers for these 3 different record types for these 3 different branches. Example as follows:

 

NY-PO-1001

NY-PO-1002

SYD-PO-1001

SYD-PO-1002

PA-PO-1001

PA-PO-1002

NY-Inv-1001

NY-Inv-1002

SYD-Inv-1001

SYD-Inv-1002

PA-Inv-1001

PA-Inv-1002

NY-OR-1001

NY-OR-1002

SYD-OR-1001

SYD-OR-1002

PA-OR-1001

PA-OR-1002

 

Using Auto-Numbers in Salesforce produces the result below, which we DO NOT WANT:

 

NY-PO-1001

NY-PO-1002

SYD-PO-1003

SYD-PO-1004

PA-PO-1005

PA-PO-1006

NY-Inv-1007

NY-Inv-1008

SYD-Inv-1009

SYD-Inv-1010

PA-Inv-1011

PA-Inv-1012

NY-OR-1013

NY-OR-1014

SYD-OR-1015

SYD-OR-1016

PA-OR-1017

PA-OR-1018

 

What is the solution without APEX or triggers for this?

 

If there is no standard solution in Salesforce, what do we need to do for APEX / Triggers to resolve the above?