• jeevitha annabathula 5
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies
@isTest
public class InvoicelineConvertTest
{
    static testmethod void InvoicelineConvertTest ()
    {
        Invoice_Line__c b = new Invoice_Line__c(Quantity__c=100, Unit_Price__c=90,Invoice__c='a0Z0R000002u0KE');
        
   //a0p0R000003TCD2
       System.debug('Unit Price before inserting new Invoice Line: ' + b.Unit_Price__c);

       // Insert Invoice Line
       insert b;
    
       // Retrieve the Invoice Line
       b = [SELECT Unit_Price__c FROM Invoice_Line__c WHERE Id =:b.Id];
       System.debug('Price after trigger fired: ' + b.Unit_Price__c);

       // Test that the trigger correctly updated the price
       System.assertEquals(90, b.Unit_Price__c);
        
        Invoice_Line__c[] newInv1 = [select id,name,Invoice__c from Invoice_Line__c];
        insert newInv1;
        ApexPages.StandardSetController sc = new ApexPages.standardSetController(newInv1);
        InvoiceLineItems  controller = new InvoiceLineItems(sc);
        Test.startTest();
            controller.addLineItem();
            controller.removerow();
            controller.cancel();
         System.assertNotEquals(null,controller.saveLineItem());
        Test.stopTest();
            
        
               
    }
}
I have written two separate visual force pages to prepopulate and add rows dynamically. I would like to know how to merge these two codes. Can some help me with this coding please.
 
PREPOPULATE
<apex:page standardController="IT_Contract_Line__c" extensions="Autocall,AddNewRows" showHeader="true" sidebar="true">
<apex:form >
<apex:pageBlock >
    
 <apex:pageBlockSection >
 <apex:pageBlockTable value="{!cwrap}" var="cn">
       <apex:column headerValue="Product">
<apex:inputField value="{!Testing.Product__c}" >
    <apex:actionSupport event="onchange"  action="{!autoCal}"   reRender="accEmail,accPhone">
</apex:actionSupport>
</apex:inputField>
</apex:column>
<apex:column headerValue="UOM">
<apex:inputField value="{!Testing.UOM_Unit_Of_Measure1__c}"  id="accEmail"  html-disabled="true"/>
</apex:column>
<apex:column headerValue="Unit Price">
<apex:inputField value="{!Testing.Unit_Price__c}"  id="accPhone"/>
</apex:column>
<apex:column headerValue="QUantity">
<apex:inputField value="{!Testing.Quantity__c}"/>
</apex:column>
<apex:column headerValue="Discount">
<apex:inputField value="{!Testing.Unit_Discount__c}"/>
</apex:column>
<apex:column headerValue="Line Tax">
<apex:inputField value="{!Testing.Line_Tax__c}"/>
</apex:column>
<apex:column headerValue="IT-Contracts">
<apex:outputField value="{!Testing.IT_Contracts__c }"  html-disabled="true"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="AddRow" action="{!addRows}" reRender="lab"/>
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlock>
</apex:form>
</apex:page>
PREPOPULATE
public class Autocall {
public IT_Contract_Line__c Testing {get;set;}
public boolean flag{get;set;}
private ApexPages.StandardController stdController;
public Autocall(ApexPages.StandardController controller) {
Testing=(IT_Contract_Line__c)controller.getRecord();
}
//function is called from actionsupport event

public PageReference autoCal()
{
Id accId = Testing.Name;     // collecting account id from visualforce page
List<Product2> accLst = [select id,UOM__c,List_Price__c from Product2 where id=:Testing.Product__c];
Testing.UOM_Unit_Of_Measure1__c = accLst[0].UOM__c; 
Testing.Unit_Price__c = accLst[0].List_Price__c;
return null;
}
 public PageReference save()
{
upsert Testing;
flag=true;
    PageReference nextPage = new ApexPages.StandardController(Testing).view();
        nextPage.setRedirect(true);      
        return nextPage;

}
}

