function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StaciStaci 

copying existing case information to new case through apex class

I have a button that needs to take certain fields from an existing case, create a new case with a different record type and those certain fields .  I also want a pop-up to require 5 fields to be re-filled in with different information.  I have this half way working, but I don't quite know how to make the existing case information be put into the new case.  Any help would be greatly appreciated!

Class
public class CW_recurringIncident
{
public Boolean isDisplayPopUp {get; set;}
public CW_recurringIncident(ApexPages.StandardController controller)
{
isDisplayPopUp = true;
{Case c = (Case) controller.getRecord(); c.Status = 'New'; c.RecordTypeId = '012e00000004RxS';}

}
}

Page
<apex:page standardController="Case" extensions="CW_recurringIncident">
<apex:form id="frm">
<apex:detail subject="{!Case.Id}" relatedList="false" title="false"/>
<apex:outputPanel id="tstpopup" rendered="{!IF(isDisplayPopUp ==true,true,false)}" >
<apex:outputPanel styleClass="popupBackground" layout="block" />
<apex:outputPanel styleClass="custPopup" layout="block">
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField label="Incident First Response" value="{!Case.Incident_First_Response__c}"  required="true"/>
<apex:inputField label="Incident Start" value="{!Case.Incident_Start__c}" onclick="" required="true"/>
<apex:inputField label="Service Restored" value="{!Case.Incident_Resolved__c}" onclick="" required="true"/>
<apex:inputField label="Defect Type" value="{!Case.Defect_Type_Multi__c}" required="true"/>
<apex:inputField label="Service Restoration Description" value="{!Case.Service_Restoration__c}" onclick="" required="true"/>

<apex:outputPanel >
<apex:CommandButton action="{!save}" value="Save"/>
<apex:CommandButton action="{!cancel}" value="Cancel"/>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:outputPanel>





</apex:form>



<style type="text/css"> .errorMsg{ width:159px; }
.custPopup{ background-color: white; border-width: 3px;
border-style: solid;
z-index: 9999;
left: 25%;
padding:10px;
position: absolute;
width: 1000px;
//margin-left: -80px; top:100px; margin-left: -170px;
//top:305px;
border-radius: 5px;
}

.datePicker{z-index:10000}



.popupBackground{ background-color:black; opacity: 0.20; filter: alpha(opacity = 20);
position: absolute; width: 100%; height: 100%; top: 0; left: 0;
z-index: 997 } a.actionlink:hover{ text-decoration:underline; }
.customactionLink { color: #015BA7; font-weight: normal; text-decoration: none; } </style>

<script>
      function setFocusOnLoad() { }
</script>
</apex:page>
Best Answer chosen by Staci
Abhi__SFDCAbhi__SFDC
Try below code, for those 5 fields if you want to show the information from the existing case, you need to 
get the value from the url like -: 
System.currentPageReference().getParameters().get('00N90000002uuWB'); //  00N90000002uuWB >>  ID of the inputfield
 
then use that in standardcontroller Case c -: 

public class CW_recurringIncident
{
public Boolean isDisplayPopUp {get; set;}
public string param;
public CW_recurringIncident(ApexPages.StandardController controller)
{

{
if(System.currentPageReference().getParameters().get('00N90000002uuWB') <> null ){

param = System.currentPageReference().getParameters().get('00N90000002uuWB');

}


Case c = (Case) controller.getRecord(); c.Status = 'New'; c.RecordTypeId = '01290000000NeEm'; c.EngineeringReqNumber__c=param ;}
isDisplayPopUp = true;
}
}

Its working for me. Let me know if you get any issues.

All Answers

Abhi__SFDCAbhi__SFDC
In your Button URL, you can pass the info from existing case to the new case.

If my New Case button opens up a VF page. In the url of my button i will pass the info like 

/apex/VFPAGE?acc2={!Account.name} (Grabbing the InputElement Id from the pagesource (inspect element)) acc2 is account name field. 

This will open a new account VF page with Name as previous account name 

SO whatever info you want to pass into other fields , get the inputid and pass that in the url.

Let me know if you get any issues.


StaciStaci
Thanks Abhi, That kinda worked.  The pop-up still needs to show up.  How can I add that in?  here's the new URL button:

/apex/CW_Recurring_Incident?retURL={!Case.Id}&RecordType=012e00000004RxSAAU&00N30000006aSCK={!Case.Product__c}&00N30000006aSCE={!Case.Application__c}&00N30000006aSCF={!Case.Component__c}&00N30000006aSCN={!Case.Subsystem__c}&00Na0000009yTvW={!Case.Additional_email_1__c}&00Na0000009yTvX={!Case.Additional_email_2__c}&00Na0000009zDPm={!Case.Impact__c}&00Na0000009zDPp={!Case.Urgency__c}&cas6={!Case.Reason}&cas14={!Case.Subject}&cas3={!Case.Contact}&00Na0000009zDPj={!Case.CW_Type__c}&cas15={!Case.Description}&cas4={!Case.Account}&cas28={!Case.CaseNumber}&00N30000006aSCH={!Case.Implementation__c}&00N30000007Pq9o={!Case.Machine_ID__c}&00Ne0000000illW={!Case.Machine_Model__c}
Abhi__SFDCAbhi__SFDC
Try below code, for those 5 fields if you want to show the information from the existing case, you need to 
get the value from the url like -: 
System.currentPageReference().getParameters().get('00N90000002uuWB'); //  00N90000002uuWB >>  ID of the inputfield
 
then use that in standardcontroller Case c -: 

public class CW_recurringIncident
{
public Boolean isDisplayPopUp {get; set;}
public string param;
public CW_recurringIncident(ApexPages.StandardController controller)
{

{
if(System.currentPageReference().getParameters().get('00N90000002uuWB') <> null ){

param = System.currentPageReference().getParameters().get('00N90000002uuWB');

}


Case c = (Case) controller.getRecord(); c.Status = 'New'; c.RecordTypeId = '01290000000NeEm'; c.EngineeringReqNumber__c=param ;}
isDisplayPopUp = true;
}
}

Its working for me. Let me know if you get any issues.
This was selected as the best answer
StaciStaci
Abhi, thank you! that works great!  One question, how do I declare standard fields like Account and Contact Name from the cases object?  If I add it like the others here it tells me illegal assignment of string to sobject