+ Start a Discussion
azar khasimazar khasim 

I want an Controller Class for this Visualforce Page please help me

I just want a Controller Class for the Below Visualforce Page.
Please Help me in it.

Here below is my VF Page.


<apex:page controller="Booking_Link__c">
    <apex:form >
        <apex:sectionHeader title="Person Customer Edit" subtitle="New Customer"/>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Customer Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking link__c.Name}"/>
                <apex:inputField value="{!booking link__c.Salutation__c}"/>
                <apex:inputField value="{!booking link__c.First_Name__c}"/>
                <apex:inputField value="{!booking link__c.Middle_Name__c}"/>
                <apex:inputField value="{!booking link__c.Last_Name__c}"/>
                <apex:inputField value="{!booking link__c.Gender__c}"/>
                <apex:inputField value="{!booking link__c.Relation__c}"/>
                <apex:inputField value="{!booking link__c.Father_Husband__c}"/>
                <apex:inputField value="{!booking link__c.    Pan_Number__c}"/>
                <apex:inputField value="{!booking link__c.    Aadhar_Number__c}"/>
                <apex:inputField value="{!booking link__c.Date_Of_Birth__c}"/>
                <apex:inputField value="{!booking link__c.Wedding_Anniversary__c}"/>
                <apex:inputField value="{!booking link__c.Mobile__c}"/>
                <apex:inputField value="{!booking link__c.Alternate_Mobile__c}"/>
                <apex:inputField value="{!booking link__c.Phone__c}"/>
                <apex:inputField value="{!booking link__c.Other_Phone__c}"/>
                <apex:inputField value="{!booking link__c.Home_Phone__c}"/>
                <apex:inputField value="{!booking link__c.Email__c}"/>  
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Professional Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking link__c.Profession__c}"/>
                <apex:inputField value="{!booking link__c.Designation__c}"/>
                <apex:inputField value="{!booking link__c.Professional_Email__c}"/>
                <apex:inputField value="{!booking link__c.Annual_Income__c}"/>
                <apex:inputField value="{!booking link__c.CompanyMobile__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Office Address" collapsible="false" columns="2">
                <apex:inputField value="{!booking link__c.Employed_by__c}"/>
                <apex:inputField value="{!booking link__c.OfficeStreet__c}"/>
                <apex:inputField value="{!booking link__c.OfficeCity__c}"/>
                <apex:inputField value="{!booking link__c.OfficeState__c}"/>
                <apex:inputField value="{!booking link__c.OfficeCountry__c}"/>
                <apex:inputField value="{!booking link__c.OfficePinCode__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Children School Address" collapsible="false" columns="2">
                <apex:inputField value="{!booking link__c.School_Name__c}"/>
                <apex:inputField value="{!booking link__c.SchoolStreet__c}"/>
                <apex:inputField value="{!booking link__c.SchoolCity__c}"/>
                <apex:inputField value="{!booking link__c.SchoolState__c}"/>
                <apex:inputField value="{!booking link__c.SchoolCountry__c}"/>
                <apex:inputField value="{!booking link__c.SchoolPinCode__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Address Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking link__c.BillingCountry__c}"/>
                <apex:inputField value="{!booking link__c.ShippingCountry__c}"/>
                <apex:inputField value="{!booking link__c.BillingStreet__c}"/>
                <apex:inputField value="{!booking link__c.ShippingStreet__c}"/>
                <apex:inputField value="{!booking link__c.BillingCity__c}"/>
                <apex:inputField value="{!booking link__c.ShippingCity__c}"/>
                <apex:inputField value="{!booking link__c.BillingState__c}"/>
                <apex:inputField value="{!booking link__c.ShippingState__c}"/>
                <apex:inputField value="{!booking link__c.BillingPinCode__c}"/>
                <apex:inputField value="{!booking link__c.ShippingPinCode__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Best Answer chosen by azar khasim
Khan AnasKhan Anas (Salesforce Developers) 
Hi Azar,

Greetings to you!

