• DevAccount
  • NEWBIE
  • 0 Points
  • Member since 2010

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

How to write Test method for Upsert Statement. Please help..

 

public PageReference reset() 
{
TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDeleted__c from TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
return null;
}


public PageReference saveItem()
{
upsert TallySheetItemList;
reset();
return null;
}

Currently I have it in my testMethod

 

/* Test Case */

static testMethod void myUnitTest() {
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);
Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
TallySheetItems controller = new TallySheetItems(sc);
controller.reset();
controller.saveItem();
}

/* Test Case ends....*/

 

Hi,

 

Help needed on writing test method.

 

I checked the line coverage and found the below red fonted were not covered, Please help to write test cases for the Upsert statement.

 

 

public with sharing class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

Tally_Sheet__c TS;
String recordId;

public TallySheetItems(ApexPages.StandardController stdController)
{
recordId = stdController.getId();
TS = (Tally_Sheet__c) stdController.getRecord();
this.controller=stdController;
}

List<TS_NASAAC_Item__c> TallySheetItemList;

public PageReference reset()
{
TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDelete d__c from TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
return null;
}

public List<TS_NASAAC_Item__c> getTallySheetItems()
{
if(TallySheetItemList== null) reset();
return TallySheetItemList;
}

public PageReference saveItem()
{
upsert TallySheetItemList;
reset();
return null;
}

public PageReference add()
{
TS_NASAAC_Item__c TSI = new TS_NASAAC_Item__c();
TSI.Tally_Sheet_Ref__c = TS.ID;
TallySheetItemList.add(TSI);
return null;
}


/* Test Case */

static testMethod void myUnitTest() {
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);
Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
TallySheetItems controller = new TallySheetItems(sc);
controller.getTallySheetItems();
controller.reset();
controller.add();
controller.saveItem();
}

/* Test Case ends....*/


}



Any help would certainly appreciated.

Thanks
Dev

 

Hi,

 

Help needed on writing test method.

 

I checked the line coverage and found the below red fonted were not covered, Please help to write test cases for the Upsert statement.

 

 

public with sharing class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

Tally_Sheet__c TS;
String recordId;

public TallySheetItems(ApexPages.StandardController stdController)
{
recordId = stdController.getId();
TS = (Tally_Sheet__c) stdController.getRecord();
this.controller=stdController;
}

List<TS_NASAAC_Item__c> TallySheetItemList;

public PageReference reset()
{
TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDelete d__c from TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
return null;
}

public List<TS_NASAAC_Item__c> getTallySheetItems()
{
if(TallySheetItemList== null) reset();
return TallySheetItemList;
}

public PageReference saveItem()
{
upsert TallySheetItemList;
reset();
return null;
}

public PageReference add()
{
TS_NASAAC_Item__c TSI = new TS_NASAAC_Item__c();
TSI.Tally_Sheet_Ref__c = TS.ID;
TallySheetItemList.add(TSI);
return null;
}


/* Test Case */

static testMethod void myUnitTest() {
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);
Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
TallySheetItems controller = new TallySheetItems(sc);
controller.getTallySheetItems();
controller.reset();
controller.add();
controller.saveItem();
}

/* Test Case ends....*/


}



Any help would certainly appreciated.

Thanks
Dev

 

 

Hi,

 

I am new to Salesforce. Help needed on writing test method. mu current method covers 44% please help to get it 75%.

 

	 	  public with sharing class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

//added an instance varaible for the standard controller
Tally_Sheet__c TS;
String recordId;

