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
Jeremy DeseezJeremy Deseez 

Can't update a line in PageBlockTable

Hi, I make a pageBlockTable of ForecastingQuota, but when I save it, nothing happen, my QuotaAmount want to be saved.
 VFP Code :
<apex:pageMessages />
	<apex:pageBlock title="All ForecastingQuotas" id="forecast_list" mode="inlineEdit" >
	<apex:PageBlockButtons >
	    <apex:commandButton action="{!save1}" value="save"/>
	</apex:PageBlockButtons>
            <apex:pageBlockTable value="{!loadquotas}" var="qs" id="aforecastlist">
            	<apex:column headerValue="Id">
            	<apex:outputField value="{!qs.Id}"/>
            	</apex:column>
            	<apex:column headerValue="QuotaAmount">
                <apex:outputField value="{!qs.QuotaAmount }"/>
				</apex:column>
                <apex:column headerValue="QuotaOwnerId">
                <apex:outputField value="{!qs.QuotaOwnerId}"/>
				</apex:column>
                <apex:column headerValue="StartDate">
                <apex:outputField value="{!qs.StartDate}"/>
				</apex:column>
                <apex:column headerValue="ForecastingTypeId">
                <apex:outputField value="{!qs.ForecastingTypeId}"/>
				</apex:column>
                <apex:column headerValue="IsAmount">
                <apex:outputField value="{!qs.IsAmount}"/>
				</apex:column>
                <apex:column headerValue="ProductFamily">
                <apex:outputField value="{!qs.ProductFamily}"/>
				</apex:column>
                <apex:column headerValue="QuotaQuantity">
                <apex:outputField value="{!qs.QuotaQuantity}"/>
				</apex:column>
                <apex:column headerValue="PeriodId">
				<apex:outputField value="{!qs.PeriodId}"/>
				</apex:column>
		 		
				<!-- <apex:inlineEditSupport event="ondblClick"/> -->
			</apex:pageBlockTable>
	</apex:pageBlock>

Apex :
public List<ForecastingQuota> getLoadQuotas() {
		    List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota ORDER BY QuotaAmount DESC];
		    return resultsquotas;
		}

public void save1() {
	    	List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota];
		    
     		update resultsquotas;
     		System.debug(resultsquotas);
		}
Thanks for your help
 
Dilip_VDilip_V
Jeremy,

You can't actually update data using page block table.It is used to display data in a tabuler fashion.

And clearly we use apex:outputField for displaying values(QuotaAmount) in page block table.To save input values we have to use apex:inputField.

Mark it as solved if it helps.
Thanks.
Jeremy DeseezJeremy Deseez
Hi, Si i have to change the outputfield into inputfield in the page Block ? Or i have to make an other section with inputfield ? Regards
Dilip_VDilip_V
Jeremy,

It would be better to modify existing one like this.

Try this page.
<apex:pageMessages />
	<apex:pageBlock title="All ForecastingQuotas" id="forecast_list" mode="inlineEdit" >
	<apex:PageBlockButtons >
	    <apex:commandButton action="{!save1}" value="save"/>
	</apex:PageBlockButtons>
            <apex:pageBlockTable value="{!loadquotas}" var="qs" id="aforecastlist">
            	<apex:column headerValue="Id">
            	<apex:outputField value="{!qs.Id}"/>
            	</apex:column>
            	<apex:column headerValue="Industry">
                <apex:inputField value="{!qs.QuotaAmount}"/>
                </apex:column>
                <apex:column headerValue="QuotaOwnerId">
                <apex:outputField value="{!qs.QuotaOwnerId}"/>
				</apex:column>
                <apex:column headerValue="StartDate">
                <apex:outputField value="{!qs.StartDate}"/>
				</apex:column>
                <apex:column headerValue="ForecastingTypeId">
                <apex:outputField value="{!qs.ForecastingTypeId}"/>
				</apex:column>
                <apex:column headerValue="IsAmount">
                <apex:outputField value="{!qs.IsAmount}"/>
				</apex:column>
                <apex:column headerValue="ProductFamily">
                <apex:outputField value="{!qs.ProductFamily}"/>
				</apex:column>
                <apex:column headerValue="QuotaQuantity">
                <apex:outputField value="{!qs.QuotaQuantity}"/>
				</apex:column>
                <apex:column headerValue="PeriodId">
				<apex:outputField value="{!qs.PeriodId}"/>
				</apex:column>
		 		
				<!-- <apex:inlineEditSupport event="ondblClick"/> -->
			</apex:pageBlockTable>
	</apex:pageBlock>
for more info:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_iteration_components_editing.htm
Let me know if you have any issues.

Mark it as best answer if it works.

Thanks.
Jeremy DeseezJeremy Deseez
I have change it on "inputField" but when I save it nothing happens Regards *Jérémy Deseez* Information System Specialist - Salesforce Developer | *Kyriba* 247 Bureaux de la Colline 92210 ST-Cloud - France www.kyriba.com | Twitter | LinkedIn | Blog
Dilip_VDilip_V
Jeremy,

