You need to sign in to do that
Don't have an account?
problem in updating records using command button
Product Approval
| Product : | 0-234032-02 |
| Product : | 0-230057-01 |
Here, im using a wrapper class to display the list of products from the opportunity and using a checkbox when the user selects the products and clicks "approve" button i update a field with the value "Approved" in the product record.
The problem im facing here is, when i select all the products and click "approve" the update works. And for the first time if i select one product of the two products and click "approve", the update works. But the next time if i select the other product and click "approve" the button is not getting fired. While the second time i click the same "approve" consecutively it works. Im not able to figure out whats the reason for this behaviour.
Please suggest what to do.
Code:
public class cls_Approve
{
public cls_Approve(ApexPages.StandardController controller)
{
opp = (opportunity)controller.getRecord();
oppLineItem = [Select PricebookEntry.Product2.id,PricebookEntry.Product2.name , PricebookEntry.Product2.HD_Product_Approval__c from OpportunityLineItem where OpportunityId =: opp.id];
}
public class wrapProduct
{
public boolean chkProduct{get;set;}
public string wrapLineItemName{get;set;}
public string wrapLineItemId{get;set;}
public Opportunity wrapOpp{get;set;}
public wrapProduct(Opportunity op)
{
wrapOpp = op;
}
}
public List<wrapProduct> getwrapProdList()
{
queryResults = new List<wrapProduct>();
for(opportunityLineItem oli : oppLineItem)
{
wrapProduct wpObj = new wrapProduct(opp);
if(oli.PricebookEntry.Product2.name != null)
{
wpObj.wrapLineItemName = oli.PricebookEntry.Product2.name;
}
wpObj.wrapLineItemId = oli.PricebookEntry.Product2.id;
queryResults.add(wpObj);
}
return queryResults;
}
public List<string> updateProdId = new List<string>();
public List<product2> updateProd2 = new List<product2>();
public List<product2> pList = new List<product2>();
public pagereference approveProduct()
{
for(wrapProduct wpList:queryResults)
{
if(wpList.chkProduct == true)
{
updateProdId.add(wpList.wrapLineItemId);
}
}
if(updateProdId.size() >0)
{
pList = [select HD_Product_Approval__c from product2 where id in: updateProdId];
}
for(product2 p2:pList)
{
p2.HD_Product_Approval__c = 'Approved';
updateProd2.add(p2);
}
update updateProd2;
return null;
}
}
VisualForce Page:
--------------------------
<apex:page id="Page1" standardController="opportunity" extensions="cls_Approve">
<apex:form id="form1">
<b>Product Approval</b>
<apex:repeat value="{!wrapProdList}" var="oli">
<table border='1'>
<tr>
<td align="center">
<apex:inputCheckbox id="chkProd" value="{!oli.chkProduct}" disabled="{!oli.disableChkProduct}"/>
</td>
<td align="center">
<b> Product : </b>
</td>
<td>
<apex:outputText value="{!oli.wrapLineItemName}"/>
</td>
</tr>
</table>
</apex:repeat>
<apex:commandButton value="approve" action="{!approveProduct}" rerender="table1" disabled="{!fnProdApprove}"/>
</apex:form>
</apex:page>
What is your reRender attribute referring to? I don't see a Visualforce component with an id="table1" anywhere on your page. Maybe fixing your reRender attribute would be a good start.
Also, if you're working on an internal VF page or a portal VF page, then try using an apex:pageBlockTable or an apex:dataTable instead of apex:repeat.
Thanks , but the problem was due to the disabled property that i had added in the command button . Its workin fine now...