public TallySheetItems(ApexPages.StandardController stdController)
{

recordId = stdController.getId();
TS = (Tally_Sheet__c) stdController.getRecord();
this.controller=stdController;  
 
}


                List<TS_NASAAC_Item__c> TallySheetItemList;
                List<TS_NASAAC_Item__c> TallySheetItemList1;
                public double total { get; set; }
                public PageReference reset() {
                     TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
                     NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDeleted__c from
                     TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
                     
                     
                     return null;
                }  
             
                public List<TS_NASAAC_Item__c> getTallySheetItems() {
                     if(TallySheetItemList== null) reset();
                     return TallySheetItemList;
                }
 
                public void setTallySheetItems(List<TS_NASAAC_Item__c> TallySheetItems) {
                      TallySheetItemList = TallySheetItems;
                }
 
                public PageReference saveItem() {
                     total = 0;
                     for(TS_NASAAC_Item__c o: TallySheetItemList)
                     {           
                       if(o.GR_WT_KGS__c!= null)
                       {             
                       total += o.GR_WT_KGS__c;          
                       }
                     }    
                     TS.TOTAL__c = total;     
                     update TS;              
                      upsert TallySheetItemList;
                      reset();
                      return null;
                }
 
                public PageReference add() {
                                TS_NASAAC_Item__c TSI = new TS_NASAAC_Item__c();
                                TSI.Tally_Sheet_Ref__c = TS.ID;
                                TallySheetItemList.add(TSI);
                                return null;
                }
                
                //string RowID;
                //public String getRowID() {return this.RowID;}
                //public List<TS_NASAAC_Item__c> TSIlst { get; set; }              
                //public PageReference DeleteRow()
                //{
                //string RowID = ApexPages.CurrentPage().getParameters().get('RowID');
                
                //TallySheetItemDelList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
                    // NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c from
                    // TS_NASAAC_Item__c where ID = :RowID limit 1];
      
               // if ( TallySheetItemDelList.size() > 0 )
                  //    {           
                  //      delete TallySheetItemDelList;   
                 //      }   
                       
                       
                // if for any reason we are missing the reference
                //if (RowID == null)
                //{
                  //return null;      }           
                  // find the account record within the collection      
                  //TS_NASAAC_Item__c tobeDeleted = null;      
                  //for(TS_NASAAC_Item__c a : TSIlst)       
                  //if (a.Id == RowID)
                  //{         
                   //tobeDeleted = a;         
                   // break;       
                    //}           
                     //if account record found delete it     
                     // if (tobeDeleted != null)
                     // {       Delete tobeDeleted;      }                  
                   //reset();           
                //delete TallySheetItemDelList;
               // return null;
                //}
                
                public PageReference ExportExcel()
                {
                 TS.Exported__c = true;
                 update TS;
                 PageReference customPage = Page.vfTallySheetExport;
                 customPage.setRedirect(true);
                 customPage.getParameters().put('id', recordId);
                 return customPage;
                }
                
                public string[] getheaders()
                {
                return new string [] {'Melt#', 'BND#', 'GR WT KGS', 'TARE', 'NET WT KGS', 'Melt Date', 'INGOTS', 'Ref#'} ;
                }
                
                public List<TS_NASAAC_Item__c> getTallySheetItems1() {
                     if(TallySheetItemList== null) reset1();
                     return TallySheetItemList;
                }
                
                 public PageReference reset1() {
                     TallySheetItemList= [select MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
                     NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c from
                     TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
      
                     return null;
                }  
                
                 public PageReference Completed() {
                                TS.Completed__c = true;
                                 update TS;
                                return null;
                }
                
                
     /* Test Case */

static testMethod void myUnitTest() {
 
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);

Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
 List<TS_NASAAC_Item__c> TallySheetItemList;
 List<TS_NASAAC_Item__c> TallySheetItemList1;
 

TallySheetItems controller = new TallySheetItems(sc);
controller.reset();

 TallySheetItemList = null;
controller.getTallySheetItems();

TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDeleted__c from
TS_NASAAC_Item__c where Tally_Sheet_Ref__c = 'a06T0000008OAyE' and IsDeleted__c = false order by CreatedDate limit 100 ];

controller.add();
controller.ExportExcel();
controller.getheaders();
controller.reset1();
controller.Completed();         
controller.saveItem();

}

/* Test Case ends....*/

 
}

 

 

 

 

Hi,

 

I am sucessful in exporting Visual force page to Excel with the

 

contenttype="application/vnd.ms-excel#FileName.xls

 

on the Page Tag. My Page have a (.jpg) Image.

 

But the Images are not showing up on excel. Please let me know how to export the visualforce page to excel with the image.

 

Thanks and would appreciate any help on this.

Arif

