I'm attempting to build a custom related list from scratch, with a whole set of new functionality, and in doing so, am replicating the way the default related list looks and feels. Part of this includes the Del hyperlink, which pops up with a "Are you sure?" message, and then deletes, and refreshes the page, or does nothing, based on user input.
My related list is located inside a Component, which is then added to a visualforce page, with the Projects id value handed to it. The related list takes this id, and finds objects related to it, (In this case, an Invoice), and pulls those values out, depending on RecordType, which is part of the parameters for the component.
What I am trying to do, is have the user be able to click on a link on the component, and have that link run a javascript function, which creates the pop up window, and then either runs a Controller function, or does nothing. Right now, I have it set up akin to this:
<component header.. >
<script>
function FuncName()
{
CallApexControllerMethod();
}
</script>
//.. we start looping through the invoices..
<apex:commandLink action="javascript:if (window.confirm('Are you sure? You should usually close an invoice, instead of deleting it, as all data will be lost when deleting an invoice.')) FuncName();">
<apex:param name="idVal" value="{!i.Id}" assignTo="{!idVal}"/>
Del
</apex:commandLink>
//Continue looping..
<apex:actionFunction name="CallApexControllerMethod" action="{!DeleteSchedule}" />
//End table..
And in my controller, I have the following method:
public String idVal { get; set; }
public PageReference DeleteSchedule()
{
String id = idVal;
if (id != null)
{
Invoice_Schedule__c tobeDeleted = null;
for(Invoice_Schedule__c i : invoices_not_gen)
if (i.Id == id) {
tobeDeleted = i;
break;
}
//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}
The problem that keeps coming up, is that FuncName is never found, I keep getting errors where its saying "JavaScript Function Not Defined" in my Chrome. I've tried a whole set of solutions, from changing the syntax and how I call the function, removing the script from the component and putting it on the page instead (so I avoid having three functions with the same name), making the function a variable to try to get it to have a global scope, to removing as much as I can, and just calling a method or two, and nothing seems to have worked- in all cases, I cannot get the function to be "defined". Any ideas how I would go about doing this? Am I missing some obvious flaw?
I come from a c# background, and my web experience mostly comes from ruby on rails and asp.net, and I have avoided javascript like the plague after a set of experiences while in high school, when I was doing a lot of commissioned work, and I would continuously run into errors, and due to a lack of a debugger or other such tool, I would have to dig through code by hand. I've already done all of that with this, and I still can't figure out why its not working.
Thanks to everyone for the replies- I got a few ideas from them, and Im going to give them a shot on Monday- will post back here, and mark best answer when I find a solution then.