Please change the controller name from Booking_Link__c, don't use object name as a controller name. As Sunil suggested, use a different property name in visualforce page instead of booking_Link__c

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="BookingController">
    <apex:form >
        <apex:sectionHeader title="Person Customer Edit" subtitle="New Customer"/>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Customer Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking.Name}"/>
                <apex:inputField value="{!booking.Salutation__c}"/>
                <apex:inputField value="{!booking.First_Name__c}"/>
                <apex:inputField value="{!booking.Middle_Name__c}"/>
                <apex:inputField value="{!booking.Last_Name__c}"/>
                <apex:inputField value="{!booking.Gender__c}"/>
                <apex:inputField value="{!booking.Relation__c}"/>
                <apex:inputField value="{!booking.Father_Husband__c}"/>
                <apex:inputField value="{!booking.Pan_Number__c}"/>
                <apex:inputField value="{!booking.Aadhar_Number__c}"/>
                <apex:inputField value="{!booking.Date_Of_Birth__c}"/>
                <apex:inputField value="{!booking.Wedding_Anniversary__c}"/>
                <apex:inputField value="{!booking.Mobile__c}"/>
                <apex:inputField value="{!booking.Alternate_Mobile__c}"/>
                <apex:inputField value="{!booking.Phone__c}"/>
                <apex:inputField value="{!booking.Other_Phone__c}"/>
                <apex:inputField value="{!booking.Home_Phone__c}"/>
                <apex:inputField value="{!booking.Email__c}"/>  
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Professional Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking.Profession__c}"/>
                <apex:inputField value="{!booking.Designation__c}"/>
                <apex:inputField value="{!booking.Professional_Email__c}"/>
                <apex:inputField value="{!booking.Annual_Income__c}"/>
                <apex:inputField value="{!booking.CompanyMobile__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Office Address" collapsible="false" columns="2">
                <apex:inputField value="{!booking.Employed_by__c}"/>
                <apex:inputField value="{!booking.OfficeStreet__c}"/>
                <apex:inputField value="{!booking.OfficeCity__c}"/>
                <apex:inputField value="{!booking.OfficeState__c}"/>
                <apex:inputField value="{!booking.OfficeCountry__c}"/>
                <apex:inputField value="{!booking.OfficePinCode__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Children School Address" collapsible="false" columns="2">
                <apex:inputField value="{!booking.School_Name__c}"/>
                <apex:inputField value="{!booking.SchoolStreet__c}"/>
                <apex:inputField value="{!booking.SchoolCity__c}"/>
                <apex:inputField value="{!booking.SchoolState__c}"/>
                <apex:inputField value="{!booking.SchoolCountry__c}"/>
                <apex:inputField value="{!booking.SchoolPinCode__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Address Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking.BillingCountry__c}"/>
                <apex:inputField value="{!booking.ShippingCountry__c}"/>
                <apex:inputField value="{!booking.BillingStreet__c}"/>
                <apex:inputField value="{!booking.ShippingStreet__c}"/>
                <apex:inputField value="{!booking.BillingCity__c}"/>
                <apex:inputField value="{!booking.ShippingCity__c}"/>
                <apex:inputField value="{!booking.BillingState__c}"/>
                <apex:inputField value="{!booking.ShippingState__c}"/>
                <apex:inputField value="{!booking.BillingPinCode__c}"/>
                <apex:inputField value="{!booking.ShippingPinCode__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class BookingController {
    
    public Booking_Link__c booking {get;set;}
    
    public BookingController(){
        booking = new Booking_Link__c();
    }
    
    public PageReference save(){
        try {  
            INSERT booking;
        }
        catch (Exception e) {
            ApexPages.addMessages (e);
            return null;
        }
        PageReference pr = new ApexPages.StandardController(booking).view();
        return pr;
    }
    
    public void cancel(){
        booking = new Booking_Link__c();
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Sunil RathoreSunil Rathore
Hi,
Please refer the below code:
public class Booking_Link__c {

    public Booking_Link__c objBillingLink { get;  set; }

    public NewAndExistingController() {
		objBillingLink = new Booking_Link__c();
    }

    public PageReference save() {
        try {
            insert objBillingLink
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        //  After successful Save, navigate to the default view page
        PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
        return (redirectSuccess);
    }
	public PageReference cancel() {
	 PageReference reRend = new PageReference('/apex/yourpagename');
        reRend.setRedirect(true);
        return reRend;
	}
}

With this controller, you have to use objBillingLink in the VF page instead of booking link__c. Like:
<apex:inputField value="{!objBillingLink .Name}"/>
 replace all the booking link__c refernce with objBillingLink.

Hope this will help you, if yes then please mark it as best answer so that it can also help others.

Many Thanks,
Sunil Rathore
Khan AnasKhan Anas (Salesforce Developers) 
Hi Azar,

Greetings to you!

Please change the controller name from Booking_Link__c, don't use object name as a controller name. As Sunil suggested, use a different property name in visualforce page instead of booking_Link__c

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="BookingController">
    <apex:form >
        <apex:sectionHeader title="Person Customer Edit" subtitle="New Customer"/>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Customer Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking.Name}"/>
                <apex:inputField value="{!booking.Salutation__c}"/>
                <apex:inputField value="{!booking.First_Name__c}"/>
                <apex:inputField value="{!booking.Middle_Name__c}"/>
                <apex:inputField value="{!booking.Last_Name__c}"/>
                <apex:inputField value="{!booking.Gender__c}"/>
                <apex:inputField value="{!booking.Relation__c}"/>
                <apex:inputField value="{!booking.Father_Husband__c}"/>
                <apex:inputField value="{!booking.Pan_Number__c}"/>
                <apex:inputField value="{!booking.Aadhar_Number__c}"/>
                <apex:inputField value="{!booking.Date_Of_Birth__c}"/>
                <apex:inputField value="{!booking.Wedding_Anniversary__c}"/>
                <apex:inputField value="{!booking.Mobile__c}"/>
                <apex:inputField value="{!booking.Alternate_Mobile__c}"/>
                <apex:inputField value="{!booking.Phone__c}"/>
                <apex:inputField value="{!booking.Other_Phone__c}"/>
                <apex:inputField value="{!booking.Home_Phone__c}"/>
                <apex:inputField value="{!booking.Email__c}"/>  
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Professional Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking.Profession__c}"/>
                <apex:inputField value="{!booking.Designation__c}"/>
                <apex:inputField value="{!booking.Professional_Email__c}"/>
                <apex:inputField value="{!booking.Annual_Income__c}"/>
                <apex:inputField value="{!booking.CompanyMobile__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Office Address" collapsible="false" columns="2">
                <apex:inputField value="{!booking.Employed_by__c}"/>
                <apex:inputField value="{!booking.OfficeStreet__c}"/>
                <apex:inputField value="{!booking.OfficeCity__c}"/>
                <apex:inputField value="{!booking.OfficeState__c}"/>
                <apex:inputField value="{!booking.OfficeCountry__c}"/>
                <apex:inputField value="{!booking.OfficePinCode__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Children School Address" collapsible="false" columns="2">
                <apex:inputField value="{!booking.School_Name__c}"/>
                <apex:inputField value="{!booking.SchoolStreet__c}"/>
                <apex:inputField value="{!booking.SchoolCity__c}"/>
                <apex:inputField value="{!booking.SchoolState__c}"/>
                <apex:inputField value="{!booking.SchoolCountry__c}"/>
                <apex:inputField value="{!booking.SchoolPinCode__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Address Information" collapsible="false" columns="2">
                <apex:inputField value="{!booking.BillingCountry__c}"/>
                <apex:inputField value="{!booking.ShippingCountry__c}"/>
                <apex:inputField value="{!booking.BillingStreet__c}"/>
                <apex:inputField value="{!booking.ShippingStreet__c}"/>
                <apex:inputField value="{!booking.BillingCity__c}"/>
                <apex:inputField value="{!booking.ShippingCity__c}"/>
                <apex:inputField value="{!booking.BillingState__c}"/>
                <apex:inputField value="{!booking.ShippingState__c}"/>
                <apex:inputField value="{!booking.BillingPinCode__c}"/>
                <apex:inputField value="{!booking.ShippingPinCode__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class BookingController {
    
    public Booking_Link__c booking {get;set;}
    
    public BookingController(){
        booking = new Booking_Link__c();
    }
    
    public PageReference save(){
        try {  
            INSERT booking;
        }
        catch (Exception e) {
            ApexPages.addMessages (e);
            return null;
        }
        PageReference pr = new ApexPages.StandardController(booking).view();
        return pr;
    }
    
    public void cancel(){
        booking = new Booking_Link__c();
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
azar khasimazar khasim
Hi Sunil,

Thank You, Sunil your suggestion was nice. I will definitely remember these things.
azar khasimazar khasim
Hi Khan Anas,

Thank You for your Controller Code, and it was a great thing to backup the members of the community with their ideas.
You are really a Humble Person with great Attitude. I will definitely remember this one for sure.

Thank You so much

With Regards,
Azar Khasim.
Sunil RathoreSunil Rathore
Hi Azar,

You are always welcome!!!

If it solves your problem then please mark it a solved/best answer so it may also help others in the future.

Many Thanks,
Sunil Rathore
azar khasimazar khasim
Actually, I was unable to give the best answer because both Codes are working absolutely fine.
  • For my interest, Both the Answers are the Best Answers.
  • But there is only one to choose the Best Answer.

So for that, I was giving to Khan Anas because it has both Controller class and Visualforce Page also.

So in the future, it will help the remaining customers to get the data fully without a doubt.