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
Ketan Solanki29Ketan Solanki29 

Apex class updated object field value not reflected in another apex class

Hi Team,

I am facing issue in Apex class. i have one class where i am updating custom Quote object field and then i am passing Object Id to other class where i quering recoid using ID but i am not getting updated value its retriving old value.

Can anybody tell, what causes this issue ?? why updated value not reflected in another apex class ??

Thanks in Advance,

 
kalpeshs91kalpeshs91
Check Private/Public declaration. If it is fine then paste block of code here to get clear idea of issue.
Ketan Solanki29Ketan Solanki29
For Example my current Quote Email_Template_Body__c = '<h1> THIS IS KETAN SOLANKI</h1>'

public class GenerateQuote{

        public generateQuotePDF(){
        
            String editedEmailTemplateHtmlText = '<h1> Hi This Is Testing Line 00001</h1>'; 
                
            quote.Email_Template_Body__c = templateOutputHtml;
                               
            UPDATE quote; 

            system.debug('=======GenerateQuote================>>'+quote.Email_Template_Body__c);             
                    
            PageReference pdf = Page.PdfGenerator;
            
            pdf.getParameters().put('quoteId', quote.Id );              
            
            Blob pdfBody = pdf.getContent();
                        
        
        }
        
}


public class PdfGeneratorCont{

        public PdfGeneratorCont (){
                
             String templateOutputHtml;  
                                
             String quoteId = ApexPages.CurrentPage().getParameters().get('quoteId');                     
        
             Quote__c quote = [ SELECT Id,Name,Email_Template_Body__c FROM Quote__c WHERE Id =: quoteId ];     
                
             templateOutputHtml = quote.Email_Template_Body__c; 
                                 
             system.debug('=======PDF GENERATOR OUTPUT================>>'+templateOutputHtml); 
        
        }
        
}

After execution of code i am getting diffrent out put like below :

=======GenerateQuote================>><h1> Hi This Is Testing Line 00001</h1>
=======PDF GENERATOR OUTPUT================>><h1> THIS IS KETAN SOLANKI</h1>

Why my PdfGeneratorCont fetching old value from Quote object ???

Thanks,
Ketan Solanki
kalpeshs91kalpeshs91
I guess your quote is not updating in 1st class. Put try catch for 'update quote' to check the error.
Ketan Solanki29Ketan Solanki29
Kalpesh i am getting updated values in below statement in Debug Log

system.debug('=======GenerateQuote================>>'+quote.Email_Template_Body__c);       

Output :

=======GenerateQuote================>><h1> Hi This Is Testing Line 00001</h1> 
Ketan Solanki29Ketan Solanki29
Hey Kalpesh. i am using Apex from last 5 years. i have already checked code and it showing result in debug log if exception is raise then code will not executed and it will show exception. So here no need to write try catch block.