ADD ROWS DYNAMICALLY
<apex:page standardController="IT_Contract_Line__c"  recordSetVar="IT_Contract_Line__c" extensions="ITContractLines">
     <apex:form > 
        <apex:pageBlock >
             <apex:pageBlockSection title="Add Vendor QuoteLines" columns="1">
             <apex:pageBlockTable value="{!listMeetingAttendee}" var="meetAtt" id="customTable">
             <apex:column headerValue="Product">
                 <apex:inputField value="{!meetAtt.Product__c}" required="true"/>
             </apex:column>
                 <apex:column headerValue="Quantity">
                 <apex:inputField value="{!meetAtt.Quantity__c}"/>
             </apex:column>
             <apex:column headerValue="Unit Price">
                 <apex:inputField value="{!meetAtt.Unit_Price__c }"/>
             </apex:column>             
                 <apex:column headerValue="Unit Discount">
                 <apex:inputField value="{!meetAtt.Unit_Discount__c}"/>
             </apex:column>
                  <apex:column headerValue="Line Tax">
                 <apex:inputField value="{!meetAtt.Line_Tax__c}"/>
             </apex:column>
             <apex:column headerValue="IT-Contract">
                 <apex:outputField value="{!meetAtt.IT_Contracts__c }"  html-disabled="true"/>
             </apex:column>
                 <apex:column id="two">
               <apex:commandButton value="Remove LineItem" action="{!removerow}"/>  
              </apex:column>
             </apex:pageBlockTable>
             </apex:pageBlockSection>
             <apex:pageBlockButtons >
                 <apex:commandButton value="Add IT-ContractLines" action="{!addLineItem}" rerender="customTable" immediate="true"/>
                 <apex:commandButton value="Save IT-ContractLines" action="{!saveLineItem}"/>
                 <apex:commandButton value="Cancel" action="{!cancel}" immediate="true"/>
             </apex:pageBlockButtons>
             
         </apex:pageBlock> 
     </apex:form>
</apex:page>
ADD ROWS DYNAMICALLY
public class ITContractLines {
public List<IT_Contract_Line__c> listMeetingAttendee {get; set;}
    IT_Contract_Line__c meetingAttendee = new IT_Contract_Line__c();
   IT_Contracts__c meetingAttendees = new IT_Contracts__c();
    public String KARId = apexpages.currentpage().getParameters().get('Id');
     public ApexPages.StandardSetController stdCntrlr {get; set;}
     public ITContractLines(ApexPages.StandardSetController controller) { 
     stdCntrlr = controller;
        listMeetingAttendee = new List<IT_Contract_Line__c>();
        system.debug(KARId);
        if(KARId<>null){
            for(IT_Contracts__c KAR: [SELECT Id FROM IT_Contracts__c WHERE Id =:KARId ]){
                meetingAttendee.IT_Contracts__c = KARId ;
                listMeetingAttendee.add(meetingAttendee );
            }      
        } else{
             listMeetingAttendee.add(meetingAttendee );
        }
        
    }
    public void addLineItem(){
        IT_Contract_Line__c meetAtt = new IT_Contract_Line__c();
        meetAtt.IT_Contracts__c = KARId ;
        listMeetingAttendee.add(meetAtt);
    }
    public PageReference saveLineItem() {
         system.debug('listMeetingAttendee'+listMeetingAttendee);
        for(Integer i=0; i<listMeetingAttendee.size(); i++)
        {
            upsert listMeetingAttendee;
        }
        PageReference nextPage = new ApexPages.StandardController(meetingAttendees).view();
        nextPage.setRedirect(true);      
        return nextPage;
        }
    public void removerow()
     { 
         Integer i = listMeetingAttendee.size();
          listMeetingAttendee.remove(i-1);
     }
         public PageReference cancel(){
         Id ide =  ApexPages.Currentpage().getParameters().get('id'); 
         return new PageReference('/' + KARId );
    }
}

 
<apex:page StandardController="Test_QuoteLine__c" extensions="Multiadd" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add Line Item" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save QuoteLineItem" action="{!save}"/>
    </apex:pageBlockButtons>
    
        <apex:pageblock id="pb1">
            
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="6">
                
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Delete</apex:facet>
                    <apex:commandButton value="Remove" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>   
                
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Sales price</apex:facet>
                    <apex:inputfield value="{!e1.acct.Unit_Price__c}" required="false"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Quantity</apex:facet>
                    <apex:inputfield value="{!e1.acct.Quantity__c}" required="false"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Discount</apex:facet>
                    <apex:inputfield value="{!e1.acct.Discount__c}" required="false"/>
                </apex:panelGrid>
                    <apex:panelGrid >
                    <apex:facet name="header">Quote</apex:facet>
                    <apex:inputfield value="{!e1.acct.New_Quote__c}" required="false" />
                </apex:panelGrid>
                <apex:panelGrid >
                    <apex:facet name="header">Product</apex:facet>
                    <apex:inputfield value="{!e1.acct.Product__c}" required="false" />
                </apex:panelGrid>
      </apex:panelGrid>
        </apex:repeat>
    </apex:pageblock>
