• inanskar
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 6
    Replies

Hii all, 

I  already ask this query .. but i'm looking for different..I am looking for vf for uploading a file ..i am looking to upload a file using only this code.and i have to work on this code neglect this signed policy signatures...i have to upload the files in continous 5 page blocks

for each page block i gave cancel,upload,addmore  buttons i worked for one page block it worked fine but my requirement is i have to make up 5 similar pageblocks

Through repeat tag  i tried by having rows = 5 i'm getting type error : cannot repeat the file of defined...and i tried  for making the entire form  duplicated into 2 times but only one  file is uploading but my my requirement is all files have to be uploaded .. can u give me any suggestiong or correct for this .. i'm pasting code..Hope u can give me suggestions for this.. i have been trying this since 2 weeks..the following is the code:...

 

Vf page

------------------------------------------------------------------------------------------------------------------------------------------

<apex:page Controller="sub_FileUploadController" action="{!page2onLoad}" sidebar="false" cache="true" >
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
</meta>
<title>file input Test</title>
</head>

<apex:form id="apexform"> 

<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload Filess"> 
</apex:commandbutton>
<apex:pageblock >

<apex:PageBlocksection title="File Details" columns="1">
<apex:pageblocksectionItem >
<apex:outputLabel value=""/> 
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload File"> 
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton action="{!page2onLoad1}" value="Add More"/> 
</apex:commandButton> 
</apex:pageblocksectionItem> 
<apex:pageBlockSectionItem > 
<apex:outputLabel value="File Description"/>
<apex:inputtext id="ufdescription" value="{!userfiledescription}" />
</apex:pageBlockSectionItem> 

<!--Div Code used to display Progress bar image -->
<div id="display1" width="350">

</div> 
</apex:PageBlocksection>
</apex:pageblock> 

<apex:inputhidden id="filetypehidden" value="{!filetype}"/>
<apex:inputhidden id="filesizehidden" value="{!filesize}"/>
<apex:inputhidden id="filenamehidden" value="{!filenamehidden}"/>
<input type="hidden" id="submithidden" value="false"/>

<script type="text/javascript"> 
function getFileType()
{
try
{
var filetype;
var filename;
var filesizeF;
filetype=document.forms['submitform'].elements['file'].value; 
document.getElementById('j_id0:apexform:filenamehidden').value=filetype;
filetype=filetype.substring(filetype.indexOf('.',0)+1,filetype.length); 

document.getElementById('j_id0:apexform:filetypehidden').value=filetype;
filename=document.forms['submitform'].elements['key'];

if(filetype!='' || filetype!=null)
{
filename.value=filename.value + '.' + filetype;
}
if(navigator.appName!='Microsoft Internet Explorer')

try 
{
filesizeF=document.forms['submitform'].elements['file']; 
<!-- alert(filesizeF.files[0].fileSize);-->
document.getElementById('j_id0:apexform:filesizehidden').value=filesizeF.files[0].fileSize; 
//document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
catch(errr)
{
}
}
else
{
document.getElementById('j_id0:apexform:filesizehidden').value=0; 
}


if(document.getElementById('j_id0:apexform:filesizehidden').value!=0 && document.getElementById('j_id0:apexform:filesizehidden').value!='undefined' && document.getElementById('j_id0:apexform:filenamehidden').value!=undefined) {
document.getElementById('submithidden').value='true';
return true;
}
else
{
alert('Unable to capture file details..');
document.getElementById('submithidden').value='false';
return false;

}
catch(err)
{
alert(err);
return false;
}
}
function completedfunction()
{

try

if(document.getElementById('submithidden').value=='true')
{

<!--Code to display Progress bar image -->
var html = '';
html += '<img src="/resource/1323008320000/LoadingImage">';
html += '</img>'
document.getElementById('display1').innerHTML = html;
<!--Code to display Progress bar image end -->
document.forms['submitform'].submit(); 

} } 
catch(err)
{
alert(err);

}


</script> 
</apex:form>




<form id="submitform" 
action="https://s3.amazonaws.com/{!BucketName}"
method="post" enctype="multipart/form-data" >






<input type="hidden" name="AWSAccessKeyId" value="{!key}"/>
<input type="hidden" name="policy" value="{!policy}"/> 
<input type="hidden" name="signature" value="{!signedPolicy}"/>
<!-- <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AcctID}" /> -->
<input type="hidden" value="{!Filename}" name="key"/>

<apex:outputLabel value="File to upload"/>

<input id="fileid" type="file" size="50" name="file" /> 


</form>

</html>
</apex:page>

------------------------------------------------------------------------------------------------------------------------------------------------------------

Apex Code

 

public class sub_FileUploadController{
/*
public PageReference Deletefile() {
DeleteObjectRequest request = new DeleteObjectRequest();

BucketName = bucketName;
Key = FileKey;

S3Response response = s3Client.DeleteObject(request);
return null;
}
*/

public PageReference cancel() {
//string queryChild='SELECT Id,parent__c FROM '+ childName + 'Whereid=:' + AcctId + 'LIMIT 1' ;
// SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
Account_Documents__c A = [SELECT id,parent__c from Account_Documents__c where id=:AcctID];
delete a;
return new PageReference('/'+a.parent__c +'/d?retURL=%2F'+ a.parent__c);
//delete childObject;
//return null;
}


public string secret {get;set;}
public string key { get ;set; }
public string BucketName{get;set;}
public string BucketName1{get;set;}
public String serverURL {get;set;}
public String AcctID {get;set;}
public String AcctID1 {get;set;}
public String userFileName{get;set;}
public String userFileDescription{get;set;}
public String userFileDescription1{get;set;}
public String filenamehidden{get;set;}
public string Filename{get;set;}
public string fileType{get;set;}
public Boolean onemore{get;set;}
public Decimal fileSize{get;set;}
//private String AWSCredentialName = 'tvarana7';



//Variable for 2nd form(apexform1)
public string fileType1{get;set;}
public Decimal fileSize1{get;set;}
public String filenamehidden1{get;set;}
public string Filename1{get;set;}
string filedescriptionAPI1;
string filetypeAPI1;
string filesizeinbytesAPI1;
String filenameAPI1;


string filedescriptionAPI;
string filetypeAPI;
string filesizeinbytesAPI;
String filenameAPI;

datetime expire = system.now().addMinutes(40);
String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+
expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';


string policy { get {return
'{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ BucketName+'" } ,'+

// { "acl": "'+ record.Access__c +'" },'+ '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+
// '{"success_action_redirect": "https://'+serverurl+'/'+AcctID+'"},' +
'["starts-with", "$key", ""] ]}'; } }



public sub_FileUploadController()
{
secret='bXrMni3+SWcWU60QDDI37hNjllWCY3syswO0EFbF';
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
BucketName1='tvarana7';
onemore= False;
}
public String getPolicy() {
return EncodingUtil.base64Encode(Blob.valueOf(policy));
}

public String getSignedPolicy() {
return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy)),secret);
}


//tester
public String getHexPolicy() {
String p = getPolicy();
return EncodingUtil.convertToHex(Blob.valueOf(p));
}


private String make_sig(string canonicalBuffer,string secret) {
String macUrl ;
String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret));
Blob mac = Crypto.generateMac('HMacSHA1',blob.valueof(canonicalBuffer),blob.valueof(secret));
macUrl = EncodingUtil.base64Encode(mac);
return macUrl;
}
public String bucketToList {get;set;}

private String ChildName;

public void page2onLoad()
{
system.debug('ACCTID:'+AcctID);
if(AcctID==null || AcctID=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');



ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');




parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');




serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename=childObject.id;
filedescriptionAPI=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI=Apexpages.currentpage().getparameters().get('FILENAMEAPI');

}
else
{
String selectfields;
if(filedescriptionAPI!='' && filedescriptionAPI!=null){
selectfields=filedescriptionAPI;}
if(filetypeAPI!='' && filetypeAPI!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI;}
else{
selectfields=filetypeAPI;}
}
if(filesizeinbytesAPI!=null && filesizeinbytesAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI;}
else{
selectfields=filesizeinbytesAPI;}
}
if(filenameAPI!='null' && filenameAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI;}
else{
selectfields=filenameAPI;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'');
SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}

