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
dai tran 6dai tran 6 

Why delete row action not call apex function?

visualforce page:
<apex:form >    
         <apex:pageBlock title="Your Carts:"> 
            
            <apex:pageblockTable value="{!MapProducts}" var="a"> 
                <apex:column >
                    <apex:image width="100" height="100" value="{!URLFOR($Resource.ProductImage, 'ProductImage/' & MapProducts[a]['ImageName__c'])}"></apex:image>
                </apex:column>
                
                <apex:column headerValue="Name" value="{!MapProducts[a]['Name']}"/> 
                <apex:column headerValue="Price" value="{!MapProducts[a]['Price__c']}"/> 
                <apex:column headerValue="Amount" > 
                    <apex:inputText style="text-align:right;width:100px;" value="{!MapProducts[a]['Amount']}"/>
                </apex:column>
                <apex:column headerValue="Money" value="{!MapProducts[a]['Total']}"/> 
                <apex:column >
                    <apex:commandLink action="{!deleteItem}" reRender="MapProducts" ><apex:param assignTo="{!iKey}" value="{!a}" name="assignvalue" /> Remove Row</apex:commandLink>
                </apex:column>
            </apex:pageblockTable>   
          <apex:pageBlock title="Total Money:"> 
             <apex:outputText >{!iTotalMoney}</apex:outputText> 
          </apex:pageBlock>
        </apex:pageBlock> 
   </apex:form>

apex function:
public void deleteItem()
  {
      System.Debug('deleteItem') ;
      iTotalMoney=0;      
      System.Debug(iKey) ;
      MapProducts.remove(iKey);
      for (Integer key : MapProducts.keySet()) {     
        iTotalMoney +=Double.valueOf(MapProducts.get(key).get('Total'));
      }
  }

Log debug output
43.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;NBA,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
03:14:43.0 (94306)|USER_INFO|[EXTERNAL]|0057F000002yTNz|daitb@vnitsolutions.com|Pacific Standard Time|GMT-07:00
03:14:43.0 (138242)|EXECUTION_STARTED
03:14:43.0 (143358)|CODE_UNIT_STARTED|[EXTERNAL]|0667F000009PMhv|VF: /apex/carts
03:14:43.0 (360015)|VF_DESERIALIZE_VIEWSTATE_BEGIN|0667F000009PMhv
03:14:43.0 (7435075)|VF_DESERIALIZE_VIEWSTATE_END
03:14:43.0 (9840462)|SYSTEM_MODE_ENTER|true
03:14:43.0 (14743313)|SYSTEM_MODE_ENTER|true
03:14:43.0 (15488240)|VF_SERIALIZE_VIEWSTATE_BEGIN|0667F000009PMhv
03:14:43.0 (17250235)|VF_SERIALIZE_VIEWSTATE_END
03:14:43.20 (20160362)|CUMULATIVE_LIMIT_USAGE
03:14:43.20 (20160362)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

03:14:43.20 (20160362)|CUMULATIVE_LIMIT_USAGE_END

03:14:43.0 (20198901)|CODE_UNIT_FINISHED|VF: /apex/carts
03:14:43.0 (21042239)|EXECUTION_FINISHED
log not exist text: deleteItem
Why delete row action not call apex function?

Best Answer chosen by dai tran 6
GauravGargGauravGarg
<apex:form id="frm_details">    
         <apex:pageBlock title="Your Carts:"> 
            
            <apex:pageblockTable value="{!MapProducts}" var="a"> 
                <apex:column >
                    <apex:image width="100" height="100" value="{!URLFOR($Resource.ProductImage, 'ProductImage/' & MapProducts[a]['ImageName__c'])}"></apex:image>
                </apex:column>
                
                <apex:column headerValue="Name" value="{!MapProducts[a]['Name']}"/> 
                <apex:column headerValue="Price" value="{!MapProducts[a]['Price__c']}"/> 
                <apex:column headerValue="Amount" > 
                    <apex:inputText style="text-align:right;width:100px;" value="{!MapProducts[a]['Amount']}"/>
                </apex:column>
                <apex:column headerValue="Money" value="{!MapProducts[a]['Total']}"/> 
                <apex:column >
                    <apex:commandLink action="{!deleteItem}" reRender="frm_details"><apex:param assignTo="{!iKey}" value="{!a}" name="assignvalue" /> Remove Row</apex:commandLink>
                </apex:column>
            </apex:pageblockTable>   
          <apex:pageBlock title="Total Money:"> 
             <apex:outputText >{!iTotalMoney}</apex:outputText> 
          </apex:pageBlock>
        </apex:pageBlock> 
   </apex:form>

We need to provide the ID of particular attribute to refresh, I have added form ID and refer the same as reRender value. 

All Answers

GauravGargGauravGarg
Hi Dal,

Please add one more attribute "ID" in <apex:commandLink> and it will work. Like below
 
<apex:commandLink action="{!deleteItem}" reRender="MapProducts" id="cml_Delete" >

Thanks,
Gaurav
Skype: gaurav62990
 
dai tran 6dai tran 6
I had add but it still not work.
GauravGargGauravGarg
you need to reRender to some ID value not MAP. 
Ajay K DubediAjay K Dubedi
Hi Dai,

You need to change your line number 16 to this. Hope it helps you.

<apex:commandLink action="{!deleteItem}" reRender="MapProducts" ><apex:param assignTo="{!iKey}" value="{!a.Id}" name="assignvalue" /> Remove Row</apex:commandLink>

Make sure in your apex class you have to use getter setter method like this.

public String iKey{get;set;}

Please select as best answer if it helps you.

Thank you,
Ajay Dubedi.
dai tran 6dai tran 6
Thank you, It had go to deleteItem function, but it not update after  MapProducts.remove(iKey); (reRender not ok)
  public Map<Integer,  Map<String,String>> MapProducts {get;set;}
  public Double iTotalMoney {get;set;}
  public Integer iKey{get;set;}  
dai tran 6dai tran 6
I had check after deleteItem function, MapProducts had remove item ok.
But reRender not update to web page.
Why?
GauravGargGauravGarg
<apex:form id="frm_details">    
         <apex:pageBlock title="Your Carts:"> 
            
            <apex:pageblockTable value="{!MapProducts}" var="a"> 
                <apex:column >
                    <apex:image width="100" height="100" value="{!URLFOR($Resource.ProductImage, 'ProductImage/' & MapProducts[a]['ImageName__c'])}"></apex:image>
                </apex:column>
                
                <apex:column headerValue="Name" value="{!MapProducts[a]['Name']}"/> 
                <apex:column headerValue="Price" value="{!MapProducts[a]['Price__c']}"/> 
                <apex:column headerValue="Amount" > 
                    <apex:inputText style="text-align:right;width:100px;" value="{!MapProducts[a]['Amount']}"/>
                </apex:column>
                <apex:column headerValue="Money" value="{!MapProducts[a]['Total']}"/> 
                <apex:column >
                    <apex:commandLink action="{!deleteItem}" reRender="frm_details"><apex:param assignTo="{!iKey}" value="{!a}" name="assignvalue" /> Remove Row</apex:commandLink>
                </apex:column>
            </apex:pageblockTable>   
          <apex:pageBlock title="Total Money:"> 
             <apex:outputText >{!iTotalMoney}</apex:outputText> 
          </apex:pageBlock>
        </apex:pageBlock> 
   </apex:form>

We need to provide the ID of particular attribute to refresh, I have added form ID and refer the same as reRender value. 
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Dai,

You need to assign an id to render the particular section.

Please mark as best answer if it helps you.

Thank You,
Ajay Dubedi