</apex:pageblock>
</apex:form>
</apex:page>



controller:
public class Multiadd
{
    
   
    public List<Test_QuoteLine__c>lstAcct  = new List<Test_QuoteLine__c>();
    private ApexPages.StandardController controller;
    public Multiadd(ApexPages.StandardSetController controller) {
        controller.setPageSize(10);
       
    }
    
      public List<innerClass> lstInner 
    {   get;set;    }
    
       public String selectedRowIndex
    {get;set;}  
    
     public Integer count = 1;
    //{get;set;}
    
     public PageReference Save()
    {
        PageReference pr = new PageReference('/a59/o');
        
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstAcct.add(lstInner[j].acct);
        } 
        insert lstAcct;
        pr.setRedirect(True);
        return pr;
    }
          
    //add one more row
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    
    /*Begin addMore*/
    public void addMore()
    {
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        
        //add the record to the inner class list
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    
      public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }
    
    public MultiAdd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
        
    }
        
    public class innerClass
    {       
       
        public String recCount
        {get;set;}
        
        
        public Test_QuoteLine__c acct 
        {get;set;}
        
     
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);         
            /*create a new account*/
            acct = new Test_QuoteLine__c();
        acct.New_Quote__c = ApexPages.CurrentPage().getparameters().get('quoteId');
            
        }   
    }
}
quote value has to prepoulate here
 
controller:
public with sharing class meetingAttendeeExtension {
    public List<jee__Test_QL__c> listMeetingAttendee {get; set;}
    jee__Test_QL__c meetingAttendee = new jee__Test_QL__c();
    public String KARId = apexpages.currentpage().getParameters().get('QuoteId');
    ApexPages.StandardController controller;
    public meetingAttendeeExtension(ApexPages.StandardController controller) {
        listMeetingAttendee = new List<jee__Test_QL__c>();
        if(KARId<>null){
            for(jee__Test_quote__c KAR: [SELECT Id FROM jee__Test_quote__c WHERE Id =:KARId ]){
                meetingAttendee.jee__Quote__c = KARId ;
                listMeetingAttendee.add(meetingAttendee );
            }      
        } else{
             listMeetingAttendee.add(meetingAttendee );
        }
        
    }
    public void addMeetingAttendee(){
        jee__Test_QL__c meetAtt = new jee__Test_QL__c();
         meetAtt.jee__Quote__c = KARId ;
        listMeetingAttendee.add(meetAtt);
    }
    public PageReference saveMeetingAttendees() {
        for(Integer i=0; i<listMeetingAttendee.size(); i++)
        {
            insert listMeetingAttendee;
        }
        return new PageReference('/' + KARId);
        }
    public PageReference cancel(){
        return new PageReference('/' + KARId );
    }
}

vf:
<apex:page standardController="Test_QL__c" extensions="meetingAttendeeExtension" showHeader="false" applyHtmlTag="false">
     <apex:form >
         <apex:pageBlock >
             <apex:pageBlockSection title="Add Meeting Attendees" columns="1">
             <apex:pageBlockTable value="{!listMeetingAttendee}" var="meetAtt" id="customTable">
            <apex:column headerValue="salesPrice">
                 <apex:inputField value="{!meetAtt.Sales_Price__c}"/>
             </apex:column>
             <apex:column headerValue="Quantity">
                 <apex:inputField value="{!meetAtt.Quantity__c}"/>
             </apex:column>
             <apex:column headerValue="Discount">
                 <apex:inputField value="{!meetAtt.Discount__c}"/>
             </apex:column>
            <apex:column headerValue="Product">
                 <apex:inputField value="{!meetAtt.Product__c}"/>
             </apex:column>
            <apex:column headerValue="Quote">
                 <apex:inputField value="{!meetAtt.Quote__c}"/>
             </apex:column>
             </apex:pageBlockTable>
             </apex:pageBlockSection>
             <apex:pageBlockButtons >
                 <apex:commandButton value="Add Account Row" action="{!addMeetingAttendee}" rerender="customTable" immediate="true"/>
                 <apex:commandButton value="Save Meeting Attendees" action="{!saveMeetingAttendees}"/>
                 <apex:commandButton value="Cancel" action="{!cancel}" immediate="true"/>
             </apex:pageBlockButtons>
             
         </apex:pageBlock>
     </apex:form>
</apex:page>