if(filenameAPI!='' && filenameAPI!='null'){
filenameAPI=filenameAPI.replace('\'','');
childObject.put(filenameAPI,userFileName);}
if(filedescriptionAPI!='' && filedescriptionAPI!='null'){
filedescriptionAPI=filedescriptionAPI.replace('\'','');
childObject.put(filedescriptionAPI,userFileDescription);}
if(filetypeAPI!='' && filetypeAPI!='null'){
filetypeAPI=filetypeAPI.replace('\'','');
childObject.put(filetypeAPI,filetype);}
if(filesizeinbytesAPI!='null' && filesizeinbytesAPI!=''){
filesizeinbytesAPI=filesizeinbytesAPI.replace('\'','');
childObject.put(filesizeinbytesAPI,(decimal)((fileSize)));}
system.debug('........................filesizeinbytesAPI fileSize........................'+fileSize);

update childObject;
}
}

//second method

public void page2onLoad1(){


onemore=True;
system.debug('ACCTID1:'+AcctID1);
if(AcctID1==null || AcctID1=='')
{

string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];

System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID1=childObject.Id;

serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename1=childObject.id;
filedescriptionAPI1=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI1=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI1=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI1=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
// }
// else
// {
String selectfields;
if(filedescriptionAPI1!='' && filedescriptionAPI1!=null){
selectfields=filedescriptionAPI1;}
if(filetypeAPI1!='' && filetypeAPI1!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI1;}
else{
selectfields=filetypeAPI1;}
}
if(filesizeinbytesAPI1!=null && filesizeinbytesAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI1;}
else{
selectfields=filesizeinbytesAPI1;}
}
if(filenameAPI1!='null' && filenameAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI1;}
else{
selectfields=filenameAPI1;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI1);

system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'');
// SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];

}


else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];}

if(filenameAPI1!='' && filenameAPI1!='null'){
filenameAPI1=filenameAPI1.replace('\'','');
childObject.put(filenameAPI1,userFileName);}
if(filedescriptionAPI1!='' && filedescriptionAPI1!='null'){
filedescriptionAPI1=filedescriptionAPI1.replace('\'','');
childObject.put(filedescriptionAPI1,userFileDescription1);}
if(filetypeAPI1!='' && filetypeAPI1!='null'){
filetypeAPI1=filetypeAPI1.replace('\'','');
childObject.put(filetypeAPI1,filetype1);}
if(filesizeinbytesAPI1!='null' && filesizeinbytesAPI1!=''){
filesizeinbytesAPI1=filesizeinbytesAPI1.replace('\'','');
childObject.put(filesizeinbytesAPI1,(decimal)((fileSize1)));}
system.debug('........................filesizeinbytesAPI1 fileSize1........................'+fileSize1);

update childObject;
}
}

//second method end

public static testmethod void testuplod(){
PageReference pageRef = Page.sub_FileUpload;
Account a=new Account();
a.name='Test';
insert a;
pageRef.getParameters().put('id',a.id);
pageRef.getParameters().put('ParentObjecName','Account');
pageRef.getParameters().put('ChildObjectName','tva__Account_documents__c');
pageRef.getParameters().put('ParentRefName','tva__Parent__c');
pageRef.getParameters().put('serverURL','https://na12.salesforce.com/services/Soap/c/12.0/00DU0000000Hg3A');
pageRef.getParameters().put('FILETYPEAPI','tva__file_type__c');
pageRef.getParameters().put('FILEDESCRIPTIONAPI','tva__file_description__c');
pageRef.getParameters().put('FILESIZEINBYTESAPI','tva__File_Size_in_Bytes__c');
pageRef.getParameters().put('FILENAMEAPI','tva__file_name__c');

sub_FileUploadController fp = new sub_FileUploadController();
Test.setCurrentPage(pageRef);
System.debug(fp.Policy);
System.debug(fp.getSignedPolicy());
System.debug(fp.getHexPolicy());
fp.page2onLoad();
fp.filesize=100000;
fp.page2onLoad();
}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

Hope i'll get a solution for this

Thanks in Advance

Hii all, 

I am looking for vf for uploading a file ..I tried and it worked fine but my rquirement  is that i had to take 5 pageblock sections in that each page block section i had to upload a single file my code works fine for one page block section for another it didn't work fine can u guide me the r8 solution

I had also tried with repeat tag by making row="5".. but it didn't work for me ..I'm pasting the code i tried

 

Vf page

------------------------------------------------------------------------------------------------------------------------------------------

<apex:page Controller="sub_FileUploadController" sidebar="false" >

<apex:repeat value="{!userfiledescription}">
<apex:form id="apexform">

<table border="1">

<tr>
<td>


<apex:outputLabel value=""/>
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload File">
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton action="{!page2onLoad1}" value="Add More"/>
</apex:commandButton>
</td></tr>


<tr><td>
<apex:outputLabel value="File Description"/></td>
<td>

<apex:inputtext id="ufdescription" value="{!userfiledescription}" />
</td>
</tr>

</table>


<!--Div Code used to display Progress bar image -->
<div id="display1" width="350">

</div>



<apex:inputhidden id="filetypehidden" value="{!filetype}"/>
<apex:inputhidden id="filesizehidden" value="{!filesize}"/>
<apex:inputhidden id="filenamehidden" value="{!filenamehidden}"/>
<input type="hidden" id="submithidden" value="false"/>

<script type="text/javascript">
function getFileType()
{
try
{
var filetype;
var filename;
var filesizeF;
filetype=document.forms['submitform'].elements['file'].value;
document.getElementById('j_id0:apexform:filenamehidden').value=filetype;
filetype=filetype.substring(filetype.indexOf('.',0)+1,filetype.length);

document.getElementById('j_id0:apexform:filetypehidden').value=filetype;
filename=document.forms['submitform'].elements['key'];

if(filetype!='' || filetype!=null)
{
filename.value=filename.value + '.' + filetype;
}
if(navigator.appName!='Microsoft Internet Explorer')
{
try
{
filesizeF=document.forms['submitform'].elements['file'];
<!-- alert(filesizeF.files[0].fileSize);-->
document.getElementById('j_id0:apexform:filesizehidden').value=filesizeF.files[0].fileSize;
//document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
catch(errr)
{
}
}
else
{
document.getElementById('j_id0:apexform:filesizehidden').value=0;
}


if(document.getElementById('j_id0:apexform:filesizehidden').value!=0 && document.getElementById('j_id0:apexform:filesizehidden').value!='undefined' && document.getElementById('j_id0:apexform:filenamehidden').value!=undefined) {
document.getElementById('submithidden').value='true';
return true;
}
else
{
alert('Unable to capture file details..');
document.getElementById('submithidden').value='false';
return false;
}
}
catch(err)
{
alert(err);
return false;
}
}
function completedfunction()
{

try
{
if(document.getElementById('submithidden').value=='true')
{

<!--Code to display Progress bar image -->
var html = '';
html += '<img src="/resource/1323008320000/LoadingImage">';
html += '</img>'
document.getElementById('display1').innerHTML = html;
<!--Code to display Progress bar image end -->
document.forms['submitform'].submit();

} }
catch(err)
{
alert(err);

}
}

</script>

</apex:form>
</apex:repeat>

<form id="submitform"
action="https://s3.amazonaws.com/{!BucketName}"
method="post" enctype="multipart/form-data">

<input type="hidden" name="AWSAccessKeyId" value="{!key}"/>
<input type="hidden" name="policy" value="{!policy}"/>
<input type="hidden" name="signature" value="{!signedPolicy}"/>
<!-- <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AcctID}" /> -->
<input type="hidden" value="{!Filename}" name="key"/>

<apex:outputLabel value="File to upload"/>
<input id="fileid" type="file" size="50" name="file"/>


</form>



</apex:page>

------------------------------------------------------------------------------------------------------------------------------------------------------------

Apex Code

 