Hi,

     I am trying to Pass Standard controller output value to Extension controller Method's Soql. but its not passing the Parameter "RefID" to the extention controller Method's Soql where condition.

 

The soql works if I hard code the value in  where condition instead of parameter, like where TALLY_SHEET_REF__C = 'a005000000H1kcCAAR'

 

 

As you can see, I have red bolded the line that are not working..

 

 

My Visualforce page: (standardController="Tally_Sheets__c"  and  extensions="TallySheetItems")

 

<apex:page standardController="Tally_Sheets__c" extensions="TallySheetItems"  >
<apex:sectionHeader title="{!$ObjectType.Tally_Sheets__c.label}" subtitle="{!Tally_Sheets__c.name}"/>
<apex:pageBlock title="{!$ObjectType.Tally_Sheets__c.label} Header Detail">
<apex:pageBlockButtons location="top" >
<apex:form >
<apex:stylesheet value="{!$Resource.PacoriniCSS}"/>
<apex:commandButton action="{!edit}" value="Edit"/>
<apex:commandButton action="{!delete}" value="Delete"/>
<apex:commandButton action="{!URLFOR($Action.Tally_Sheets__c.Clone,Tally_Sheets__c.id)}" value="Clone"/>
</apex:form>
</apex:pageBlockButtons>
<table width="100%" >
<tr width="100%">
<td width="25%" >
<apex:outputLabel style="font-weight:bold;" value="State:" />
<apex:outputField id="txtState" value="{!Tally_Sheets__c.State__c}"/>
</td>
<td width="25%" >
<apex:outputLabel style="font-weight:bold;" value="Ref#:"/>
<apex:outputField id="Ref" value="{!Tally_Sheets__c.Name}"/>
<apex:param value="{!Tally_Sheets__c.Name}" name="RefID" id="RefID" />
</td>
</tr>
</table>

<apex:form >
<apex:outputPanel id="in" >
<apex:actionStatus startText="Updating...." id="outStatus">
<apex:facet name="stop">
<apex:dataTable value="{!TallySheetItems}" var="TSI" styleClass="list" rowClasses="even,odd" headerClass="dthdr" >
<apex:column headerValue="Ref#" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.Tally_Sheet_Ref__c}" /></apex:column>
<apex:column headerValue="Melt#" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.MELT__c}" required="false"/></apex:column>
<apex:column headerValue="Melt Date" ><apex:inputField style="width:100%; height:100%;" value="{!TSI.Melt_Date__c}" required="false"/></apex:column>
<apex:column headerValue="GR_WT_KG" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.GR_WT_KGS__c}" required="false"/></apex:column>
<apex:column headerValue="Tare" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.Tare__c}" required="false"/></apex:column>
</apex:dataTable>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<apex:commandButton value="Submit" action="{!save}" />
<apex:commandButton value="Add" action="{!add}" rerender="in" status="inStatus" />
<apex:commandButton value="Reset" action="{!reset}" rerender="in,outStatus" status="outStatus" />
</apex:form>
</apex:pageBlock>
</apex:page>

 

My extensions Controller "TallySheetItems":

 

 

public class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

//added an instance varaible for the standard controller

public TallySheetItems(ApexPages.StandardController stdController)
{
this.controller=stdController;
}

List<Tally_Sheet_Item__c> TallySheetItemList;

public PageReference reset() {
TallySheetItemList= [select TALLY_SHEET_REF__C, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Tally_Sheet_Item_Ref__c from
Tally_Sheet_Item__c where TALLY_SHEET_REF__C = :ApexPages.currentPage().getParameters().get('RefID') limit 100 ];

return null;
}

public List<Tally_Sheet_Item__c> getTallySheetItems() {
if(TallySheetItemList== null) reset();
return TallySheetItemList;
}

public void setTallySheetItems(List<Tally_Sheet_Item__c> TallySheetItems) {
TallySheetItemList = TallySheetItems;
}

public PageReference save() {
upsert TallySheetItemList;
return null;
}

