You need to sign in to do that
Don't have an account?
Test User 153
ActionFunction ... Not able to pass parameters
I am uploading a document and attaching it to a case using Javascript. Till this point it is working fine. But when I am trying to send the parameter ( CASE ID) using Action function and even though the function is getting called the caseId is not sent through... PFB the code...
<apex:page standardController="Case" extensions="InputfileUploadCont">
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
function uploadFile()
{
var input = document.getElementById('file-input');
// var parentId = "500g0000004UEb2" ;
var caseId;
var filesToUpload = input.files;
for(var i = 0, f; f = filesToUpload[i]; i++)
{
var reader = new FileReader();
// Keep a reference to the File in the FileReader so it can be accessed in callbacks
reader.file = f;
reader.onerror = function(e)
{
switch(e.target.error.code)
{
case e.target.error.NOT_FOUND_ERR:
alert('File Not Found!');
break;
case e.target.error.NOT_READABLE_ERR:
alert('File is not readable');
break;
case e.target.error.ABORT_ERR:
break; // noop
default:
alert('An error occurred reading this file.');
};
};
reader.onabort = function(e)
{
alert('File read cancelled');
};
reader.onload = function(e)
{
var newRecords = [];
var newCase = new sforce.SObject("Case");
newCase.Case_Language__c = "Russian";
newCase.subject = document.getElementById("subject");
newRecords.push(newCase);
var resultCase = sforce.connection.create(newRecords);
if(resultCase [0].getBoolean("success")){
alert('case created' + resultCase[0].id);
}else{
alert('Could not create record '+result);
}
var att = new sforce.SObject("Attachment");
att.Name = this.file.name;
att.ContentType = this.file.type;
att.ParentId = resultCase[0].id;
att.Body = (new sforce.Base64Binary(e.target.result)).toString();
sforce.connection.create([att],
{
onSuccess : function(result, source)
{
if (result[0].getBoolean("success"))
{
alert('Done : ' + resultCase[0].id);
var a = resultCase[0].Id
updateCase(a);
console.log("new attachment created with id " + result[0].id);
}
else
{
console.log("failed to create attachment " + result[0]);
}
},
onFailure : function(error, source)
{
console.log("An error has occurred " + error);
}
});
};
reader.readAsBinaryString(f);
}
}
</script>
<script src="/soap/ajax/29.0/connection.js" type="text/javascript"></script>
<apex:form >
<input id="file-input" type="file" name="file"/>
<input type="button" value="Upload" onclick="uploadFile();" />
<apex:actionFunction name="updateCase" action="{!updateCase}" reRender="txt" >
<apex:param name="scaseId" assignTo="{!updatedCaseId}" value="" />
</apex:actionFunction>
<b><apex:outputLabel value="{!val}" id ="txt"/></b>
</apex:form>
</apex:page>
CONTROLLER
public with sharing class InputfileUploadCont{
public Id updatedCaseId {get; set;}
public String val{get;set;}
public InputfileUploadCont(ApexPages.StandardController controller) {}
public void updateCase(){
val = 'Case ID : - ' + updatedCaseId;
system.debug('Case ID : - ' + updatedCaseId);
system.debug('scaseId Case ID : - ' + Apexpages.currentPage().getParameters().get('scaseId'));
system.debug('updatedCaseId Case ID : - ' + Apexpages.currentPage().getParameters().get('updatedCaseId'));
}
}
<apex:page standardController="Case" extensions="InputfileUploadCont">
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
function uploadFile()
{
var input = document.getElementById('file-input');
// var parentId = "500g0000004UEb2" ;
var caseId;
var filesToUpload = input.files;
for(var i = 0, f; f = filesToUpload[i]; i++)
{
var reader = new FileReader();
// Keep a reference to the File in the FileReader so it can be accessed in callbacks
reader.file = f;
reader.onerror = function(e)
{
switch(e.target.error.code)
{
case e.target.error.NOT_FOUND_ERR:
alert('File Not Found!');
break;
case e.target.error.NOT_READABLE_ERR:
alert('File is not readable');
break;
case e.target.error.ABORT_ERR:
break; // noop
default:
alert('An error occurred reading this file.');
};
};
reader.onabort = function(e)
{
alert('File read cancelled');
};
reader.onload = function(e)
{
var newRecords = [];
var newCase = new sforce.SObject("Case");
newCase.Case_Language__c = "Russian";
newCase.subject = document.getElementById("subject");
newRecords.push(newCase);
var resultCase = sforce.connection.create(newRecords);
if(resultCase [0].getBoolean("success")){
alert('case created' + resultCase[0].id);
}else{
alert('Could not create record '+result);
}
var att = new sforce.SObject("Attachment");
att.Name = this.file.name;
att.ContentType = this.file.type;
att.ParentId = resultCase[0].id;
att.Body = (new sforce.Base64Binary(e.target.result)).toString();
sforce.connection.create([att],
{
onSuccess : function(result, source)
{
if (result[0].getBoolean("success"))
{
alert('Done : ' + resultCase[0].id);
var a = resultCase[0].Id
updateCase(a);
console.log("new attachment created with id " + result[0].id);
}
else
{
console.log("failed to create attachment " + result[0]);
}
},
onFailure : function(error, source)
{
console.log("An error has occurred " + error);
}
});
};
reader.readAsBinaryString(f);
}
}
</script>
<script src="/soap/ajax/29.0/connection.js" type="text/javascript"></script>
<apex:form >
<input id="file-input" type="file" name="file"/>
<input type="button" value="Upload" onclick="uploadFile();" />
<apex:actionFunction name="updateCase" action="{!updateCase}" reRender="txt" >
<apex:param name="scaseId" assignTo="{!updatedCaseId}" value="" />
</apex:actionFunction>
<b><apex:outputLabel value="{!val}" id ="txt"/></b>
</apex:form>
</apex:page>
CONTROLLER
public with sharing class InputfileUploadCont{
public Id updatedCaseId {get; set;}
public String val{get;set;}
public InputfileUploadCont(ApexPages.StandardController controller) {}
public void updateCase(){
val = 'Case ID : - ' + updatedCaseId;
system.debug('Case ID : - ' + updatedCaseId);
system.debug('scaseId Case ID : - ' + Apexpages.currentPage().getParameters().get('scaseId'));
system.debug('updatedCaseId Case ID : - ' + Apexpages.currentPage().getParameters().get('updatedCaseId'));
}
}