public class sub_FileUploadController{
/*
public PageReference Deletefile() {
DeleteObjectRequest request = new DeleteObjectRequest();

BucketName = bucketName;
Key = FileKey;

S3Response response = s3Client.DeleteObject(request);
return null;
}
*/

public PageReference cancel() {
//string queryChild='SELECT Id,parent__c FROM '+ childName + 'Whereid=:' + AcctId + 'LIMIT 1' ;
// SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
Account_Documents__c A = [SELECT id,parent__c from Account_Documents__c where id=:AcctID];
delete a;
return new PageReference('/'+a.parent__c +'/d?retURL=%2F'+ a.parent__c);
//delete childObject;
//return null;
}


public string secret {get;set;}
public string key { get ;set; }
public string BucketName{get;set;}
public string BucketName1{get;set;}
public String serverURL {get;set;}
public String AcctID {get;set;}
public String AcctID1 {get;set;}
public String userFileName{get;set;}
public String userFileDescription{get;set;}
public String userFileDescription1{get;set;}
public String filenamehidden{get;set;}
public string Filename{get;set;}
public string fileType{get;set;}
public Boolean onemore{get;set;}
public Decimal fileSize{get;set;}
//private String AWSCredentialName = 'tvarana7';



//Variable for 2nd form(apexform1)
public string fileType1{get;set;}
public Decimal fileSize1{get;set;}
public String filenamehidden1{get;set;}
public string Filename1{get;set;}
string filedescriptionAPI1;
string filetypeAPI1;
string filesizeinbytesAPI1;
String filenameAPI1;


string filedescriptionAPI;
string filetypeAPI;
string filesizeinbytesAPI;
String filenameAPI;

datetime expire = system.now().addMinutes(40);
String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+
expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';


string policy { get {return
'{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ BucketName+'" } ,'+

// { "acl": "'+ record.Access__c +'" },'+ '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+
// '{"success_action_redirect": "https://'+serverurl+'/'+AcctID+'"},' +
'["starts-with", "$key", ""] ]}'; } }



public sub_FileUploadController()
{
secret='bXrMni3+SWcWU60QDDI37hNjllWCY3syswO0EFbF';
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
BucketName1='tvarana7';
onemore= False;
}
public String getPolicy() {
return EncodingUtil.base64Encode(Blob.valueOf(policy));
}

public String getSignedPolicy() {
return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy)),secret);
}


//tester
public String getHexPolicy() {
String p = getPolicy();
return EncodingUtil.convertToHex(Blob.valueOf(p));
}


private String make_sig(string canonicalBuffer,string secret) {
String macUrl ;
String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret));
Blob mac = Crypto.generateMac('HMacSHA1',blob.valueof(canonicalBuffer),blob.valueof(secret));
macUrl = EncodingUtil.base64Encode(mac);
return macUrl;
}
public String bucketToList {get;set;}

private String ChildName;

public void page2onLoad()
{
system.debug('ACCTID:'+AcctID);
if(AcctID==null || AcctID=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');



ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');




parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');




serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename=childObject.id;
filedescriptionAPI=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI=Apexpages.currentpage().getparameters().get('FILENAMEAPI');

}
else
{
String selectfields;
if(filedescriptionAPI!='' && filedescriptionAPI!=null){
selectfields=filedescriptionAPI;}
if(filetypeAPI!='' && filetypeAPI!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI;}
else{
selectfields=filetypeAPI;}
}
if(filesizeinbytesAPI!=null && filesizeinbytesAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI;}
else{
selectfields=filesizeinbytesAPI;}
}
if(filenameAPI!='null' && filenameAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI;}
else{
selectfields=filenameAPI;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'');
SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}

if(filenameAPI!='' && filenameAPI!='null'){
filenameAPI=filenameAPI.replace('\'','');
childObject.put(filenameAPI,userFileName);}
if(filedescriptionAPI!='' && filedescriptionAPI!='null'){
filedescriptionAPI=filedescriptionAPI.replace('\'','');
childObject.put(filedescriptionAPI,userFileDescription);}
if(filetypeAPI!='' && filetypeAPI!='null'){
filetypeAPI=filetypeAPI.replace('\'','');
childObject.put(filetypeAPI,filetype);}
if(filesizeinbytesAPI!='null' && filesizeinbytesAPI!=''){
filesizeinbytesAPI=filesizeinbytesAPI.replace('\'','');
childObject.put(filesizeinbytesAPI,(decimal)((fileSize)));}
system.debug('........................filesizeinbytesAPI fileSize........................'+fileSize);

update childObject;
}
}

//second method

public void page2onLoad1(){


onemore=True;
system.debug('ACCTID1:'+AcctID1);
if(AcctID1==null || AcctID1=='')
{

string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];

System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID1=childObject.Id;

serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename1=childObject.id;
filedescriptionAPI1=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI1=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI1=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI1=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
// }
// else
// {
String selectfields;
if(filedescriptionAPI1!='' && filedescriptionAPI1!=null){
selectfields=filedescriptionAPI1;}
if(filetypeAPI1!='' && filetypeAPI1!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI1;}
else{
selectfields=filetypeAPI1;}
}
if(filesizeinbytesAPI1!=null && filesizeinbytesAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI1;}
else{
selectfields=filesizeinbytesAPI1;}
}
if(filenameAPI1!='null' && filenameAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI1;}
else{
selectfields=filenameAPI1;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI1);

system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'');
// SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];

}


else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];}

if(filenameAPI1!='' && filenameAPI1!='null'){
filenameAPI1=filenameAPI1.replace('\'','');
childObject.put(filenameAPI1,userFileName);}
if(filedescriptionAPI1!='' && filedescriptionAPI1!='null'){
filedescriptionAPI1=filedescriptionAPI1.replace('\'','');
childObject.put(filedescriptionAPI1,userFileDescription1);}
if(filetypeAPI1!='' && filetypeAPI1!='null'){
filetypeAPI1=filetypeAPI1.replace('\'','');
childObject.put(filetypeAPI1,filetype1);}
if(filesizeinbytesAPI1!='null' && filesizeinbytesAPI1!=''){
filesizeinbytesAPI1=filesizeinbytesAPI1.replace('\'','');
childObject.put(filesizeinbytesAPI1,(decimal)((fileSize1)));}
system.debug('........................filesizeinbytesAPI1 fileSize1........................'+fileSize1);

update childObject;
}
}

//second method end

public static testmethod void testuplod(){
PageReference pageRef = Page.sub_FileUpload;
Account a=new Account();
a.name='Test';
insert a;
pageRef.getParameters().put('id',a.id);
pageRef.getParameters().put('ParentObjecName','Account');
pageRef.getParameters().put('ChildObjectName','tva__Account_documents__c');
pageRef.getParameters().put('ParentRefName','tva__Parent__c');
pageRef.getParameters().put('serverURL','https://na12.salesforce.com/services/Soap/c/12.0/00DU0000000Hg3A');
pageRef.getParameters().put('FILETYPEAPI','tva__file_type__c');
pageRef.getParameters().put('FILEDESCRIPTIONAPI','tva__file_description__c');
pageRef.getParameters().put('FILESIZEINBYTESAPI','tva__File_Size_in_Bytes__c');
pageRef.getParameters().put('FILENAMEAPI','tva__file_name__c');

sub_FileUploadController fp = new sub_FileUploadController();
Test.setCurrentPage(pageRef);
System.debug(fp.Policy);
System.debug(fp.getSignedPolicy());
System.debug(fp.getHexPolicy());
fp.page2onLoad();
fp.filesize=100000;
fp.page2onLoad();
}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

Hope i'll get a solution for this

Thanks in Advance

Hii all, 

I am looking for vf for uploading a file ..I tried and it worked fine but my rquirement  is that i had to take 5 pageblock sections in that each page block section i had to upload a single file my code works fine for one page block section for another it didn't work fine can u guide me the r8 solution

I had also tried with repeat tag by making row="5".. but it didn't work for me ..I'm pasting the code i tried

 

Vf page

------------------------------------------------------------------------------------------------------------------------------------------

<apex:page Controller="sub_FileUploadController" sidebar="false" >

<apex:repeat value="{!userfiledescription}">
<apex:form id="apexform">

<table border="1">

<tr>
<td>


