[Salesforce] - Create record for different objects from same Page Layout 




Code for Visualforce page - 
<apex:page controller="StudTeachUpdate">
<apex:form >
<apex:pageblock >
<apex:pageblockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageblockButtons>
<apex:pageblockSection title="Student">
<apex:inputField value="{!stud.Student_Name__c}"/>
<apex:inputField value="{!stud.Email_Id__c}"/>
<apex:inputField value="{!stud.Country__c}"/>

</apex:pageblockSection>

<apex:pageblockSection title="Professor">
<apex:inputField value="{!prof.Name}"/>
<apex:inputfield value="{!prof.Email_id__c}"/>
</apex:pageblockSection>

</apex:pageblock>
  </apex:form>
</apex:page>


Code for Controller - 
public class StudTeachUpdate {

public Student__c stud{get;set;}
public Professor__c prof{get;set;}

    public StudTeachUpdate ()
    {
        stud= new Student__c ();
        prof = new Professor__c();

    }
public pagereference save()
{
insert stud;
insert prof;

return null;
}

}
[Salesforce] - A Simple Visualforce Code to create a Pdf of a record
Code -

<apex:page StandardController="Account" renderAs="PDF">
  <apex:pageBlock >
  <apex:pageBlockTable value="{!Account.Contacts}" var="Con" style="border:1px solid;" cellpadding="6px">

  <apex:column headerValue="Name">
  {!Con.name}
  </apex:column>

  <apex:column headerValue="Title">
  {!Con.Title}
  </apex:column>

  <apex:column headerValue="Email">
  {!Con.email}
  </apex:column>

  </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

Creating a Simple Visualforce Page - For Beginners

Creating a Simple Visualforce Page - For Beginners





Code - 

<apex:page standardController="Student_new__c">
  <apex:sectionheader title="Student"/>
  <apex:form >
  <apex:PageBlock title="Input"> 
  <apex:PageBlockButtons >
  <apex:commandButton value="Save" action="{!Save}"/>
  </apex:PageBlockButtons>
  <apex:pageblockSection >
  
  <apex:inputField value="{!Student_new__c.Name}"/>
  <apex:inputField value="{!Student_new__c.class__c}"/>
   <apex:inputField value="{!Student_new__c.Class_Monitor__c}"/>
   <apex:inputField value="{!Student_new__c.Teacher_Name__c}"/>
   
  </apex:pageblockSection>
  </apex:PageBlock>
  
  </apex:form>
  <apex:form >
  <apex:PageBlock title="output"> 
  <apex:pageblockSection >
  <apex:outputField value="{!Student_new__c.class__c}"/>
   <apex:outputField value="{!Student_new__c.Class_Monitor__c}"/>
   <apex:outputField value="{!Student_new__c.Teacher_Name__c}"/>
   
  </apex:pageblockSection>
  </apex:PageBlock>
  
  </apex:form>
  

</apex:page>

Java Hibernate tutorials


For Java Hibernate tutorials visit the link below :


http://javalite.io/activejdbc

Insert - Update - Delete in JDBC ....

Insert - Update - Delete in JDBC ....

package jdbcpack;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

//import com.mysql.jdbc.PreparedStatement;

public class InsUpdDel
{

    public static void main(String[] args)
    {
        Connection con=null;
        PreparedStatement pstat = null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
           
            pstat = con.prepareStatement("Insert into student values(?,?,?)");
            pstat.setInt(1, 2009);
            pstat.setString(2, "Rohit");
            pstat.setInt(3,22);
            int x= pstat.executeUpdate();
            if(x>=1)
                System.out.println("\n successfully inserted !!");
           
            System.out.println("\n........Updating .......");
           
            Scanner sc =  new Scanner(System.in);
            System.out.println("Please enter the sid");
            int i = sc.nextInt();
            pstat = con.prepareStatement("Update student set age=30 where sid=?");
                    pstat.setInt(1, i);
                            x= pstat.executeUpdate();
                            if(x>=1)
                                System.out.println("successfully updated !!");
                           
           
            System.out.println("\n.............Delete Statement........................");
           
           
            System.out.println("Please enter the sid to be deleted !!");
            i=sc.nextInt();
            pstat=con.prepareStatement("delete from student where sid=?");
            pstat.setInt(1,i);
            x= pstat.executeUpdate();
           
            if(x>=1)
                System.out.println("successfully Deleted !!");
            else
                System.out.println("not found !!");
           
           
           
        }
       
        catch(Exception ex)
        {
            System.out.println(ex.toString());
        }
        finally
        {
            try
            {
                con.close();
                pstat.close();
            }
   
            catch (SQLException e)
            {
                e.printStackTrace();
            }
   
        }
    }

}

Simple JDBC Programme

Simple JDBC Programme



package jdbcpack2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Test1 {

    public static void main(String[] args)
    {
        Connection con=null;
        Statement stmt=null;
       
        try
        {
           
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
            stmt=con.createStatement();
            ResultSet rs = stmt.executeQuery("select *from student");
            while(rs.next())
            {
                System.out.println("Result :" + rs.getInt(1) + " " + rs.getString(2) + " " + rs.getInt(3));
               
            }
        }
        catch (ClassNotFoundException e)
        {
           
            e.printStackTrace();
        }
       
        catch (SQLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
   
    }

}


calculate Month from Two Dates

int calculateMonth()
{
int month;

month = this.getOpenDate().getMonth() - this.getCloseDate().getMonth();
int year =  this.getCloseDate().getYear()-this.getOpenDate().getYear();
month = month + year*12;
this.setTime(month);

return month;

}



--------------------------------------------------------------------------------------------------------------------------

public Date getCloseDate()
{
SimpleDateFormat ft = new SimpleDateFormat("dd/MM/yyyy");
Date dt = null;
try
{

dt =ft.parse( this.closeDate);
}

catch (ParseException e)
{

e.printStackTrace();
}
return dt;
}

-------------------------------------------------------------------------------------------------------------------------

public void setCloseDate(String closeDate) 
{
this.closeDate = closeDate;
}