Sunday, 22 February 2015

trigger ownerValueSave on Branch__c(before update)
{
  if(trigger.isupdate)
  {
  for(Branch__c b:Trigger.new)
  {
     if(b.ownerId != Trigger.old[0].OwnerId)
     {
         User u = [select id,name from User where id=:Trigger.old[0].OwnerId];
        
         if(b.Owner2__c==null)
         {
             b.Owner2__c=b.Owner1__c;
         }
        
         if(b.Owner1__c==null)
         {
             b.Owner1__c=u.name;
        
         }
        
         else
        
        
          if(b.Owner2__c!=null)
         {
             b.Owner2__c= b.Owner1__c;
         }
        
         if(b.Owner1__c!=null)
         {
             b.Owner1__c=u.name;
         }
         
       
     }
  }
    
  }
}   

Inline Edit Functinalitry for Custom Object





Visualforce Page:
 
<apex:page controller="InlineEditClsforCandidate" showHeader="false" standardStylesheets="true">
<apex:form >
      <apex:pageBlock title="Inline Edit Functionality for Candidate" tabStyle="Mobile__c">
      <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!SaveCandidate}" />
      <apex:commandButton value="Cancel" />
      </apex:pageBlockButtons>
          <apex:pageBlockSection title="Candidate Details" columns="2">
              <apex:outputField value="{!can.Name}"/>
              <apex:outputField value="{!can.Frist_Name__c}"/>
              <apex:outputField value="{!can.Last_Name__c}"/>
              <apex:outputField value="{!can.E_Mail__c}"/>
              <apex:outputField value="{!can.Mobile__c}"/>
              <apex:outputField value="{!can.State__c}"/>
              <apex:outputField value="{!can.Street__c}"/>
              <apex:outputField value="{!can.Visa_Required__c}"/>
              <apex:outputField value="{!can.Years_of_Experince__c}"/>
              <apex:inlineEditSupport event="onclick"/>
          </apex:pageBlockSection>
          <apex:pageBlockSection title="Emplyoment Details">
              <apex:outputField value="{!can.SSN__c}"/>
              <apex:outputField value="{!can.Phone__c}"/>
              <apex:outputField value="{!can.Fax__c}"/>
              <apex:outputField value="{!can.City__c}"/>
              <apex:outputField value="{!can.Zip_Postal_Code__c}"/>
              <apex:inlineEditSupport event="onclick"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>
Controller :

public with sharing class InlineEditClsforCandidate {

    public PageReference SaveCandidate() {
        update can;
        return null;
    }


    String canid { get; set; }

    public Candidate__C can { get; set; }
   
    public InlineEditClsforCandidate(){
   
    canid = System.currentPagereference().getParameters().get('Id');
   
    can = [SELECT City__c,Frist_Name__c,Last_Name__c,Mobile__c,Name,Phone__c,E_Mail__c ,State__c,Street__c,Visa_Required__c,Years_of_Experince__c, Fax__c,SSN__c,Zip_Postal_Code__c FROM Candidate__c WHERE id=:canid ];
   
    }