<apex:outputLabel value=""/>
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload File">
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton action="{!page2onLoad1}" value="Add More"/>
</apex:commandButton>
</td></tr>


<tr><td>
<apex:outputLabel value="File Description"/></td>
<td>

<apex:inputtext id="ufdescription" value="{!userfiledescription}" />
</td>
</tr>

</table>


<!--Div Code used to display Progress bar image -->
<div id="display1" width="350">

</div>



<apex:inputhidden id="filetypehidden" value="{!filetype}"/>
<apex:inputhidden id="filesizehidden" value="{!filesize}"/>
<apex:inputhidden id="filenamehidden" value="{!filenamehidden}"/>
<input type="hidden" id="submithidden" value="false"/>

<script type="text/javascript">
function getFileType()
{
try
{
var filetype;
var filename;
var filesizeF;
filetype=document.forms['submitform'].elements['file'].value;
document.getElementById('j_id0:apexform:filenamehidden').value=filetype;
filetype=filetype.substring(filetype.indexOf('.',0)+1,filetype.length);

document.getElementById('j_id0:apexform:filetypehidden').value=filetype;
filename=document.forms['submitform'].elements['key'];

if(filetype!='' || filetype!=null)
{
filename.value=filename.value + '.' + filetype;
}
if(navigator.appName!='Microsoft Internet Explorer')
{
try
{
filesizeF=document.forms['submitform'].elements['file'];
<!-- alert(filesizeF.files[0].fileSize);-->
document.getElementById('j_id0:apexform:filesizehidden').value=filesizeF.files[0].fileSize;
//document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
catch(errr)
{
}
}
else
{
document.getElementById('j_id0:apexform:filesizehidden').value=0;
}


if(document.getElementById('j_id0:apexform:filesizehidden').value!=0 && document.getElementById('j_id0:apexform:filesizehidden').value!='undefined' && document.getElementById('j_id0:apexform:filenamehidden').value!=undefined) {
document.getElementById('submithidden').value='true';
return true;
}
else
{
alert('Unable to capture file details..');
document.getElementById('submithidden').value='false';
return false;
}
}
catch(err)
{
alert(err);
return false;
}
}
function completedfunction()
{

try
{
if(document.getElementById('submithidden').value=='true')
{

<!--Code to display Progress bar image -->
var html = '';
html += '<img src="/resource/1323008320000/LoadingImage">';
html += '</img>'
document.getElementById('display1').innerHTML = html;
<!--Code to display Progress bar image end -->
document.forms['submitform'].submit();

} }
catch(err)
{
alert(err);

}
}

</script>

</apex:form>
</apex:repeat>

<form id="submitform"
action="https://s3.amazonaws.com/{!BucketName}"
method="post" enctype="multipart/form-data">

<input type="hidden" name="AWSAccessKeyId" value="{!key}"/>
<input type="hidden" name="policy" value="{!policy}"/>
<input type="hidden" name="signature" value="{!signedPolicy}"/>
<!-- <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AcctID}" /> -->
<input type="hidden" value="{!Filename}" name="key"/>

<apex:outputLabel value="File to upload"/>
<input id="fileid" type="file" size="50" name="file"/>


</form>



</apex:page>

------------------------------------------------------------------------------------------------------------------------------------------------------------

Apex Code

 

public class sub_FileUploadController{
/*
public PageReference Deletefile() {
DeleteObjectRequest request = new DeleteObjectRequest();

BucketName = bucketName;
Key = FileKey;

S3Response response = s3Client.DeleteObject(request);
return null;
}
*/

public PageReference cancel() {
//string queryChild='SELECT Id,parent__c FROM '+ childName + 'Whereid=:' + AcctId + 'LIMIT 1' ;
// SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
Account_Documents__c A = [SELECT id,parent__c from Account_Documents__c where id=:AcctID];
delete a;
return new PageReference('/'+a.parent__c +'/d?retURL=%2F'+ a.parent__c);
//delete childObject;
//return null;
}


public string secret {get;set;}
public string key { get ;set; }
public string BucketName{get;set;}
public string BucketName1{get;set;}
public String serverURL {get;set;}
public String AcctID {get;set;}
public String AcctID1 {get;set;}
public String userFileName{get;set;}
public String userFileDescription{get;set;}
public String userFileDescription1{get;set;}
public String filenamehidden{get;set;}
public string Filename{get;set;}
public string fileType{get;set;}
public Boolean onemore{get;set;}
public Decimal fileSize{get;set;}
//private String AWSCredentialName = 'tvarana7';



//Variable for 2nd form(apexform1)
public string fileType1{get;set;}
public Decimal fileSize1{get;set;}
public String filenamehidden1{get;set;}
public string Filename1{get;set;}
string filedescriptionAPI1;
string filetypeAPI1;
string filesizeinbytesAPI1;
String filenameAPI1;


string filedescriptionAPI;
string filetypeAPI;
string filesizeinbytesAPI;
String filenameAPI;

datetime expire = system.now().addMinutes(40);
String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+
expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';


string policy { get {return
'{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ BucketName+'" } ,'+

// { "acl": "'+ record.Access__c +'" },'+ '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+
// '{"success_action_redirect": "https://'+serverurl+'/'+AcctID+'"},' +
'["starts-with", "$key", ""] ]}'; } }



public sub_FileUploadController()
{
secret='bXrMni3+SWcWU60QDDI37hNjllWCY3syswO0EFbF';
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
BucketName1='tvarana7';
onemore= False;
}
public String getPolicy() {
return EncodingUtil.base64Encode(Blob.valueOf(policy));
}

public String getSignedPolicy() {
return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy)),secret);
}


//tester
public String getHexPolicy() {
String p = getPolicy();
return EncodingUtil.convertToHex(Blob.valueOf(p));
}


private String make_sig(string canonicalBuffer,string secret) {
String macUrl ;
String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret));
Blob mac = Crypto.generateMac('HMacSHA1',blob.valueof(canonicalBuffer),blob.valueof(secret));
macUrl = EncodingUtil.base64Encode(mac);
return macUrl;
}
public String bucketToList {get;set;}

private String ChildName;

public void page2onLoad()
{
system.debug('ACCTID:'+AcctID);
if(AcctID==null || AcctID=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');



ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');




parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');




serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename=childObject.id;
filedescriptionAPI=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI=Apexpages.currentpage().getparameters().get('FILENAMEAPI');

}
else
{
String selectfields;
if(filedescriptionAPI!='' && filedescriptionAPI!=null){
selectfields=filedescriptionAPI;}
if(filetypeAPI!='' && filetypeAPI!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI;}
else{
selectfields=filetypeAPI;}
}
if(filesizeinbytesAPI!=null && filesizeinbytesAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI;}
else{
selectfields=filesizeinbytesAPI;}
}
if(filenameAPI!='null' && filenameAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI;}
else{
selectfields=filenameAPI;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'');
SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}

if(filenameAPI!='' && filenameAPI!='null'){
filenameAPI=filenameAPI.replace('\'','');
childObject.put(filenameAPI,userFileName);}
if(filedescriptionAPI!='' && filedescriptionAPI!='null'){
filedescriptionAPI=filedescriptionAPI.replace('\'','');
childObject.put(filedescriptionAPI,userFileDescription);}
if(filetypeAPI!='' && filetypeAPI!='null'){
filetypeAPI=filetypeAPI.replace('\'','');
childObject.put(filetypeAPI,filetype);}
if(filesizeinbytesAPI!='null' && filesizeinbytesAPI!=''){
filesizeinbytesAPI=filesizeinbytesAPI.replace('\'','');
childObject.put(filesizeinbytesAPI,(decimal)((fileSize)));}
system.debug('........................filesizeinbytesAPI fileSize........................'+fileSize);

update childObject;
}
}

//second method

