You need to sign in to do that
Don't have an account?

create case, cancel still creates new case
I have a button that I need to create a case, but render the edit page of that new case, but if cancel is clicked its still creating the new case. I can't quite figure out how to accomplish this altogether. Please help!
Button:
/apex/CW_MAMtoIncident?caseID={!Case.Id}&retURL={!Case.Id}
Page: <apex:page standardController="Case" extensions="CW_MAMtoIncident" action="{!autorun}">
</apex:page>
Class:
public class CW_MAMtoIncident{
public Case caseID;
public Case newCase{get;set;}
public CW_MAMtoIncident(ApexPages.StandardController controller) {
}
public pageReference autorun(){
caseID = [SELECT Site_Code__c, Id FROM Case WHERE Id = :ApexPages.currentPage().getParameters().get('caseID')];
Case newCase = new Case(Id = ApexPages.currentPage().getParameters().get('newid'));
newCase.RecordTypeId = '01230000000uzis';
newCase.ParentId = caseID.Id;
if(caseID.Site_Code__c == 'CAR')
{
newCase.AccountId = 'xxxxxxxxxxxxxxxxxx';
}else{
if(caseID.Site_code__c == '')
{
newCase.AccountId = '';
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
//insert newCase;
PageReference retPage = new PageReference('/' + newCase.Id + '/e' );
return retPage;
}
}
Button:
/apex/CW_MAMtoIncident?caseID={!Case.Id}&retURL={!Case.Id}
Page: <apex:page standardController="Case" extensions="CW_MAMtoIncident" action="{!autorun}">
</apex:page>
Class:
public class CW_MAMtoIncident{
public Case caseID;
public Case newCase{get;set;}
public CW_MAMtoIncident(ApexPages.StandardController controller) {
}
public pageReference autorun(){
caseID = [SELECT Site_Code__c, Id FROM Case WHERE Id = :ApexPages.currentPage().getParameters().get('caseID')];
Case newCase = new Case(Id = ApexPages.currentPage().getParameters().get('newid'));
newCase.RecordTypeId = '01230000000uzis';
newCase.ParentId = caseID.Id;
if(caseID.Site_Code__c == 'CAR')
{
newCase.AccountId = 'xxxxxxxxxxxxxxxxxx';
}else{
if(caseID.Site_code__c == '')
{
newCase.AccountId = '';
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
//insert newCase;
PageReference retPage = new PageReference('/' + newCase.Id + '/e' );
return retPage;
}
}
You are calling Autorun method on page load. In Autorun you have written case creation login which is running on load of page.
So while loading of the page itself your case is creating.
Button:
/500/e?retURL={!Case.Id}&{!Case.RecordTypeId}=01230000000uzis&cas28_lkid={!Case.Id}&cas28={!Case.CaseNumber}&saveURL=/apex/CW_MAMtoIncident?caseID={!Case.Id}
Class:
public class CW_MAMtoIncident{
public Case caseID;
public CW_MAMtoIncident(ApexPages.StandardController controller) {
}
public pageReference autorun(){
caseID = [SELECT Site_Code__c, Id FROM Case WHERE Id = :ApexPages.currentPage().getParameters().get('caseID')];
//Carlin
//Case newCase = new Case();
//newCase.RecordTypeId = '01230000000uzis';
//newCase.ParentId = caseID.Id;
Case newCase = new Case(Id = ApexPages.currentPage().getParameters().get('newid'));
if(caseID.Site_Code__c == 'CAR')
{
newCase.AccountId = '001e000000AtHDo';
}else{
if(caseID.Site_code__c == '')
{
newCase.AccountId = '';
}}/*}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}*/
update newCase;
PageReference retPage = new PageReference('/' + newCase.Id + '/e');
return retPage;
}
}