lookup field value is not populating and after saving record I need to go back to parent detial page to add new quote line.please help me with this . I am trying this from  three days. I refered this https://developer.salesforce.com/forums/?id=906F0000000AxCAIA0. but still it could not solve my problem. please help me with this.

 
@isTest
public class InvoicelineConvertTest
{
    static testmethod void InvoicelineConvertTest ()
    {
        Invoice_Line__c b = new Invoice_Line__c(Quantity__c=100, Unit_Price__c=90,Invoice__c='a0Z0R000002u0KE');
        
   //a0p0R000003TCD2
       System.debug('Unit Price before inserting new Invoice Line: ' + b.Unit_Price__c);

       // Insert Invoice Line
       insert b;
    
       // Retrieve the Invoice Line
       b = [SELECT Unit_Price__c FROM Invoice_Line__c WHERE Id =:b.Id];
       System.debug('Price after trigger fired: ' + b.Unit_Price__c);

       // Test that the trigger correctly updated the price
       System.assertEquals(90, b.Unit_Price__c);
        
        Invoice_Line__c[] newInv1 = [select id,name,Invoice__c from Invoice_Line__c];
        insert newInv1;
        ApexPages.StandardSetController sc = new ApexPages.standardSetController(newInv1);
        InvoiceLineItems  controller = new InvoiceLineItems(sc);
        Test.startTest();
            controller.addLineItem();
            controller.removerow();
            controller.cancel();
         System.assertNotEquals(null,controller.saveLineItem());
        Test.stopTest();
            
        
               
    }
}
Hello,

I have multiple problems. But before that I want to share the code that I wrote.

Apex Class:
public with sharing class meetingAttendeeExtension {
    public List<MeetingAttendees__c> listMeetingAttendee {get; set;}
    MeetingAttendees__c meetingAttendee = new MeetingAttendees__c();
    public String KARId = apexpages.currentpage().getParameters().get('id');
    ApexPages.StandardController controller;
    public meetingAttendeeExtension(ApexPages.StandardController controller) {
        listMeetingAttendee = new List<MeetingAttendees__c>();
        listMeetingAttendee.add(meetingAttendee );
        controller = this.controller;
    }
    public void addMeetingAttendee(){
        MeetingAttendees__c meetAtt = new MeetingAttendees__c();
        listMeetingAttendee.add(meetAtt);
    }
    public PageReference saveMeetingAttendees() {
        for(Integer i=0; i<listMeetingAttendee.size(); i++)
        {
            insert listMeetingAttendee;
        }
        return new PageReference('/' + Schema.getGlobalDescribe().get('Key_Account_Report__c').getDescribe().getKeyPrefix() + '/o'); // this works but not what I am trying to acheive
        }
    public PageReference cancel(){
        return new PageReference('/' + controller.getId() );// returns null
    }
}

Visualforce Page: 
<apex:pageBlock >
             <apex:pageBlockSection title="Add Meeting Attendees" columns="1">
             <apex:pageBlockTable value="{!listMeetingAttendee}" var="meetAtt" id="customTable">
             <apex:column headerValue="Key Account Report Name">
                 <apex:inputField value="{!meetAtt.Call_Report__c}"/>
             </apex:column>
             <apex:column headerValue="Attendee Type">
                 <apex:inputField value="{!meetAtt.Attendee_Type__c}"/>
             </apex:column>
             <apex:column headerValue="Attendee Name">
                 <apex:inputField value="{!meetAtt.Attendee_Name__c}"/>
             </apex:column>
             </apex:pageBlockTable>
             </apex:pageBlockSection>
             <apex:pageBlockButtons >
                 <apex:commandButton value="Add Account Row" action="{!addMeetingAttendee}" rerender="customTable"/>
                 <apex:commandButton value="Save Meeting Attendees" action="{!saveMeetingAttendees}"/>
                 <apex:commandButton value="Cancel" action="{!cancel}" immediate="true"/>
             </apex:pageBlockButtons>
             
         </apex:pageBlock>
     </apex:form>
</apex:page>

Now there are following questions that I am trying to find but unable to implement.
Meeting_Attendees__c is child to Key_Account_Reports__c(Master Detail Relationship).
1. when I click "Add New Attendees", the name of Parent Key Account report does not poppulate by itself (how to do this)
2. controller.getId() gives me null, i am expecting to get parent ID here, is this right way ?

Solving above will help me acheive following.
1. Auto populate name of parent object so that user need not select it from the huge liste of Key Account Reports
2. create buttons which will navigate user to parent record, detail view page.

I found previous post related  to this https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F000000090tcIAA

but this does not help.

Please suggest some way to acheive above.

Regards, 
Nitin V Palmure