public void page2onLoad1(){


onemore=True;
system.debug('ACCTID1:'+AcctID1);
if(AcctID1==null || AcctID1=='')
{

string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];

System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID1=childObject.Id;

serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename1=childObject.id;
filedescriptionAPI1=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI1=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI1=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI1=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
// }
// else
// {
String selectfields;
if(filedescriptionAPI1!='' && filedescriptionAPI1!=null){
selectfields=filedescriptionAPI1;}
if(filetypeAPI1!='' && filetypeAPI1!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI1;}
else{
selectfields=filetypeAPI1;}
}
if(filesizeinbytesAPI1!=null && filesizeinbytesAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI1;}
else{
selectfields=filesizeinbytesAPI1;}
}
if(filenameAPI1!='null' && filenameAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI1;}
else{
selectfields=filenameAPI1;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI1);

system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'');
// SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];

}


else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];}

if(filenameAPI1!='' && filenameAPI1!='null'){
filenameAPI1=filenameAPI1.replace('\'','');
childObject.put(filenameAPI1,userFileName);}
if(filedescriptionAPI1!='' && filedescriptionAPI1!='null'){
filedescriptionAPI1=filedescriptionAPI1.replace('\'','');
childObject.put(filedescriptionAPI1,userFileDescription1);}
if(filetypeAPI1!='' && filetypeAPI1!='null'){
filetypeAPI1=filetypeAPI1.replace('\'','');
childObject.put(filetypeAPI1,filetype1);}
if(filesizeinbytesAPI1!='null' && filesizeinbytesAPI1!=''){
filesizeinbytesAPI1=filesizeinbytesAPI1.replace('\'','');
childObject.put(filesizeinbytesAPI1,(decimal)((fileSize1)));}
system.debug('........................filesizeinbytesAPI1 fileSize1........................'+fileSize1);

update childObject;
}
}

//second method end

public static testmethod void testuplod(){
PageReference pageRef = Page.sub_FileUpload;
Account a=new Account();
a.name='Test';
insert a;
pageRef.getParameters().put('id',a.id);
pageRef.getParameters().put('ParentObjecName','Account');
pageRef.getParameters().put('ChildObjectName','tva__Account_documents__c');
pageRef.getParameters().put('ParentRefName','tva__Parent__c');
pageRef.getParameters().put('serverURL','https://na12.salesforce.com/services/Soap/c/12.0/00DU0000000Hg3A');
pageRef.getParameters().put('FILETYPEAPI','tva__file_type__c');
pageRef.getParameters().put('FILEDESCRIPTIONAPI','tva__file_description__c');
pageRef.getParameters().put('FILESIZEINBYTESAPI','tva__File_Size_in_Bytes__c');
pageRef.getParameters().put('FILENAMEAPI','tva__file_name__c');

sub_FileUploadController fp = new sub_FileUploadController();
Test.setCurrentPage(pageRef);
System.debug(fp.Policy);
System.debug(fp.getSignedPolicy());
System.debug(fp.getHexPolicy());
fp.page2onLoad();
fp.filesize=100000;
fp.page2onLoad();
}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

Hope i'll get a solution for this

Thanks in Advance

 

Hii all ,

I have the requirement that i have 5 pageblock section  such that each pageblocksection  contains the all feilds and the entire page contains only one save button such that i have to insert the all the fields

i'm giving the code can u get me the correct approach for the code

 

 

<apex:page controller="file2">
<apex:form >
<apex:pageBlock >

<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>

<apex:pageBlockTable value="{!f1}" var="f" id="form1">

<apex:column headerValue="Name">
<apex:inputField value="{!f.Name}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!f.Description__c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!f1}" var="f" id="form2" >

<apex:column headerValue="Name">
<apex:inputField value="{!f.Name}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!f.Description__c}"/>
</apex:column>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>

 

 

controller

-----------------------------------

public with sharing class file2 {

public file2() {
f1 = new List<File__c>();
f1.add(new File__c());

}


public List<File__c> f1 {get; set;}

public PageReference save()
{
insert f1;

return null;
}
}

 

Hi  All,

I got an issue that how to represent a javascript variable like the below code myDate in visualforce page

 

<script language="JavaScript">
var myDate = new Date(document.getElementById("{!r.Invoice_Date__c}").value);
myDate.setMonth( myDate.getMonth() + 1 );
alert(myDate);
Document.write(myDate);

</script>

can u tell the tags for representing the mydate variable in visualforce Page

 

Thanks in Advance

Hii All,

i am looking up for a formula  for auto incrementing of month for a Date 

i tried for one Opportunity closeDate to be automatically incremented in its related Invoices Invoice Date field

i tried for a formula  but it's just incrementing once can u guys help me through out for the right formula

 

DATE( 
year( Opportunity__r.CloseDate ) 
+ floor((month( Opportunity__r.CloseDate ) +Add_Months__c)/12) + if(and(month( Opportunity__r.CloseDate )=12,Add_Months__c>=12),-1,0) 

if( mod( month( Opportunity__r.CloseDate ) + Add_Months__c , 12 ) = 0, 12 , mod( month( Opportunity__r.CloseDate ) + Add_Months__c , 12 )) 

min( 
day( Opportunity__r.CloseDate ), 
case( 
max( mod( month( Opportunity__r.CloseDate ) + Add_Months__c , 12 ) , 1), 
9,30, 
4,30, 
6,30, 
11,30, 
2,28, 
31 


)

 

Thanks in Advance..

Hi all,

I have an issue regarding Dynamic Editing  I created an Opportunity item for every particelar Opportunity there ar n related invoices and for every 1 invoice there is 1 related invoice line item  I have to create a complete visualforce page where i can

 put all these there objects(Opportunity,invoice and invoiclineitem fields) and i have to dynamically edit all these fields

can u get me the code how to dynamic editing of all these fields

I try for a controller but not getting any results

Controller

------------------------------------------------------------------------------------------------------------------------------

public with sharing class vedit

{

 string id;

 public Opportunity op{get; set;}

public list<invoice__c> inv{get; set;}

public list<Invoice_Line_Item__c> invlt{get; set;}

   public vedit() 

{

  this.id=ApexPages.currentPage().getParameters().get('id');   

op=[select id,name,Invoice_Quantity__c,Invoice_Status__c,Number_Of_Invoices__c,Invoice_Total__c,DeliveryInstallationStatus__c,  Fully_Paid_Invoices_total__c,Open_Invoices_Total__c,Partially_Paid_Invoices_Total__c,Total_Invoiced_Amount__c, Total_Invoice_Quantity__c from Opportunity where id=:this.id]; 

 inv=[select id,name,Delivery_Installation_Status__c,Fully_Paid_Invoices_total__c,Invoice_Date__c,Invoice_Quantity__c,Invoice_Status__c,Invoice_Total__c,Open_Invoices_Total__c,Opportunity__c,Partially_Paid_Invoices_Total__c, Total_Invoiced_Amount__c,Total_Invoice_Quantity__c from invoice__c where opportunity__c=:op.id];  

Decimal k =op.Number_Of_Invoices__c; 

for(Integer n=0;n<k;n++)   

invlt=[select id,name,Invoice__c,Price__c,Product__c,Qty__c,Total__c from Invoice_Line_Item__c where invoice__c=:inv[n].id]; 

}

 

 }

 public PageReference editinv()

 {  return null; }

 public PageReference customsave()

update op;

 update inv; 

update invlt; 

return Page.t1;

}

 }

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I just put the controller what i thought can u get me the write controller and write vf page for dynamic editing of all these fields

 Thanks in advance

Hi all,

I have an issue regarding Dynamic Editing  I created an Opportunity item for every particelar Opportunity there ar n related invoices and for every 1 invoice there is 1 related invoice line item  I have to create a complete visualforce page where i can

 put all these there objects(Opportunity,invoice and invoiclineitem fields) and i have to dynamically edit all these fields

can u get me the code how to dynamic editing of all these fields

I try for a controller but not getting any results

Controller

------------------------------------------------------------------------------------------------------------------------------

public with sharing class vedit

