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
pdopdo 

Junction Object Class

Hey All,

I am having trouble with the below class and am hoping to get some help.  I have a Junction Object that is connecting two custom Objects, Order__c and Product_Bundle__c and I am creating a Visualforce Page that will allow the User to create the Junction Objects by adding Quantity to the records and saving the page.  The class is designed to:

1.  Query the Product_Bundle__c Custom Object for available Product Bundles and assocate them behind the scenes with the current Order__c

2.  Display them on a VF page with the inputField Quantity__c exposed

3.  If the User enters a quantity and clicks "Save", the system will create those Junction  Objects associating the Product Bundles to the Order

 

I cannot seem to get my PageBlockTable to use the list in my Controller:

ErrorError: Unknown property 'Order_Item_Junction__cStandardController.lstoitem'

 

Any help on the below code would be great!

 

Class

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem = new List<Order_Item_Junction__c>();
    public string orderid;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        string flag = '';
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        //Use this variable to test the code coverage of try-catch block within constructor and set to 'true'
        String calledFromTestClass = ApexPages.currentPage().getparameters().get('calledFromTestClass');
        
            if(orecordtype == 'New Order')
            {            
                flag = 'new';
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                flag = 'return';
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        List<Order_Item_Junction__c> lstoitem = new List<Order_Item_Junction__c>();
        
        if(calledFromTestClass == 'true') {
            lstoitem = null;
        }
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = orderid;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 Page

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script type="text/javascript">
function refreshparent()
{
    window.opener.location.reload();
    window.close();
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton status="processingimg" value="Save" action="{!save}" rerender="order" oncomplete="refreshparent()" />
                <apex:commandButton onclick="javascript&colon;window.close();" value="Cancel" />
                <apex:actionstatus id="processingimg" >
                    <apex:facet name="start">
                        <apex:image id="theImage" value="{!$Resource.ProcessingImage}" />
                    </apex:facet>
                </apex:actionstatus>
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="80%"/>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton status="processingimg" value="Save" action="{!save}" rerender="order" oncomplete="refreshparent()"/>
                <apex:commandButton onclick="javascript&colon;window.close();" value="Cancel" />
                <apex:actionstatus id="processingimg1" >
                    <apex:facet name="start">
                        <apex:image id="theImage1" value="{!$Resource.ProcessingImage}" />
                    </apex:facet>
                </apex:actionstatus>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
pdopdo

Hey Bob,

Figured it all out.  Below is my final code.  Thanks for all your help!

 

Class:

// Class           : oitemController
// Description     : Controls the list of order items to be updated per order 
//                   
// Author          : Patrick Dostal
// Created Date    : 20120106

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem {get;set;}
    public ID<Order__c> oid {get;set;}
    public string orderid;
    public integer iqty;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public PageReference saveitems()
    {
        //Save item relationships
        List<Order_Item_Junction__c> insitems = new List<Order_Item_Junction__c>();
        try{
            for(integer i=0;i<lstoitem.size();i++)
                {
                if(lstoitem[i].Quantity__c > 0)
                    {
                    Order_Item_Junction__c qtyitem = new Order_Item_Junction__c();
                    qtyitem.Order__c = oid;
                    qtyitem.Product_Bundle__c = lstbundle[i].Id;
                    qtyitem.Quantity__c = lstoitem[i].Quantity__c;
                    insitems.add(qtyitem);
                    }
                }
            if(insitems.size()>0)
                insert insitems;
        }catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
        return null; 
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        string flag = '';
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        //Use this variable to test the code coverage of try-catch block within constructor and set to 'true'
        String calledFromTestClass = ApexPages.currentPage().getparameters().get('calledFromTestClass');
        
            if(orecordtype == 'New Order')
            {            
                flag = 'new';
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                flag = 'return';
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        lstoitem = new List<Order_Item_Junction__c>();
        oid = orderid;
        
        if(calledFromTestClass == 'true') {
            lstoitem = null;
        }
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = oid;
            oitem.Quantity__c = 0;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 

 

Page:

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script language="JavaScript" type="text/javascript">
function CloseAndRefresh()
{
    window.opener.location.href="/{!$CurrentPage.parameters.oid}";
    window.top.close();
      
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headerValue="Order" value="{!l.Order__c}" width="40%"/>
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="40%"/>
                        <apex:column headerValue="Quantity" id="iqty" width="20%">
                            <apex:inputField value="{!l.Quantity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

All Answers

bob_buzzardbob_buzzard

In order to use the list on the page it needs to be a controller property, which is defined as public and has a public getter and setter.  You don't appear to have the getter and setter part of this.  You'll need to change:

 

 public List<Order_Item_Junction__c> lstoitem = new List<Order_Item_Junction__c>();

To:

 public List<Order_Item_Junction__c> lstoitem {get; set;}

 and then initialise it in your constructor:

 

lstoitem = new List<Order_Item_Junction__c>();

 

 

pdopdo

Bob!  So simple...thanks for the extra eyes.  I have updated it but now cannot get my related Order to pull in and when I try to save the records from the page, it does not save.  Any more pointers?

 

Class

// Class           : oitemController
// Description     : Controls the list of order items to be updated per order 
//                   
// Author          : Patrick Dostal
// Created Date    : 20120106

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem {get;set;}
    public ID<Order__c> oid {get;set;}
    public string orderid;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        string flag = '';
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        //Use this variable to test the code coverage of try-catch block within constructor and set to 'true'
        String calledFromTestClass = ApexPages.currentPage().getparameters().get('calledFromTestClass');
        
            if(orecordtype == 'New Order')
            {            
                flag = 'new';
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                flag = 'return';
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        lstoitem = new List<Order_Item_Junction__c>();
        oid = orderid;
        
        if(calledFromTestClass == 'true') {
            lstoitem = null;
        }
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = oid;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 Page

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script type="text/javascript">
function refreshparent()
{
    window.opener.location.reload();
    window.close();
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton status="processingimg" value="Save" action="{!save}" rerender="order" oncomplete="refreshparent()" />
                <apex:commandButton value="Cancel" action="{!cancel}" />
                <apex:actionstatus id="processingimg" >
                    <apex:facet name="start">
                        <apex:image id="theImage" value="{!$Resource.ProcessingImage}" />
                    </apex:facet>
                </apex:actionstatus>
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headerValue="Order" value="{!l.Order__c}" width="40%"/>
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="40%"/>
                        <apex:column headerValue="Quantity" width="20%">
                            <apex:inputField value="{!l.Quantity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton status="processingimg" value="Save" action="{!save}" rerender="order" oncomplete="refreshparent()"/>
                <apex:commandButton onclick="javascript&colon;window.close();" value="Cancel" />
                <apex:actionstatus id="processingimg1" >
                    <apex:facet name="start">
                        <apex:image id="theImage1" value="{!$Resource.ProcessingImage}" />
                    </apex:facet>
                </apex:actionstatus>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

bob_buzzardbob_buzzard

As you are using the standard controller save method, that will save the single junction object being identified through the id parameter - is that the behaviour that you are looking for?

pdopdo

No, looking to save the list of items that have quantity filled in.

bob_buzzardbob_buzzard

In that case you'll need to override the save method in your extension controller and iterate the list, saving each element that you need to.

pdopdo

Hi Bob,

So I have been trying to take a swing at doing this and I cannot get my code to fire.  Can you take a look and help me out?

 

Class

// Class           : oitemController
// Description     : Controls the list of order items to be updated per order 
//                   
// Author          : Patrick Dostal
// Created Date    : 20120106

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem {get;set;}
    public ID<Order__c> oid {get;set;}
    public string orderid;
    public integer iqty;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public PageReference saveitems()
    {
        //Save item relationships
        List<Order_Item_Junction__c> insitems = new List<Order_Item_Junction__c>();
        try{
            for(integer i=0;i<lstoitem.size();i++)
            {
            Order_Item_Junction__c qtyitem = new Order_Item_Junction__c();
            qtyitem.Order__c = oid;
            qtyitem.Product_Bundle__c = lstbundle[i].Id;
            qtyitem.Quantity__c = iqty;
            insitems.add(qtyitem);
            }
            if(insitems.size()>0)
                insert insitems;
        }catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
        return null; 
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        string flag = '';
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        //Use this variable to test the code coverage of try-catch block within constructor and set to 'true'
        String calledFromTestClass = ApexPages.currentPage().getparameters().get('calledFromTestClass');
        
            if(orecordtype == 'New Order')
            {            
                flag = 'new';
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                flag = 'return';
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        lstoitem = new List<Order_Item_Junction__c>();
        oid = orderid;
        
        if(calledFromTestClass == 'true') {
            lstoitem = null;
        }
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = oid;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 Page

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script type="text/javascript">
function refreshparent()
{
    window.opener.location.reload();
    window.close();
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!saveitems}" rerender="order" oncomplete="refreshparent()" />
                <apex:commandButton value="Cancel" action="{!cancel}" />
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headerValue="Order" value="{!l.Order__c}" width="40%"/>
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="40%"/>
                        <apex:column headerValue="Quantity" id="iqty" width="20%">
                            <apex:inputField value="{!l.Quantity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!saveitems}" rerender="order" oncomplete="refreshparent()"/>
                <apex:commandButton action="{!cancel}" value="Cancel" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

pdopdo

Hey Bob,

Figured it all out.  Below is my final code.  Thanks for all your help!

 

Class:

// Class           : oitemController
// Description     : Controls the list of order items to be updated per order 
//                   
// Author          : Patrick Dostal
// Created Date    : 20120106

public class oitemController
{
    public List<Product_Bundle__c> lstbundle = new List<Product_Bundle__c>();
    public List<Order_Item_Junction__c> lstoitem {get;set;}
    public ID<Order__c> oid {get;set;}
    public string orderid;
    public integer iqty;
    public boolean proceed {get;set;}
    
    public boolean setproceed()
    {
        return true;
    }
    
    public PageReference saveitems()
    {
        //Save item relationships
        List<Order_Item_Junction__c> insitems = new List<Order_Item_Junction__c>();
        try{
            for(integer i=0;i<lstoitem.size();i++)
                {
                if(lstoitem[i].Quantity__c > 0)
                    {
                    Order_Item_Junction__c qtyitem = new Order_Item_Junction__c();
                    qtyitem.Order__c = oid;
                    qtyitem.Product_Bundle__c = lstbundle[i].Id;
                    qtyitem.Quantity__c = lstoitem[i].Quantity__c;
                    insitems.add(qtyitem);
                    }
                }
            if(insitems.size()>0)
                insert insitems;
        }catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
        return null; 
    }
    
    public oitemController(ApexPages.StandardController controller)
    {
        string flag = '';
        //Order ID
        orderid = ApexPages.currentPage().getparameters().get('oid');
        //Record Type
        string orecordtype = ApexPages.currentPage().getparameters().get('rectype');
        //Use this variable to test the code coverage of try-catch block within constructor and set to 'true'
        String calledFromTestClass = ApexPages.currentPage().getparameters().get('calledFromTestClass');
        
            if(orecordtype == 'New Order')
            {            
                flag = 'new';
                //Fetch all Product Bundles where Order_Availability__c = New Order
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'New Order' and Completed__c =: TRUE order by Name];
            }
            else if(orecordtype == 'Return Order')
            {
                flag = 'return';
                //Fetch all Product Bundles where Order_Availability__c = Return Oder
                lstbundle = [Select Order_Availability__c, Name, Id From Product_Bundle__c where Order_Availability__c =:'Return Order' and Completed__c =: TRUE order by Name];
            }
        
        lstoitem = new List<Order_Item_Junction__c>();
        oid = orderid;
        
        if(calledFromTestClass == 'true') {
            lstoitem = null;
        }
        
        try{
        for(integer i=0;i<lstbundle.size();i++)
        {
            Order_Item_Junction__c oitem = new Order_Item_Junction__c();
            oitem.Product_Bundle__c = lstbundle[i].Id;
            oitem.Order__c = oid;
            oitem.Quantity__c = 0;
            lstoitem.add(oitem);
            
        }
        }catch(Exception ex){
            // Adding exeption message onto the page
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error:'+ ex.getMessage()));
            System.debug(ex.getMessage());
        }
    }   
}

 

 

Page:

<apex:page id="orderpage1" standardController="Order_Item_Junction__c" extensions="oitemController" sidebar="false" showheader="false" >
<script language="JavaScript" type="text/javascript">
function CloseAndRefresh()
{
    window.opener.location.href="/{!$CurrentPage.parameters.oid}";
    window.top.close();
      
}
</script>
    <apex:form id="form1">
        <apex:pageBlock title="Add Order Items" id="order">
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
                <apex:pageBlockSection id="pbsbundle" title="Available Product Bundles" rendered="true" columns="1">
                    <apex:pageBlockTable id="pbtbundles" value="{!lstoitem}" var="l" width="100%">
                        <apex:column headerValue="Order" value="{!l.Order__c}" width="40%"/>
                        <apex:column headervalue="Product Bundle Name" value="{!l.Product_Bundle__c}" width="40%"/>
                        <apex:column headerValue="Quantity" id="iqty" width="20%">
                            <apex:inputField value="{!l.Quantity__c}"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!saveitems}" oncomplete="CloseAndRefresh()" />
                <apex:commandButton value="Cancel" onclick="CloseAndRefresh()" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

This was selected as the best answer
bob_buzzardbob_buzzard

Glad to hear you got there.

haripopuri1haripopuri1

Thanks for response.

 

You are using data table and your code works fine for that case.

 

I have a form with input fields and related list at the bottom. I am opening a popup window for adding/editing related item (visual force page). After adding/editing the related list, I just want to refresh the related list section on the main window.

 

I tried using the oncomplete="refreshandclose()", but that is not waiting if there is any error in popup form. i.e., Required field not entered. Its just closing the popup window and reloading the main window. Reloading the main window also causes another problem i.e., if I have any unfinished changed, those are gone.

 

Thanks

 

spatelcespatelce

I am really thankful to you for posting such a great solution. It helped me totally while I was working with nearly equal to your scenario with two junction objects. 

 

Now, I am stuck as test class with one line only and that is:

if(calledFromTestClass == 'true') {
   lstSEndorsers = null; //List variable, displays records on VF Page
}

 

How can I make this condition true in my Test Class. It shows that if statement is covered during test, but condition is not 'true' so it doesn't cover "lstSEndorsers = null". If I can cover this line then I can get my code coverage for 100%.

 

Your help will be really appreciated.

kevin_carkevin_car

Hi spatelce

 

Well, I hope this answers your question-

 

Typically in some cases you have you "fudge" between controllers and test classes -- the most typical case is with HTTP callouts.

 

If you have to artificially manipulate a test contition between controller and test, it's easiest to  have test class set your controller variable and be done with it.

 

For instance, 

 

 

public class MyController {

    public Boolean calledFromTestClass;

 

    MyController () {

          calledFromTestClass = false;

          }

 

     setIsTest(Boolean val) {

          calledFromTestClass = val;

          }

    }

 

@isTest

Test.StartTest();

[---]

MyController mc = new MyController();
mc.setistest(true);

[---]

 

 

Hope this helps,