+ Start a Discussion
Anil DuttAnil Dutt 

Override New and Edit with VF Page

Hi,

I have override New and Edit buttons to use Visual Force page for Custom Object Itinerary
and VF Page uses following class as Extension {extensions="ItinerarySave"}
public class ItinerarySave {

   Itinerary__c it;
  Opportunity opp;
  public ItinerarySave(ApexPages.StandardController stdController)
    {
       it = (Itinerary__c)stdController.getRecord();
       if(it.Id != null )
        {
            it = [SELECT id , Email_To__c,Opportunity__c FROM Itinerary__c WHERE Id = :it.Id];
        }
        opp = [SELECT id , Email__c FROM Opportunity WHERE Id = :it.Opportunity__c];
     if (it.Email_To__c == null)
      {
         it.Email_To__c = opp.Email__c;
      }
    }
    public PageReference Save()
    {
       if(it.Id != null)
       {
             update it;
       }
       else
       {
          insert it;       

      }
       PageReference pr = new PageReference('/'+  it.Opportunity__c);
       pr.setRedirect(true);
       return pr;
    }
}

But record not update, insert working fine

Please help me on this how to fix

Thanks

VKrishVKrish

Try to put debug statements for each variable. May the values are not passed from VF page to controller.

Is this your full code? I dont see any get() set() methods for the variables. If you forgot it add something like

String it {get;set;}

for the variables you are trying to get from VF page.

 

Also I more big bug I am seeing is you are trying to insert when there is already Id present (ie., when already you have record)

It should be opposite something like...

if(it.Id == null) insert it;

else update it;

Anil DuttAnil Dutt

Hi VKrish

 

I edited my question ,

 

but still not gettng it to update record, insert working fine

VKrishVKrish

Did you try your system debug stmts? Is there a try catch block in your original code?

Try to use debug stmts for variables that are passed from VF page, before updating, after updating, in catch block etc.

If so, you would've got the reason why it is failing.

May be the id is not passed to the update querry.

nagalakshminagalakshmi

Hi Anil,

 

Take another id type for storing the current Itinerary__c id. And check current id is getting in id type or not through system log. And do the same procedure.....

 

Thanks