{

 string id;

 public Opportunity op{get; set;}

public list<invoice__c> inv{get; set;}

public list<Invoice_Line_Item__c> invlt{get; set;}

   public vedit() 

{

  this.id=ApexPages.currentPage().getParameters().get('id');   

op=[select id,name,Invoice_Quantity__c,Invoice_Status__c,Number_Of_Invoices__c,Invoice_Total__c,DeliveryInstallationStatus__c,  Fully_Paid_Invoices_total__c,Open_Invoices_Total__c,Partially_Paid_Invoices_Total__c,Total_Invoiced_Amount__c, Total_Invoice_Quantity__c from Opportunity where id=:this.id]; 

 inv=[select id,name,Delivery_Installation_Status__c,Fully_Paid_Invoices_total__c,Invoice_Date__c,Invoice_Quantity__c,Invoice_Status__c,Invoice_Total__c,Open_Invoices_Total__c,Opportunity__c,Partially_Paid_Invoices_Total__c, Total_Invoiced_Amount__c,Total_Invoice_Quantity__c from invoice__c where opportunity__c=:op.id];  

Decimal k =op.Number_Of_Invoices__c; 

for(Integer n=0;n<k;n++)   

invlt=[select id,name,Invoice__c,Price__c,Product__c,Qty__c,Total__c from Invoice_Line_Item__c where invoice__c=:inv[n].id]; 

}

 

 }

 public PageReference editinv()

 {  return null; }

 public PageReference customsave()

update op;

 update inv; 

update invlt; 

return Page.t1;

}

 }

 

I just put the controller what i thought can u get me the write controller and write vf page for dynamic editing of all these fields

 

Thanks in Advance

I had to display the Opportunity fields and it's related all invoices and invoice line items fields in one visual force page

so i can edit any field it had to be updated in it's related object fields i had tried the code but it's not working properly can u give me the correction of the controller

 

<apex:page controller="vfediting"><apex:pageBlock title="Opportunity" id="op2">

 

<apex:form id="f1" > <apex:outputPanel rendered="{!table1}">

 <apex:pageBlockTable value="{!op}" var="o">

 <apex:column headerValue="Action"/>

<apex:column >       

     <apex:outputLink value="/{!o.id}/e?retURL=/apex/{!$CurrentPage.Name}">Edit</apex:outputLink> 

       </apex:column>  

<apex:column value="{!o.name}"/> 

<apex:column value="{!o.Invoice_Quantity__c}"/> 

<apex:column value="{!o.Invoice_Status__c}"/> 

<apex:column value="{!o.Invoice_Total__c}"/> 

<apex:column value="{!o.DeliveryInstallationStatus__c}"/>

 <apex:column value="{!o.Fully_Paid_Invoices_total__c}"/> 

<apex:column value="{!o.Open_Invoices_Total__c}"/>

 <apex:column value="{!o.Partially_Paid_Invoices_Total__c}"/>

 <apex:column value="{!o.Total_Invoiced_Amount__c}"/>

 <apex:column value="{!o.Total_Invoice_Quantity__c}"/>

  </apex:pageBlockTable><apex:pageBlockTable value="{!inv}" var="i1">

<apex:column value="{!i1.name}">

</apex:column>

<apex:column value="{!i1.Delivery_Installation_Status__c}"></apex:column>

<apex:column value="{!i1.Fully_Paid_Invoices_total__c}"></apex:column>

<apex:column value="{!i1.Invoice_Date__c}"></apex:column>

<apex:column value="{!i1.Invoice_Quantity__c}"></apex:column>

<apex:column value="{!i1.Total_Invoiced_Amount__c}"></apex:column>

<apex:column value="{!i1.Invoice_Status__c}"></apex:column>

<apex:column value="{!i1.Invoice_Total__c}"></apex:column>

<apex:column value="{!i1.Open_Invoices_Total__c}"></apex:column>

<apex:column value="{!i1.Opportunity__c}"></apex:column>

<apex:column value="{!i1.Partially_Paid_Invoices_Total__c}"></apex:column>

</apex:pageBlockTable>

<apex:pageBlockTable value="{!invlt}" var="il2">

<apex:column value="{!il2.name}"></apex:column>

<apex:column value="{!il2.Invoice__c}"></apex:column

><apex:column value="{!il2.Price__c}"></apex:column>

<apex:column value="{!il2.Product__c}"></apex:column>

<apex:column value="{!il2.Qty__c}"></apex:column>

<apex:column value="{!il2.Total__c}"></apex:column>

</apex:pageBlockTable>

</apex:outputPanel>
 <apex:outputPanel rendered="{!table2}">

 <apex:pageBlockTable value="{!oplist}" var="o"> 

<apex:column value="{!o.name}"/> 

<apex:column value="{!o.Invoice_Quantity__c}"/> 

<apex:column value="{!o.Invoice_Status__c}"/>

 <apex:column value="{!o.Invoice_Total__c}"/> 

<apex:column value="{!o.DeliveryInstallationStatus__c}"/>

 <apex:column value="{!o.Fully_Paid_Invoices_total__c}"/>

 <apex:column value="{!o.Open_Invoices_Total__c}"/>

<apex:column value="{!o.Partially_Paid_Invoices_Total__c}"/>

 <apex:column value="{!o.Total_Invoiced_Amount__c}"/> 

<apex:column value="{!o.Total_Invoice_Quantity__c}"/> 

</apex:pageBlockTable><apex:pageBlockTable value="{!inv}" var="i1">

<apex:column headerValue="Action"/>
<apex:column ><apex:commandLink value="save" action="{!save}"/></apex:column>
<apex:column value="{!i1.name}"/>

<apex:column value="{!i1.Delivery_Installation_Status__c}"/>

<apex:column value="{!i1.Fully_Paid_Invoices_total__c}"/>

<apex:column value="{!i1.Invoice_Date__c}"/>

<apex:column value="{!i1.Invoice_Quantity__c}"/>

<apex:column value="{!i1.Total_Invoiced_Amount__c}"/>

<apex:column value="{!i1.Invoice_Status__c}"/>

<apex:column value="{!i1.Invoice_Total__c}"/>

<apex:column value="{!i1.Open_Invoices_Total__c}"/><apex:column value="{!i1.Opportunity__c}"/><apex:column value="{!i1.Partially_Paid_Invoices_Total__c}"/><apex:column value="{!i1.Total_Invoice_Quantity__c}"/><apex:column value="{!i1.Total_Invoice_Quantity__c}"></apex:column></apex:pageBlockTable><apex:pageBlockTable value="{!invlt}" var="il2"><apex:column value="{!il2.name}"></apex:column><apex:column value="{!il2.Invoice__c}"></apex:column><apex:column value="{!il2.Price__c}"></apex:column><apex:column value="{!il2.Product__c}"></apex:column><apex:column value="{!il2.Qty__c}"></apex:column><apex:column value="{!il2.Total__c}">

</apex:column></apex:pageBlockTable></apex:outputPanel>
</apex:form>

</apex:pageBlock> 

 </apex:page>

 

----------------------------------------------------------------------------------------------------------------------------------------------------

 

public with sharing class vfediting {
   
public Opportunity op{get; set;}public list<invoice__c> inv{get; set;}public list<Invoice_Line_Item__c> invlt{get; set;}

         public vfediting() 

   {          op=[select id,name,Invoice_Quantity__c,Invoice_Status__c,Invoice_Total__c,DeliveryInstallationStatus__c ,Fully_Paid_Invoices_total__c,Open_Invoices_Total__c,Partially_Paid_Invoices_Total__c,Total_Invoiced_Amount__c, Total_Invoice_Quantity__c from Opportunity where id=:ApexPages.currentPage().getParameters().get('id')];   inv=[select id,name,Delivery_Installation_Status__c,Fully_Paid_Invoices_total__c,Invoice_Date__c,Invoice_Quantity__c, Invoice_Status__c,Invoice_Total__c,Open_Invoices_Total__c,Opportunity__c,Partially_Paid_Invoices_Total__c, Total_Invoiced_Amount__c,Total_Invoice_Quantity__c from invoice__c where opportunity__c=:op.id];   invlt=[select id,name,Invoice__c,Price__c,Product__c,Qty__c,Total__c from Invoice_Line_Item__c where invoice__c=:inv[0].id];              }     

   public PageReference save() {        table2=false;        table1=true;        update inv;        update invlt;        return null;    }



    public boolean getTable2() {        return Table2;    }

 boolean Table1=true; boolean Table2=false; public boolean gettable1(){ return table1; } 


    public PageReference edit() {      table1=false;      table2=true;      return null;  } 

  public PageReference Invoices()  {   return null;   PageReference customPage = new PageReference('006/o'); //customPage.getParameters().put('id', i.ID);customPage.setRedirect(true); //return(new ApexPages.StandardController(i)).view();return customPage;
 }

}

 

