Tuesday 11 October 2011

Create the Manage Page For Custom Object.

Please Share the Subject with others. i created Manage Page for Custom obejct. Object Name is Talend and Created Some Fields in Talend object. Here i Created Apex Class and Visualforce page  for Talend Object.

Apex Class:   DataTableDelete

public class DataTableDelete {

public List<Talend__c> leas { get; set; }

   //used to get a hold of the account record selected for deletion
   public string SelectedtalendId { get; set; }

   public DataTableDelete() {
       //load account data into our DataTable
       LoadData();
   }

   private void LoadData()
   {
   
       leas = [Select t.Id,t.Name__c,t.Phone__c,t.Company__c from Talend__c t];
   }

   public void DeleteLead()
   {
      // if for any reason we are missing the reference
      if (SelectedtalendId== null)
      {
         return;
      }
      // find the account record within the collection
      Talend__c tobeDeleted = null;
      for(Talend__c t : leas)
       if (t.Id == SelectedtalendId)
       {
          tobeDeleted = t;
          break;
       }
   
      //if account record found delete it
      if (tobeDeleted != null) {
       Delete tobeDeleted;
      }
   
      //refresh the data
      LoadData();
   }
   

  }

Visual force Page: TalendManagePage

<apex:page controller="DataTableDelete">

<script>
var newWin=null;
    function openLookupPopup(id)
    {
        //alert(id);
        var url="/apex/talend1?idfield="+ id;
        newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
        if (window.focus)
        {
            newWin.focus();
        }
        return false;
    }
    function addopenLookupPopup()
    {
     
        var url="/apex/addtalend";
        newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
        if (window.focus)
        {
            newWin.focus();
        }
        return false;
    }
</script>
<apex:sectionHeader title="Talend Edit" subtitle="Talend"/>
<apex:form id="form" >
<apex:pageBlock title="Talend" id="pb1">
<apex:pageblockButtons location="Top">
     <apex:CommandButton value="Add"   onclick="addopenLookupPopup()"/>
</apex:pageblockButtons>
  <apex:pageMessages ></apex:pageMessages>
  <apex:pageBlockTable value="{!leas}" var="row">
  <apex:column >
  <apex:facet name="header">Name</apex:facet>
  <apex:outputLink value="/{!row.Id}" target="_blank">{!row.Name__c}</apex:outputLink>
  </apex:column>
     <apex:column value="{!row.Phone__c}"/>
     <apex:column value="{!row.Company__c}"/>
     <apex:column headerValue="Action">
 
      <a href="#" onclick="openLookupPopup('{!row.Id}'); return true" style="font-weight:bold">Edit</a>&nbsp;&nbsp;
      <a href="javascript:if (window.confirm('Are you sure?')) DeleteLead('{!row.Id}');" style="font-weight:bold">Del</a>
     </apex:column>
   
  </apex:pageBlockTable>
</apex:pageBlock>
<apex:actionFunction action="{!DeleteLead}" name="DeleteLead" reRender="form" >
   <apex:param name="leadid" value="" assignTo="{!SelectedtalendId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>

See in Visual force Page here inside the  Script i used Edit and Add    Visual force Page URL .
i.e  var url="/apex/addtalend";
      var url="/apex/talend1?idfield="+ id;

For this Purpose  i Created another Apex Classes and Visual force Pages.

Edit Purpose :
============
Apex Class :


public class talend1
{
public talend1(ApexPages.StandardController Controller)
{
String ParentId = System.currentPageReference().getParameters().get('idfield');
}

Talend__c talend;
public Talend__c gettalend()
{
if(talend == null)
{
   //talend = new Talend__c();
   String recordidvalue= System.currentPageReference().getParameters().get('idfield');
   talend = [Select t.Id,t.Name__c,t.Opportunity__c,t.Phone__c,t.Account__c,t.Company__c from Talend__c t where t.Id=:recordidvalue];
}
return talend;
}
public PageReference Save1()
{
Talend__c t = new Talend__c();
 String eventid= System.currentPageReference().getParameters().get('idfield');
t = [Select t.Id,t.Name__c,t.Opportunity__c,t.Phone__c,t.Account__c,t.Company__c from Talend__c t where t.Id=:eventid];
t.Name__c = talend.Name__c;
t.Company__c = talend.Company__c;
t.Phone__c = talend.Phone__c;


update t;
return new PageReference('javascript:window.close()');

}

}

Visual force Page :
=============

<apex:page standardController="Talend__c" extensions="talend1" showHeader="false" sidebar="false">
<script language="javascript">

function closeMWindow()
{
newwin = window.open(location.href,'_parent','');
newwin.close();
}


</script>

<script>
function ConfirmCancel()
{
 var isCancel = confirm("Are u sure want Cancel");
 if(isCancel) return true;
 return false;
 }

</script>

<apex:sectionHeader title="Talend Edit" subtitle="Talend"/>
<apex:form >
<apex:pageBlock title="Talend" mode="Edit">
<apex:pageBlockButtons >

<apex:commandButton value="Save" action="{!Save1}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
<apex:commandButton onclick="closeMWindow();" value="Close Main window"></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockSection title="talend" columns="1">
<apex:inputfield value="{!talend.Name__c}"/>
<apex:inputfield value="{!talend.Company__c}"/>
<apex:inputfield value="{!talend.Phone__c}"/>
<apex:inputfield value="{!talend.Account__c}"/>
<apex:inputfield value="{!talend.Opportunity__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

This Apex Class and Visual force page is Update the Record in Talend Obejct.


Add Purpose :
============
Apex Class :


public with sharing class aatalend {

    public aatalend(ApexPages.StandardController controller)
    {

    }
  Talend__c talend;
public Talend__c gettalend()
{
if(talend == null)
{
   talend = new Talend__c();
}
return talend;
}
public PageReference Save1()
{
Talend__c t = new Talend__c();
t.Name__c = talend.Name__c;
t.Company__c = talend.Company__c;
t.Phone__c = talend.Phone__c;
t.Account__c = talend.Account__c;
t.Opportunity__c = talend.Opportunity__c;

insert t;
return new PageReference('javascript:window.close()');
}

}


Visual force Page :


<apex:page standardController="Talend__c" extensions="aatalend" showHeader="false" sidebar="false">
<script language="javascript">
function closeMWindow()
{
newwin = window.open(location.href,'_parent','');
newwin.close();
}
</script>

<script>
function ConfirmCancel()
{
 var isCancel = confirm("Are u sure want Cancel");
 if(isCancel) return true;
 return false;
 }
</script>

<apex:sectionHeader title="Talend Edit" subtitle="Talend"/>
<apex:form >
<apex:pageBlock title="Talend" mode="Edit">
<apex:pageBlockButtons >

<apex:commandButton value="Save" action="{!Save1}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
<apex:commandButton onclick="closeMWindow();" value="Close Window"></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockSection title="talend" columns="1">
<apex:inputfield value="{!talend.Name__c}"/>
<apex:inputfield value="{!talend.Company__c}"/>
<apex:inputfield value="{!talend.Phone__c}"/>
<apex:inputfield value="{!talend.Account__c}"/>
<apex:inputfield value="{!talend.Opportunity__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

This code is for newly add the Record in Talend Obejct.



These are all the Steps done Properly means Talend MangePage Working Properly. Talend ManagePage display like this.








No comments:

Post a Comment