public PageReference add() {
TallySheetItemList.add(New Tally_Sheet_Item__c());
return null;
}

}

 

 

 
Please let me where am I going wrong. or Let me know any other way to pass the value from the standardController.outputfiled value to the where condition on the extension controller. ( during the "reset" method is called on the extension controller. )


Look forward to your reply


Thanks

Arif

 

 

 

Wow, I just can't seem to figure this simple thing out.  In a visualforce template I want to create a link to an object record. 

 

I've seen examples like this

 

 

({!LEFT($Api.Partner_Server_URL_140, FIND(".com/",$Api.Partner_Server_URL_140)+3)

 

but shouldn't I be able to use a simple relative URL to get this to work?

 

 

 

 

A new record was created!  <a href="/{!RelatedTo.ID}">Click here</a>  to see it.

 

 

However, when the email gets sent out the link becomes "http://5008000000dmoskaax/" and not "http://na8.salesforce.com/5008000000dmoskaax"

 

 

 

Any idears?

 

 

 

Tyler

 

 

 

How to write Test method for Upsert Statement. Please help..

 

public PageReference reset() 
{
TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDeleted__c from TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
return null;
}


public PageReference saveItem()
{
upsert TallySheetItemList;
reset();
return null;
}

Currently I have it in my testMethod

 

/* Test Case */

static testMethod void myUnitTest() {
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);
Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
TallySheetItems controller = new TallySheetItems(sc);
controller.reset();
controller.saveItem();
}

/* Test Case ends....*/

 

Hi,

 

Help needed on writing test method.

 

I checked the line coverage and found the below red fonted were not covered, Please help to write test cases for the Upsert statement.

 

 

public with sharing class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

Tally_Sheet__c TS;
String recordId;

public TallySheetItems(ApexPages.StandardController stdController)
{
recordId = stdController.getId();
TS = (Tally_Sheet__c) stdController.getRecord();
this.controller=stdController;
}

List<TS_NASAAC_Item__c> TallySheetItemList;

public PageReference reset()
{
TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDelete d__c from TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
return null;
}

public List<TS_NASAAC_Item__c> getTallySheetItems()
{
if(TallySheetItemList== null) reset();
return TallySheetItemList;
}

public PageReference saveItem()
{
upsert TallySheetItemList;
reset();
return null;
}

public PageReference add()
{
TS_NASAAC_Item__c TSI = new TS_NASAAC_Item__c();
TSI.Tally_Sheet_Ref__c = TS.ID;
TallySheetItemList.add(TSI);
return null;
}


/* Test Case */

static testMethod void myUnitTest() {
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);
Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
TallySheetItems controller = new TallySheetItems(sc);
controller.getTallySheetItems();
controller.reset();
controller.add();
controller.saveItem();
}

/* Test Case ends....*/


}



Any help would certainly appreciated.

Thanks
Dev

 

 

Hi,

 

I am new to Salesforce. Help needed on writing test method. mu current method covers 44% please help to get it 75%.

 

	 	  public with sharing class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

//added an instance varaible for the standard controller
Tally_Sheet__c TS;
String recordId;