I'm getting error can u guide me the r8 controller

Hii All,

I have Scenario

that i made custom fireld

DATA Type:picklist

Field:Days__c

values{MOn,Tue,Wed,Thu,Fri,Sat,Sun]

and i have to get the o/p as Name :Mike NUmber of  working daysDays :4

 

 

public with sharing class Workdays

{

  public Workdays() {  }

 Account a = new Account();

 List<Account> a1; 

public list<Account> getAcclist()

 {  return a1; }

 public PageReference Attendance()

 {

 a1=[select count(id),name,Days__c from Account where name=:a.name Group by Days__c];

 public Account getAccount() {  return a; }

 

}

and i'm getting ERror:ErrorError: Compile Error: Field must be grouped or aggregated: Name at line 14 column 6

 

can u plz guide how to apply group by function for this code

Thanks in Advance

 

Hi all..

I got an issue ton  trigger that

if i insert a record successively ten duplicate records has to be created

if i delete a record that particular duplicate records has to be deleted

Guys .i'm in dielemma whether trigger have the ability to create this records

plz help me out

Thanks in Advance

With regards

Inan:)

Gud afternoon guys

I'm uday new to salesforce.. i just got wondering for a query  that

i Created a Custom Object Called Invoice with the following fields
Invoice NUmber: Auto Number
Invoice Date: Date
Opportunity: Lookup(Opportunity)
Invoice Status: Picklist (Open, Partially Paid, Fully Paid)

 

But i'm wondering how to create this fields can u jst please guide how to create this fields
Invoice Total: Roll Up Inv Line Item ( Total Field)
Invoice Quantity: Roll up Summary (Qty Invoice)

and i also Created another custom object called Invoice Line Item with following fields
Inv LI ID: Auto Number
Invoice: master Detail (Invoice)
Product: Lookup(Product)
Price: Currency
Qty: Number
Total: Formula (Price*Qty)

but i'm looking how to write these following triggers for:

Each Opportunity can have multiple Invoices.

  • Create a Field on Opportunity called Total Invoiced Amount (Sum of Invoice total on Invoice). If we make any changes on Invoice or delete it then Total Invoiced Amount should also change.
  • Create a field called Total Invoiced Quantity(Type = Number) on Opportunity Object. The field should calculate and display the total Qty of Invoice Line items and populate in opportunity Total Invoiced Quantity field.
  • Create three fields Open Invoices Total, Partially Paid Invoices Total and Fully Paid Invoices total with type = number on opportunity object. The field should show the sum of all open invoices in Open Invoices Total Field, Sum of Partially Paid Invoices in Partiall Paid Invoices Total Field and Sum of Fully Paid Invoices in Fully Paid Invoices Total Field. If a status of an Invoice changes from Open to Partially paid then the field total fields should automatically adjust.

 

Can u please guide me for this.....................

                                                                                    Thanks in advance......

 

Hii all, 

I am looking for vf for uploading a file ..I tried and it worked fine but my rquirement  is that i had to take 5 pageblock sections in that each page block section i had to upload a single file my code works fine for one page block section for another it didn't work fine can u guide me the r8 solution

I had also tried with repeat tag by making row="5".. but it didn't work for me ..I'm pasting the code i tried

 

Vf page

------------------------------------------------------------------------------------------------------------------------------------------

<apex:page Controller="sub_FileUploadController" sidebar="false" >

<apex:repeat value="{!userfiledescription}">
<apex:form id="apexform">

<table border="1">

<tr>
<td>


<apex:outputLabel value=""/>
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload File">
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton action="{!page2onLoad1}" value="Add More"/>
</apex:commandButton>
</td></tr>


<tr><td>
<apex:outputLabel value="File Description"/></td>
<td>

<apex:inputtext id="ufdescription" value="{!userfiledescription}" />
</td>
</tr>

</table>


<!--Div Code used to display Progress bar image -->
<div id="display1" width="350">

</div>



<apex:inputhidden id="filetypehidden" value="{!filetype}"/>
<apex:inputhidden id="filesizehidden" value="{!filesize}"/>
<apex:inputhidden id="filenamehidden" value="{!filenamehidden}"/>
<input type="hidden" id="submithidden" value="false"/>

<script type="text/javascript">
function getFileType()
{
try
{
var filetype;
var filename;
var filesizeF;
filetype=document.forms['submitform'].elements['file'].value;
document.getElementById('j_id0:apexform:filenamehidden').value=filetype;
filetype=filetype.substring(filetype.indexOf('.',0)+1,filetype.length);

document.getElementById('j_id0:apexform:filetypehidden').value=filetype;
filename=document.forms['submitform'].elements['key'];

if(filetype!='' || filetype!=null)
{
filename.value=filename.value + '.' + filetype;
}
if(navigator.appName!='Microsoft Internet Explorer')
{
try
{
filesizeF=document.forms['submitform'].elements['file'];
<!-- alert(filesizeF.files[0].fileSize);-->
document.getElementById('j_id0:apexform:filesizehidden').value=filesizeF.files[0].fileSize;
//document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
catch(errr)
{
}
}
else
{
document.getElementById('j_id0:apexform:filesizehidden').value=0;
}


if(document.getElementById('j_id0:apexform:filesizehidden').value!=0 && document.getElementById('j_id0:apexform:filesizehidden').value!='undefined' && document.getElementById('j_id0:apexform:filenamehidden').value!=undefined) {
document.getElementById('submithidden').value='true';
return true;
}
else
{
alert('Unable to capture file details..');
document.getElementById('submithidden').value='false';
return false;
}
}
catch(err)
{
alert(err);
return false;
}
}
function completedfunction()
{

try
{
if(document.getElementById('submithidden').value=='true')
{

<!--Code to display Progress bar image -->
var html = '';
html += '<img src="/resource/1323008320000/LoadingImage">';
html += '</img>'
document.getElementById('display1').innerHTML = html;
<!--Code to display Progress bar image end -->
document.forms['submitform'].submit();

} }
catch(err)
{
alert(err);

}
}

</script>

</apex:form>
</apex:repeat>

<form id="submitform"
action="https://s3.amazonaws.com/{!BucketName}"
method="post" enctype="multipart/form-data">

<input type="hidden" name="AWSAccessKeyId" value="{!key}"/>
<input type="hidden" name="policy" value="{!policy}"/>
<input type="hidden" name="signature" value="{!signedPolicy}"/>
<!-- <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AcctID}" /> -->
<input type="hidden" value="{!Filename}" name="key"/>

<apex:outputLabel value="File to upload"/>
<input id="fileid" type="file" size="50" name="file"/>


</form>



</apex:page>

------------------------------------------------------------------------------------------------------------------------------------------------------------

Apex Code

 

public class sub_FileUploadController{
/*
public PageReference Deletefile() {
DeleteObjectRequest request = new DeleteObjectRequest();

BucketName = bucketName;
Key = FileKey;

S3Response response = s3Client.DeleteObject(request);
return null;
}
*/

public PageReference cancel() {
//string queryChild='SELECT Id,parent__c FROM '+ childName + 'Whereid=:' + AcctId + 'LIMIT 1' ;
// SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
Account_Documents__c A = [SELECT id,parent__c from Account_Documents__c where id=:AcctID];
delete a;
return new PageReference('/'+a.parent__c +'/d?retURL=%2F'+ a.parent__c);
//delete childObject;
//return null;
}


public string secret {get;set;}
public string key { get ;set; }
public string BucketName{get;set;}
public string BucketName1{get;set;}
public String serverURL {get;set;}
public String AcctID {get;set;}
public String AcctID1 {get;set;}
public String userFileName{get;set;}
public String userFileDescription{get;set;}
public String userFileDescription1{get;set;}
public String filenamehidden{get;set;}
public string Filename{get;set;}
public string fileType{get;set;}
public Boolean onemore{get;set;}
public Decimal fileSize{get;set;}
//private String AWSCredentialName = 'tvarana7';



//Variable for 2nd form(apexform1)
public string fileType1{get;set;}
public Decimal fileSize1{get;set;}
public String filenamehidden1{get;set;}
public string Filename1{get;set;}
string filedescriptionAPI1;
string filetypeAPI1;
string filesizeinbytesAPI1;
String filenameAPI1;


string filedescriptionAPI;
string filetypeAPI;
string filesizeinbytesAPI;
String filenameAPI;

datetime expire = system.now().addMinutes(40);
String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+
expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';


string policy { get {return
'{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ BucketName+'" } ,'+

// { "acl": "'+ record.Access__c +'" },'+ '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+
// '{"success_action_redirect": "https://'+serverurl+'/'+AcctID+'"},' +
'["starts-with", "$key", ""] ]}'; } }



public sub_FileUploadController()
{
secret='bXrMni3+SWcWU60QDDI37hNjllWCY3syswO0EFbF';
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
BucketName1='tvarana7';
onemore= False;
}
public String getPolicy() {
return EncodingUtil.base64Encode(Blob.valueOf(policy));
}

public String getSignedPolicy() {
return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy)),secret);
}