Are you able to edit the field now?

Please share controller 


Thanks.
Jeremy DeseezJeremy Deseez
There is my controller 
 
public with sharing class QuoteTabController {

public Decimal QuotaAmount{get;set;}
public String QuotaOwnerId{get;set;}
public Date StartDate{get;set;}
public String forecastId {get; set;}
public String forecastOwnerId {get; set;}
public String forId{get;set;}
public List<ForecastingQuota> forecastList{get;set;}
public List<ForecastingQuota> resultsquotas{get;set;}
public List<ForecastingQuota> updatequotas{get;set;}
public List<ForecastingQuota> deleteforecast{get;set;}
public List<ForecastingQuota> forecastupdated{get;set;}
public boolean editSection {get;set;}
public Integer rowIndex{get;set;}
public List<User> accountList{get;set;}
public ForecastingQuota del;
public ForecastingQuota forcast {get; set;}
public Integer forecastQuotaAmount {get; set;}
public String message{get;set;}

    public QuoteTabController(ApexPages.StandardController controller) {
    
    forcast = (ForecastingQuota) controller.getRecord();
    }

 


	    public List<ForecastingQuota> getLoadQuotas() {
		    List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota ORDER BY QuotaAmount DESC];
		    return resultsquotas;
		}




	    public void save1() {
	    	List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota];
		    
     		upsert resultsquotas;
     		System.debug(resultsquotas);
		}

	    public void UpdateLine()
		{
			ForecastingQuota forecastupdated = [SELECT CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota WHERE QuotaAmount=:forecastQuotaAmount];
			try{
				upsert forecastupdated;
			}
			catch(Exception e){
            message='Data Base error during saving...';
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, message));
            
        }
			
			
		}

		public void DeleteLine(){
			List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota ORDER BY QuotaAmount DESC];
			
	  		if(forecastId == null){
	  			return;
	  		}

	  		ForecastingQuota tobeDeleted = null;
	  		for(ForecastingQuota f : resultsquotas)
	  			if(f.Id == forecastId){
	  				tobeDeleted = f;
	  				break;
	  			}

	  			if(tobeDeleted != null){
	  				delete(tobeDeleted);
	  			}
	  			 getLoadQuotas();






		}      
        
}

Thanks
Dilip_VDilip_V
try this controller.
public with sharing class QuoteTabController {

public Decimal QuotaAmount{get;set;}
public String QuotaOwnerId{get;set;}
public Date StartDate{get;set;}
public String forecastId {get; set;}
public String forecastOwnerId {get; set;}
public String forId{get;set;}
public List<ForecastingQuota> forecastList{get;set;}
public List<ForecastingQuota> resultsquotas{get;set;}
public List<ForecastingQuota> updatequotas{get;set;}
public List<ForecastingQuota> deleteforecast{get;set;}
public List<ForecastingQuota> forecastupdated{get;set;}
public boolean editSection {get;set;}
public Integer rowIndex{get;set;}
public List<User> accountList{get;set;}
public ForecastingQuota del;
public ForecastingQuota forcast {get; set;}
public Integer forecastQuotaAmount {get; set;}
public String message{get;set;}

    public QuoteTabController(ApexPages.StandardController controller) {
    
    forcast = (ForecastingQuota) controller.getRecord();
    }

 


	    public List<ForecastingQuota> getLoadQuotas() {
		    List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota ORDER BY QuotaAmount DESC];
		    return resultsquotas;
		}




	    public void save1() {
	    	List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota];
		    
     		upsert resultsquotas;
     		System.debug(resultsquotas);
update loadquotas;
		}

	    public void UpdateLine()
		{
			ForecastingQuota forecastupdated = [SELECT CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota WHERE QuotaAmount=:forecastQuotaAmount];
			try{
				upsert forecastupdated;
			}
			catch(Exception e){
            message='Data Base error during saving...';
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, message));
            
        }
			
			
		}

		public void DeleteLine(){
			List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
		    resultsquotas = [SELECT Id,CurrencyIsoCode, ForecastingTypeId, IsAmount, IsQuantity, PeriodId,ProductFamily,QuotaAmount,StartDate,QuotaQuantity,QuotaOwnerId FROM ForecastingQuota ORDER BY QuotaAmount DESC];
			
	  		if(forecastId == null){
	  			return;
	  		}

	  		ForecastingQuota tobeDeleted = null;
	  		for(ForecastingQuota f : resultsquotas)
	  			if(f.Id == forecastId){
	  				tobeDeleted = f;
	  				break;
	  			}

	  			if(tobeDeleted != null){
	  				delete(tobeDeleted);
	  			}
	  			 getLoadQuotas();






		}      
        
}
Let me know if you have any issues.

Mark it as best answer if it works.

Thanks.