Below is my VF page (only imp content given)

<apex:page showheader="false" sidebar="false" standardStylesheets="false" id="page" controller="BAR_ABNCheck_CC" action="{!initDetailPage}">

Save My Details

        <apex:outputPanel id="tempPanel1">                      
            function saveMyDetails(){
                var myJson = $('form').serializeObjectCustom();
                for (var key in myJson) {
                    if (myJson.hasOwnProperty(key)) {                               
                        if (typeof myJson[key] == 'object') {
                            for (var arrayKey in myJson[key]) {
                                if (myJson[key].hasOwnProperty(arrayKey)) {
                                    myJson[key][arrayKey] = replaceBlankValues(myJson[key][arrayKey]);  
                        } else {
                            myJson[key] = replaceBlankValues(myJson[key]);                                    

                var barJson = JSON.stringify(myJson);
                var attachId = **'{!saveDetailId}'**;
                attachFilesToBAR(attachId,false); <!-- javascript method to upload files from page

Below is my Apex controller

public class BAR_ABNCheck_CC {
       public String barJson {get; set;}
       public String saveDetailId {get; set;}

public PageReference saveMyDetails(){
Id recTypeId = BAR_Utilities.getRecordTypeId('Opportunity', 'Enterprise_Business_BAR_EPR');
String accId = ApexPages.currentPage().getParameters().get('accountId') ;
String oppId = ApexPages.currentPage().getParameters().get('oppId');
List<Opportunity> incompleteOpps = [Select Id, BAR_isDetailsPageCompleted__c, BAR_ApplicationStatus__c 
                                    From Opportunity 
                                    Where Account.Id = :accId AND RecordTypeId =: recTypeId 
                                                              AND OwnerId =: UserInfo.getUserId() 
                                                              AND (BAR_ApplicationStatus__c != 'Completed' OR BAR_ApplicationStatus__c != '')];
System.debug('incompleteOpps '+incompleteOpps);                                                              
String OpportunityId;      
    //try {            
        if(String.isBlank(accId)) {
            Opportunity opp = [Select Id, Account.Id From Opportunity Where Id = :oppId];
            accId = opp.Account.Id;
            //throw new BAR_DetailsFormException('Account Id should not be null.');
        System.debug('barJson: ' +barJson);  
        BAR_FormWrapper form = BAR_FormWrapper.parse(barJson);

        Account acc = [Select id, Name, Dealer_Code__c, BAR_Account_PIN_code__c, BillingState, BillingStreet, BillingPostalCode, BillingCity, BillingCountry, BAR_Address_for_Email_Bill__c, TradingStartDate__c, BAR_Registered_Date__c
                                                                        From Account Where Id = :accId];
        if(incompleteOpps.isEmpty() && String.isBlank(oppId)){
            OpportunityId = updateOpportunityDetails(form, acc, null, false, recTypeId) ;
            OpportunityId = updateOpportunityDetails(form, acc, oppId, false, recTypeId) ;

        // update billing details
        updateAccountDetails(form, acc);
    //} catch (Exception e){
        //return BAR_GlobalConstants.errorMsgPrefix + e.getMessage() +' '+ e.getStackTraceString();
    **saveDetailId = OpportunityId;
    //PageReference pr = new PageReference('/'+OpportunityId);
    //return pr;  
    return null;  

I am getting value of 'saveDetailId ' in debug log but alert in javascript is blank


You will get the update value on complete of your action function,

<apex:actionfunction name="saveDetailsfunction" action="{!saveMyDetails}" oncomplete="alert('{!saveDetailId}')"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.