public TallySheetItems(ApexPages.StandardController stdController)
{

recordId = stdController.getId();
TS = (Tally_Sheet__c) stdController.getRecord();
this.controller=stdController;  
 
}


                List<TS_NASAAC_Item__c> TallySheetItemList;
                List<TS_NASAAC_Item__c> TallySheetItemList1;
                public double total { get; set; }
                public PageReference reset() {
                     TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
                     NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDeleted__c from
                     TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
                     
                     
                     return null;
                }  
             
                public List<TS_NASAAC_Item__c> getTallySheetItems() {
                     if(TallySheetItemList== null) reset();
                     return TallySheetItemList;
                }
 
                public void setTallySheetItems(List<TS_NASAAC_Item__c> TallySheetItems) {
                      TallySheetItemList = TallySheetItems;
                }
 
                public PageReference saveItem() {
                     total = 0;
                     for(TS_NASAAC_Item__c o: TallySheetItemList)
                     {           
                       if(o.GR_WT_KGS__c!= null)
                       {             
                       total += o.GR_WT_KGS__c;          
                       }
                     }    
                     TS.TOTAL__c = total;     
                     update TS;              
                      upsert TallySheetItemList;
                      reset();
                      return null;
                }
 
                public PageReference add() {
                                TS_NASAAC_Item__c TSI = new TS_NASAAC_Item__c();
                                TSI.Tally_Sheet_Ref__c = TS.ID;
                                TallySheetItemList.add(TSI);
                                return null;
                }
                
                //string RowID;
                //public String getRowID() {return this.RowID;}
                //public List<TS_NASAAC_Item__c> TSIlst { get; set; }              
                //public PageReference DeleteRow()
                //{
                //string RowID = ApexPages.CurrentPage().getParameters().get('RowID');
                
                //TallySheetItemDelList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
                    // NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c from
                    // TS_NASAAC_Item__c where ID = :RowID limit 1];
      
               // if ( TallySheetItemDelList.size() > 0 )
                  //    {           
                  //      delete TallySheetItemDelList;   
                 //      }   
                       
                       
                // if for any reason we are missing the reference
                //if (RowID == null)
                //{
                  //return null;      }           
                  // find the account record within the collection      
                  //TS_NASAAC_Item__c tobeDeleted = null;      
                  //for(TS_NASAAC_Item__c a : TSIlst)       
                  //if (a.Id == RowID)
                  //{         
                   //tobeDeleted = a;         
                   // break;       
                    //}           
                     //if account record found delete it     
                     // if (tobeDeleted != null)
                     // {       Delete tobeDeleted;      }                  
                   //reset();           
                //delete TallySheetItemDelList;
               // return null;
                //}
                
                public PageReference ExportExcel()
                {
                 TS.Exported__c = true;
                 update TS;
                 PageReference customPage = Page.vfTallySheetExport;
                 customPage.setRedirect(true);
                 customPage.getParameters().put('id', recordId);
                 return customPage;
                }
                
                public string[] getheaders()
                {
                return new string [] {'Melt#', 'BND#', 'GR WT KGS', 'TARE', 'NET WT KGS', 'Melt Date', 'INGOTS', 'Ref#'} ;
                }
                
                public List<TS_NASAAC_Item__c> getTallySheetItems1() {
                     if(TallySheetItemList== null) reset1();
                     return TallySheetItemList;
                }
                
                 public PageReference reset1() {
                     TallySheetItemList= [select MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
                     NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c from
                     TS_NASAAC_Item__c where Tally_Sheet_Ref__c = :TS.ID and IsDeleted__c = false order by CreatedDate limit 100 ];
      
                     return null;
                }  
                
                 public PageReference Completed() {
                                TS.Completed__c = true;
                                 update TS;
                                return null;
                }
                
                
     /* Test Case */

static testMethod void myUnitTest() {
 
PageReference PageRef = Page.vfTallySheet;
test.setCurrentPage(PageRef);

Apexpages.Standardcontroller sc = new Apexpages.Standardcontroller(new Tally_Sheet__c());
 List<TS_NASAAC_Item__c> TallySheetItemList;
 List<TS_NASAAC_Item__c> TallySheetItemList1;
 

TallySheetItems controller = new TallySheetItems(sc);
controller.reset();

 TallySheetItemList = null;
controller.getTallySheetItems();

TallySheetItemList= [select ID, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Ref__c, IsDeleted__c from
TS_NASAAC_Item__c where Tally_Sheet_Ref__c = 'a06T0000008OAyE' and IsDeleted__c = false order by CreatedDate limit 100 ];

controller.add();
controller.ExportExcel();
controller.getheaders();
controller.reset1();
controller.Completed();         
controller.saveItem();

}

/* Test Case ends....*/

 
}

 

 

Hi,

     I am trying to Pass Standard controller output value to Extension controller Method's Soql. but its not passing the Parameter "RefID" to the extention controller Method's Soql where condition.

 

The soql works if I hard code the value in  where condition instead of parameter, like where TALLY_SHEET_REF__C = 'a005000000H1kcCAAR'

 

 

As you can see, I have red bolded the line that are not working..

 

 

My Visualforce page: (standardController="Tally_Sheets__c"  and  extensions="TallySheetItems")

 

