+ Start a Discussion
SFDC n12SFDC n12 

New case creation help needed

Hi,

I am having a requirement for which i need help


1) I am  having a text box and a custom button in my visualforce page which is creating a lead record

2) When i enter the values and hit the button a new case has to be created and atttached to the corresponding lead that is created

Help me how to do this

my controller:

public class AF_ScriptController {
  
    public String status {get;set;}
    public Lead_Object__c obj {get; set; }
    public Case caseRecord {get; set;}

   /**
   ** Constructor
   **/
   public AF_ScriptController (ApexPages.StandardController controller) {
 
      String newId = ApexPages.currentPage().getParameters().get('leadId');
      System.debug ('new Id *** :' + newId);

      if (newId != '') {
         obj = [Select Id,First_Name__c,Last_Name__c,Dealer_Type__c,Products_Dealership__c,F_I_Manager__c,Contracts_Electronically__c,Dealer_Track_RouteOne__c,What_percent_of_inventory_has_a_selling__c,What_percent_of_your_inventory_has_less__c,What_percent_of_your_inventory_is_newer__c,How_many_front_line_ready_units_do_you_c__c,What_are_your_average_monthly_used_vehic__c,Service_Department_on_site__c,Dealership_Retail__c,Dealership_Permanent_Building__c,Dealership_Payed__c,How_many_years_have_you_been_in_business__c,Leadstatus__c, test__c, salutation__c  from Lead_Object__c where id = :newId limit 1];
        
         if (obj.LeadStatus__c == 'Qualified' ) {
            System.debug ('Qualified *** : ' + status);
            status = System.Label.AF_QualifiedScript;
         }
         else {
            status = System.Label.AF_UnqualifiedScript;
            System.debug ('UnQualified *** :' + status);
         }
        
      
  
      }
     



   }
  
      public PageReference createNewCase(){

         Case cs = new case();
         cs.subject ='Lead Override Requested';
         insert cs;
       return new PageReference('/apex/AF_Flow?leadid=' + lead.id);

   }}


VF PAGE :


<apex:page standardController="Lead_Object__c" extensions="AF_ScriptController" >

<apex:pageBlock title="Comments Section" rendered="{!obj.Leadstatus__c == 'Unqualified'}">

          <b> <apex:outputLabel value="Lead Override Comments"  rendered="{!obj.Leadstatus__c == 'Unqualified'}" style="color:brown"/></b>

          <b> <apex:inputText   style="width: 270px; height: 100px;" required="true"/></b>

     <center> <b>  <apex:commandButton action="{!createNewCase}" value="Submit Lead Override" id="theButton"/></b></center>
      </apex:pageBlock>



Help me how to do this , am i doing wrong

Thanks in advance





    








anuragsinghnsanuragsinghns
How are you associating the case with the lead do you have a lookup?If so you need to pass the lead Id in that field.
Ex
Lookupfield__c=lead.ID
Sumitkumar_ShingaviSumitkumar_Shingavi
I believe, below line
return new PageReference('/apex/AF_Flow?leadid=' + lead.id);
should be
return new PageReference('/apex/AF_Flow?leadid=' + newId);