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
ckumckum 

Unable to call actionFunction 'action' .

Hi,

 

I am facing an issue with the action function. In my Page I have an actionFunction mentioned below:

 

<apex:actionFunction name="SAVEALL" action="{!saveAll}" rerender="OPquoteEdit" status="statusProductAll"/>

 Now in one of the javascript function I have called SAVEALL(); . Once it is called it uses the status message but donot go to the function in controller 'saveAll'. I have a system debug in the first line of the function but it is not reaching that line. Kindly help how can I call my actionFunction's action i.e.; 'saveAll' function in controller.

 

public PageReference saveAll()

{

System.debug('starttttttttttttttttttttttttttt');

if(INFW_SaveQuoLineItems)

{

System.debug('*****INFW_SaveQuoLineItems TRUE *****');

INFW_quoteId = System.currentPageReference().getParameters().get('quoteId');

PageReference pr = new PageReference('/'+INFW_quoteId);

pr.setRedirect(true);

return pr;

}

else

{

QuoteLineItems();

return null;

}

System.debug('finishhhhhhhhhhhhhhhhhhhhhhhh');

return null;

}

 

Thanks

ckum

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

I can't see the code that calls your actionFunction, but here's a few tips:

 

CommandButtons should be used for calling action methods and I think that the command button is try to perform some default functionality that is interferring with your call. Try moving this call to the oncomplete event handler:

 

<apex:commandButton value="Save All" onclick oncomplete="javascript&colon;return Message4Going2QuoteDetailPage('saveall');" rerender="opdummy"/>

 Now this will run after the commandbutton does whatever else it thinks it needs to do. 

To use this actionFunction it needs to be called like this:

 

<apex:commandButton value="Do Something" action="{!doSomething}" oncomplete="SAVEITEMS();" />

<apex:actionFunction name="SAVEITEMS" action="{!saveAll}" rerender="OPquoteEdit" status="statusProductAll"/> 

 

Does this help?

 

Wes 

All Answers

WesNolte__cWesNolte__c

Hey

 

Does you actionStatus 'statusProductAll' start up at all? Can you post the visualforce code please?

 

Wes 

ckumckum

Yes My Status is working properly. It comes and it goes but actionFunction does not work at all.

Cant send the full code as it is the big one. Just sending few more lines related to same code

 

<apex:commandButton value="Save All" onclick="javascript:return Message4Going2QuoteDetailPage('saveall');" rerender="opdummy"/>

<apex:actionFunction name="SAVEITEMS" action="{!saveAll}" rerender="OPquoteEdit" status="statusProductAll"/>

<script language="Javascript">

 

 

 

 

function Message4Going2QuoteDetailPage(saveinfo)