//tester
public String getHexPolicy() {
String p = getPolicy();
return EncodingUtil.convertToHex(Blob.valueOf(p));
}


private String make_sig(string canonicalBuffer,string secret) {
String macUrl ;
String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret));
Blob mac = Crypto.generateMac('HMacSHA1',blob.valueof(canonicalBuffer),blob.valueof(secret));
macUrl = EncodingUtil.base64Encode(mac);
return macUrl;
}
public String bucketToList {get;set;}

private String ChildName;

public void page2onLoad()
{
system.debug('ACCTID:'+AcctID);
if(AcctID==null || AcctID=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');



ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');




parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');




serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename=childObject.id;
filedescriptionAPI=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI=Apexpages.currentpage().getparameters().get('FILENAMEAPI');

}
else
{
String selectfields;
if(filedescriptionAPI!='' && filedescriptionAPI!=null){
selectfields=filedescriptionAPI;}
if(filetypeAPI!='' && filetypeAPI!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI;}
else{
selectfields=filetypeAPI;}
}
if(filesizeinbytesAPI!=null && filesizeinbytesAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI;}
else{
selectfields=filesizeinbytesAPI;}
}
if(filenameAPI!='null' && filenameAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI;}
else{
selectfields=filenameAPI;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'');
SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}

if(filenameAPI!='' && filenameAPI!='null'){
filenameAPI=filenameAPI.replace('\'','');
childObject.put(filenameAPI,userFileName);}
if(filedescriptionAPI!='' && filedescriptionAPI!='null'){
filedescriptionAPI=filedescriptionAPI.replace('\'','');
childObject.put(filedescriptionAPI,userFileDescription);}
if(filetypeAPI!='' && filetypeAPI!='null'){
filetypeAPI=filetypeAPI.replace('\'','');
childObject.put(filetypeAPI,filetype);}
if(filesizeinbytesAPI!='null' && filesizeinbytesAPI!=''){
filesizeinbytesAPI=filesizeinbytesAPI.replace('\'','');
childObject.put(filesizeinbytesAPI,(decimal)((fileSize)));}
system.debug('........................filesizeinbytesAPI fileSize........................'+fileSize);

update childObject;
}
}

//second method

public void page2onLoad1(){


onemore=True;
system.debug('ACCTID1:'+AcctID1);
if(AcctID1==null || AcctID1=='')
{

string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];

System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID1=childObject.Id;

serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename1=childObject.id;
filedescriptionAPI1=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI1=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI1=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI1=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
// }
// else
// {
String selectfields;
if(filedescriptionAPI1!='' && filedescriptionAPI1!=null){
selectfields=filedescriptionAPI1;}
if(filetypeAPI1!='' && filetypeAPI1!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI1;}
else{
selectfields=filetypeAPI1;}
}
if(filesizeinbytesAPI1!=null && filesizeinbytesAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI1;}
else{
selectfields=filesizeinbytesAPI1;}
}
if(filenameAPI1!='null' && filenameAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI1;}
else{
selectfields=filenameAPI1;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI1);

system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'');
// SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];

}


else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];}

if(filenameAPI1!='' && filenameAPI1!='null'){
filenameAPI1=filenameAPI1.replace('\'','');
childObject.put(filenameAPI1,userFileName);}
if(filedescriptionAPI1!='' && filedescriptionAPI1!='null'){
filedescriptionAPI1=filedescriptionAPI1.replace('\'','');
childObject.put(filedescriptionAPI1,userFileDescription1);}
if(filetypeAPI1!='' && filetypeAPI1!='null'){
filetypeAPI1=filetypeAPI1.replace('\'','');
childObject.put(filetypeAPI1,filetype1);}
if(filesizeinbytesAPI1!='null' && filesizeinbytesAPI1!=''){
filesizeinbytesAPI1=filesizeinbytesAPI1.replace('\'','');
childObject.put(filesizeinbytesAPI1,(decimal)((fileSize1)));}
system.debug('........................filesizeinbytesAPI1 fileSize1........................'+fileSize1);

update childObject;
}
}

//second method end

public static testmethod void testuplod(){
PageReference pageRef = Page.sub_FileUpload;
Account a=new Account();
a.name='Test';
insert a;
pageRef.getParameters().put('id',a.id);
pageRef.getParameters().put('ParentObjecName','Account');
pageRef.getParameters().put('ChildObjectName','tva__Account_documents__c');
pageRef.getParameters().put('ParentRefName','tva__Parent__c');
pageRef.getParameters().put('serverURL','https://na12.salesforce.com/services/Soap/c/12.0/00DU0000000Hg3A');
pageRef.getParameters().put('FILETYPEAPI','tva__file_type__c');
pageRef.getParameters().put('FILEDESCRIPTIONAPI','tva__file_description__c');
pageRef.getParameters().put('FILESIZEINBYTESAPI','tva__File_Size_in_Bytes__c');
pageRef.getParameters().put('FILENAMEAPI','tva__file_name__c');

sub_FileUploadController fp = new sub_FileUploadController();
Test.setCurrentPage(pageRef);
System.debug(fp.Policy);
System.debug(fp.getSignedPolicy());
System.debug(fp.getHexPolicy());
fp.page2onLoad();
fp.filesize=100000;
fp.page2onLoad();
}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

Hope i'll get a solution for this

Thanks in Advance

Hii all ,

I have the requirement that i have 5 pageblock section  such that each pageblocksection  contains the all feilds and the entire page contains only one save button such that i have to insert the all the fields

i'm giving the code can u get me the correct approach for the code

 

 

<apex:page controller="file2">
<apex:form >
<apex:pageBlock >

<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>

<apex:pageBlockTable value="{!f1}" var="f" id="form1">

<apex:column headerValue="Name">
<apex:inputField value="{!f.Name}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!f.Description__c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!f1}" var="f" id="form2" >

<apex:column headerValue="Name">
<apex:inputField value="{!f.Name}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!f.Description__c}"/>
</apex:column>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>
</apex:page>

 

 

controller

-----------------------------------

public with sharing class file2 {

public file2() {
f1 = new List<File__c>();
f1.add(new File__c());

}


public List<File__c> f1 {get; set;}

public PageReference save()
{
insert f1;

return null;
}
}

 

Hii All,

I have Scenario

that i made custom fireld

DATA Type:picklist

Field:Days__c

values{MOn,Tue,Wed,Thu,Fri,Sat,Sun]

and i have to get the o/p as Name :Mike NUmber of  working daysDays :4

 

 

public with sharing class Workdays

{

  public Workdays() {  }

 Account a = new Account();

 List<Account> a1; 

public list<Account> getAcclist()

 {  return a1; }

 public PageReference Attendance()

 {

 a1=[select count(id),name,Days__c from Account where name=:a.name Group by Days__c];

 public Account getAccount() {  return a; }

 

}

and i'm getting ERror:ErrorError: Compile Error: Field must be grouped or aggregated: Name at line 14 column 6

 

can u plz guide how to apply group by function for this code

Thanks in Advance