You need to sign in to do that
Don't have an account?
Luca Benedettini 7
Apex Controller Exstention and action
Hi eveyone. I'm writing a VF page with a controller exstention and i have 2 problems. In my page when you fill the field Merge To Case and click Merge all the attachments of one case need to be reparented.
First Problem Am I passing Merge_To_Case in the right way between VF and CaseControllerExstention.
Second When i click on merge button , it's seems to do nothing and I don't understand why.
I hope you can help me.Here my code:
VF page:
<apex:page standardController="Case" extensions="CaseMergeExtension" showHeader="true" sidebar="false">
<apex:form >
<apex:actionfunction name="MergeCase" action="MergeCase" >
<apex:param name="Casetomerge" value="" assignTo="{!Case.Merge_To_Case__c}" />
</apex:actionFunction>
<apex:sectionHeader description="Case Merging Page" title="Case">
</apex:sectionHeader>
<apex:pageBlock title="Case To BE Merged {!Case.CaseNumber}">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Merge" onClick="MergeCase('{!Case.Merge_To_Case__c}')" />
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="FondereCasi">Merge To Case</apex:outputLabel>
<apex:inputField id="FondereCasi" value="{!Case.Merge_To_Case__c}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<br/><br/><h1>ATTENTION !</h1>
<p><b>When you click Merge button the case {!Case.CaseNumber} will be merge with {!Case.Merge_To_Case__c}</b></p>
</apex:pageBlock>
</apex:form>
<!-- End Default Content REMOVE THIS -->
</apex:page>
and here the Apex Exstension Controller:
public class CaseMergeExtension {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public Case caso{get;set;}
public CaseMergeExtension(ApexPages.StandardController stdcontroller) {
this.caso = (Case)stdController.getRecord();
}
//pass Merge_To_Case__c from VF page in Casetomerge variable
public String Casetomerge{get;set;}
//function used to merge Case and case referenced by Merge_To_Case__c field
public void MergeCase(){
//take the ID of Case referende By Merge_To_Case__c field and put it in CaseIDF variable
Map<Id, Case> CaseMap = new Map<Id, Case>([
SELECT Id
FROM case
where CaseNumber=: 'Casetomerge']);
List<Id> CaseId= new List<Id>(CaseMap.keySet());
Id CaseIDF=CaseId.get(0);
//Create a List of all Attachment from caso Object, that need to be reparented
Map<id,List<Attachment>> AttachMap=new Map<Id,List<Attachment>>();
for(Case cs:[select id, (select id from attachments) from case where ID=:caso.Id]){
AttachMap.put(cs.id,cs.attachments);
}
List<Attachment> attach= AttachMap.get(caso.Id);
//reparent all the Attachemnts fro caso to the Case referenced by Merge_To_Case__c field
for(Attachment a:attach ){
a.parentid=CaseIDF;
}
update caso;
}
}
First Problem Am I passing Merge_To_Case in the right way between VF and CaseControllerExstention.
Second When i click on merge button , it's seems to do nothing and I don't understand why.
I hope you can help me.Here my code:
VF page:
<apex:page standardController="Case" extensions="CaseMergeExtension" showHeader="true" sidebar="false">
<apex:form >
<apex:actionfunction name="MergeCase" action="MergeCase" >
<apex:param name="Casetomerge" value="" assignTo="{!Case.Merge_To_Case__c}" />
</apex:actionFunction>
<apex:sectionHeader description="Case Merging Page" title="Case">
</apex:sectionHeader>
<apex:pageBlock title="Case To BE Merged {!Case.CaseNumber}">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Merge" onClick="MergeCase('{!Case.Merge_To_Case__c}')" />
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="FondereCasi">Merge To Case</apex:outputLabel>
<apex:inputField id="FondereCasi" value="{!Case.Merge_To_Case__c}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<br/><br/><h1>ATTENTION !</h1>
<p><b>When you click Merge button the case {!Case.CaseNumber} will be merge with {!Case.Merge_To_Case__c}</b></p>
</apex:pageBlock>
</apex:form>
<!-- End Default Content REMOVE THIS -->
</apex:page>
and here the Apex Exstension Controller:
public class CaseMergeExtension {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public Case caso{get;set;}
public CaseMergeExtension(ApexPages.StandardController stdcontroller) {
this.caso = (Case)stdController.getRecord();
}
//pass Merge_To_Case__c from VF page in Casetomerge variable
public String Casetomerge{get;set;}
//function used to merge Case and case referenced by Merge_To_Case__c field
public void MergeCase(){
//take the ID of Case referende By Merge_To_Case__c field and put it in CaseIDF variable
Map<Id, Case> CaseMap = new Map<Id, Case>([
SELECT Id
FROM case
where CaseNumber=: 'Casetomerge']);
List<Id> CaseId= new List<Id>(CaseMap.keySet());
Id CaseIDF=CaseId.get(0);
//Create a List of all Attachment from caso Object, that need to be reparented
Map<id,List<Attachment>> AttachMap=new Map<Id,List<Attachment>>();
for(Case cs:[select id, (select id from attachments) from case where ID=:caso.Id]){
AttachMap.put(cs.id,cs.attachments);
}
List<Attachment> attach= AttachMap.get(caso.Id);
//reparent all the Attachemnts fro caso to the Case referenced by Merge_To_Case__c field
for(Attachment a:attach ){
a.parentid=CaseIDF;
}
update caso;
}
}