<apex:page standardController="Tally_Sheets__c" extensions="TallySheetItems"  >
<apex:sectionHeader title="{!$ObjectType.Tally_Sheets__c.label}" subtitle="{!Tally_Sheets__c.name}"/>
<apex:pageBlock title="{!$ObjectType.Tally_Sheets__c.label} Header Detail">
<apex:pageBlockButtons location="top" >
<apex:form >
<apex:stylesheet value="{!$Resource.PacoriniCSS}"/>
<apex:commandButton action="{!edit}" value="Edit"/>
<apex:commandButton action="{!delete}" value="Delete"/>
<apex:commandButton action="{!URLFOR($Action.Tally_Sheets__c.Clone,Tally_Sheets__c.id)}" value="Clone"/>
</apex:form>
</apex:pageBlockButtons>
<table width="100%" >
<tr width="100%">
<td width="25%" >
<apex:outputLabel style="font-weight:bold;" value="State:" />
<apex:outputField id="txtState" value="{!Tally_Sheets__c.State__c}"/>
</td>
<td width="25%" >
<apex:outputLabel style="font-weight:bold;" value="Ref#:"/>
<apex:outputField id="Ref" value="{!Tally_Sheets__c.Name}"/>
<apex:param value="{!Tally_Sheets__c.Name}" name="RefID" id="RefID" />
</td>
</tr>
</table>

<apex:form >
<apex:outputPanel id="in" >
<apex:actionStatus startText="Updating...." id="outStatus">
<apex:facet name="stop">
<apex:dataTable value="{!TallySheetItems}" var="TSI" styleClass="list" rowClasses="even,odd" headerClass="dthdr" >
<apex:column headerValue="Ref#" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.Tally_Sheet_Ref__c}" /></apex:column>
<apex:column headerValue="Melt#" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.MELT__c}" required="false"/></apex:column>
<apex:column headerValue="Melt Date" ><apex:inputField style="width:100%; height:100%;" value="{!TSI.Melt_Date__c}" required="false"/></apex:column>
<apex:column headerValue="GR_WT_KG" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.GR_WT_KGS__c}" required="false"/></apex:column>
<apex:column headerValue="Tare" ><apex:inputField style="width:95%; height:100%;" value="{!TSI.Tare__c}" required="false"/></apex:column>
</apex:dataTable>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<apex:commandButton value="Submit" action="{!save}" />
<apex:commandButton value="Add" action="{!add}" rerender="in" status="inStatus" />
<apex:commandButton value="Reset" action="{!reset}" rerender="in,outStatus" status="outStatus" />
</apex:form>
</apex:pageBlock>
</apex:page>

 

My extensions Controller "TallySheetItems":

 

 

public class TallySheetItems {

private ApexPages.StandardController controller {get; set;}

//added an instance varaible for the standard controller

public TallySheetItems(ApexPages.StandardController stdController)
{
this.controller=stdController;
}

List<Tally_Sheet_Item__c> TallySheetItemList;

public PageReference reset() {
TallySheetItemList= [select TALLY_SHEET_REF__C, MELT__c, BND__c, GR_WT_KGS__c, Tare__c,
NET_WT_KGS__c, Melt_Date__c, INGOTS__c, Tally_Sheet_Item_Ref__c from
Tally_Sheet_Item__c where TALLY_SHEET_REF__C = :ApexPages.currentPage().getParameters().get('RefID') limit 100 ];

return null;
}

public List<Tally_Sheet_Item__c> getTallySheetItems() {
if(TallySheetItemList== null) reset();
return TallySheetItemList;
}

public void setTallySheetItems(List<Tally_Sheet_Item__c> TallySheetItems) {
TallySheetItemList = TallySheetItems;
}

public PageReference save() {
upsert TallySheetItemList;
return null;
}

public PageReference add() {
TallySheetItemList.add(New Tally_Sheet_Item__c());
return null;
}

}

 

 

 
Please let me where am I going wrong. or Let me know any other way to pass the value from the standardController.outputfiled value to the where condition on the extension controller. ( during the "reset" method is called on the extension controller. )


Look forward to your reply


Thanks

Arif