{

var QuoId = "{!INFW_quoteId}";

if(saveLineItems == 'true')

{

var inputId = globalInputId;

var inputarr = inputId.split(":");

var inputIndex;

for(var i = 0; i < inputarr.length; i++)

{

if(!isNaN(inputarr[i]))

{

inputIndex = inputarr[i];

break;

}

}

var firststr = inputId.substr(0, inputId.indexOf(':'+inputIndex));

var laststr = inputId.substr(firststr.length+inputIndex.length+1, inputId.indexOf('txtQuantity'));

laststr = laststr.substr(0, laststr.length-11);

 

sforce.connection.sessionId = sId;

 

if(saveinfo == 'saveall')

{

callSave(firststr, laststr, inputIndex);

alert("Call Next Func");

if(SAVEITEMS())

alert("YESSS ");

}

return false;

}

 

function callSave(firststr, laststr, inputIndex)

{

var arrQuoteLines = new Array();

for(var i = 0; i <= inputIndex; i++)

{

var objQuoteLine = new sforce.SObject("INFW_QuoteLine__c");

objQuoteLine.Id = document.getElementById(firststr+':'+i+laststr+'hidProLineId').value;

if(document.getElementById(firststr+':'+i+laststr+'txtQuantity').value != null && document.getElementById(firststr+':'+i+laststr+'txtQuantity').value != '')

{

objQuoteLine.Quantity__c = getFloatValue(document.getElementById(firststr+':'+i+laststr+'txtQuantity').value);

}

if(document.getElementById(firststr+':'+i+laststr+'txtlistPrice').value != null && document.getElementById(firststr+':'+i+laststr+'txtlistPrice').value != '')

{

objQuoteLine.Unit_List_Price__c =getFloatValue(document.getElementById(firststr+':'+i+laststr+'txtlistPrice').value).toFixed(2);

}

if(document.getElementById(firststr+':'+i+laststr+'txtDiscount').value != null && document.getElementById(firststr+':'+i+laststr+'txtDiscount').value != '')

{

objQuoteLine.Discount__c =getFloatValue(document.getElementById(firststr+':'+i+laststr+'txtDiscount').value).toFixed(5);

}

/* if(document.getElementById(firststr+':'+i+laststr+'txtSalesPrice').value != null && document.getElementById(firststr+':'+i+laststr+'txtSalesPrice').value != '')

{

objQuoteLine.Unit_Sales_Price__c =getFloatValue(document.getElementById(firststr+':'+i+laststr+'txtSalesPrice').value).toFixed(2);

}*/

if(document.getElementById(firststr+':'+i+laststr+'txtWarrantyDate').value != '' && document.getElementById(firststr+':'+i+laststr+'txtWarrantyDate').value != null)

{

var objRenewalValue = document.getElementById(firststr+':'+i+laststr+'txtWarrantyDate').value;

var dateArr = objRenewalValue.split("/");

objQuoteLine.Renewal_Date__c = new Date(dateArr[2], (dateArr[0] - 1), dateArr[1]);

}

if(document.getElementById(firststr+':'+i+laststr+'txtExtendedPrice').value != null && document.getElementById(firststr+':'+i+laststr+'txtExtendedPrice').value != '')

{

objQuoteLine.Warranty_Amount__c =getFloatValue(document.getElementById(firststr+':'+i+laststr+'txtWarrantyAmount').value).toFixed(2);

}

if(document.getElementById(firststr+':'+i+laststr+'chkSelect').value != null && document.getElementById(firststr+':'+i+laststr+'chkSelect').value != '')

{

objQuoteLine.Active__c =(document.getElementById(firststr+':'+i+laststr+'chkSelect').checked) ? true : false;

}

if(document.getElementById(firststr+':'+i+laststr+'hidDescriptionValue').value != null && document.getElementById(firststr+':'+i+laststr+'hidDescriptionValue').value != '')

{

var tempDescription = document.getElementById(firststr+':'+i+laststr+'hidDescriptionValue').value;

if(tempDescription == null || tempDescription == '')

{

objQuoteLine.Description__c = ' ';

}

else

{

objQuoteLine.Description__c =document.getElementById(firststr+':'+i+laststr+'hidDescriptionValue').value;

}

}

if(document.getElementById(firststr+':'+i+laststr+'txtInternalNotes').value != null && document.getElementById(firststr+':'+i+laststr+'txtInternalNotes').value != '')

{

objQuoteLine.Notes__c =document.getElementById(firststr+':'+i+laststr+'txtInternalNotes').value;

}

 

arrQuoteLines.push(objQuoteLine);

 

}

var result = sforce.connection.update(arrQuoteLines);

alert(result);

}

 

 

saveAll function in Controller:

 

public PageReference saveAll()

{

System.debug('starttttttttttttttttttttttttttt');

if(INFW_SaveQuoLineItems)

{

System.debug('*****INFW_SaveQuoLineItems TRUE *****');

INFW_quoteId = System.currentPageReference().getParameters().get('quoteId');

PageReference pr = new PageReference('/'+INFW_quoteId);

pr.setRedirect(true);

return pr;

}

else

{

QuoteLineItems();

return null;

}

System.debug('finishhhhhhhhhhhhhhhhhhhhhhhh');

return null;

}

 

 

public List<INFW_QuoteLine__c> QuoteLineItems()

{

if(INFW_ProductLineLimit == null )

INFW_ProductLineLimit = '';

String test = '';

if(AllowDragDrop)

test = 'select Original_Unit_Price__c, Product2__c, Id, Discount__c, Renewal_Date__c, Warranty_Amount__c, Unit_Sales_Price__c, Product2__r.IsActive, Gross_Margin__c, Quantity__c, Unit_List_Price__c, Active__c, Product2__r.Name, Description__c, Notes__c , Record_Type__c from INFW_QuoteLine__c where Quote__c =\'' + INFW_quoteId + '\' Order BY Sort_Order__c, Product2__r.Name ASC' + INFW_ProductLineLimit;

else

test = 'select Original_Unit_Price__c, Product2__c, Id, Discount__c, Renewal_Date__c, Warranty_Amount__c, Unit_Sales_Price__c, Product2__r.IsActive, Gross_Margin__c, Quantity__c, Unit_List_Price__c, Active__c, Product2__r.Name, Description__c, Notes__c , Record_Type__c from INFW_QuoteLine__c where Quote__c =\'' + INFW_quoteId + '\' Order BY Product2__r.Name ASC ' +INFW_ProductLineLimit;

lstQuoteLineItems = Database.query(test);

System.debug('test====' +test);

System.debug('**************'+lstQuoteLineItems);

for(Integer i = 0; i < lstQuoteLineItems.size(); i++)

{

if(lstQuoteLineItems[i].Discount__c != null && lstQuoteLineItems[i].Discount__c != 0)

{

Decimal tempDiscount = lstQuoteLineItems[i].Discount__c;

lstQuoteLineItems[i].Discount__c = tempDiscount.setScale(5);

}

if(lstQuoteLineItems[i].Unit_List_Price__c != null && lstQuoteLineItems[i].Unit_List_Price__c != 0)

{

Decimal tempCost = lstQuoteLineItems[i].Unit_List_Price__c;

lstQuoteLineItems[i].Unit_List_Price__c = tempCost.setScale(2);

}

if(lstQuoteLineItems[i].Unit_Sales_Price__c != null && lstQuoteLineItems[i].Unit_Sales_Price__c != 0)

{

Decimal tempUnitP = lstQuoteLineItems[i].Unit_Sales_Price__c;

// lstQuoteLineItems[i].Unit_Sales_Price__c = tempUnitP.setScale(2); unit sales price is not writable

}

if( lstQuoteLineItems[i].Quantity__c != null && lstQuoteLineItems[i].Quantity__c != 0)

{ System.debug('*****Starting Add*****'+ lstQuoteLineItems[i].Quantity__c + '$$$$$$$$$$$$$$$' + lstQuoteLineItems[i].Record_Type__c);

 

if(lstQuoteLineItems[i].Record_Type__c == 'Services')

{

Decimal tempQuantity = lstQuoteLineItems[i].Quantity__c;

lstQuoteLineItems[i].Quantity__c = tempQuantity.setScale(2);

}

}

String renewalDate = String.ValueOf(lstQuoteLineItems[i].Renewal_Date__c);

if(renewalDate == null)

{

renewalDate = '';

}

}

System.debug('lstQuoteLineItemsin quoteLine items====='+lstQuoteLineItems);

return lstQuoteLineItems;

}

 

This is the relative code for my issue. Kindly help if you can.

 

Thanks,

ckum 

WesNolte__cWesNolte__c

I can't see the code that calls your actionFunction, but here's a few tips:

 

CommandButtons should be used for calling action methods and I think that the command button is try to perform some default functionality that is interferring with your call. Try moving this call to the oncomplete event handler:

 

<apex:commandButton value="Save All" onclick oncomplete="javascript&colon;return Message4Going2QuoteDetailPage('saveall');" rerender="opdummy"/>

 Now this will run after the commandbutton does whatever else it thinks it needs to do. 

To use this actionFunction it needs to be called like this:

 

<apex:commandButton value="Do Something" action="{!doSomething}" oncomplete="SAVEITEMS();" />

<apex:actionFunction name="SAVEITEMS" action="{!saveAll}" rerender="OPquoteEdit" status="statusProductAll"/> 

 

Does this help?

 

Wes 

This was selected as the best answer
ckumckum

Oh Waoo that works!!!!!!!!!

 

Thanks a lot Wes

 

Cheers!!!

 

ckum