ads

Thursday, 18 August 2016

Junction Object Creation and Dependent Picklist Using Junction Object



Step 1 :- Create First object  with name "Teacher" and Add some Records







Step 2 :- Create Second object  with name "Subject" and Add some Records










Step 3:- Create Third object with name "Junction"  and have master- detail relationship with Two                     above objects and  then Add some Records








Step 4 :- Making Dependent Picklist 


Controller code :-


public class junction3 {

    public string searchteach{get; set;}
    public string searchsubject{get; set;}
    
    public list<selectoption> gettechlist(){
        list<selectoption> selectteacher= new list<selectoption>();
        list<teacher__c> techlist1= [select name from teacher__c];
        for(teacher__c e:techlist1){
            selectteacher.add(new selectoption(e.name,e.name));
        }
        return selectteacher;
    }
    
    public list<selectoption> getsublist(){
        list<selectoption> selectsubject= new list<selectoption>();
        list<junction__c> junlist1= [select name, teacher__r.name,subject__r.name  from junction__c where teacher__r.name=:searchteach];
        for(junction__c e:junlist1){
            selectsubject.add(new selectoption(e.subject__r.name,e.subject__r.name));
        }
        return selectsubject;
    }
    
    
    
    
    
    public list<selectoption> getsublist1(){
        list<selectoption> selectteacher1= new list<selectoption>();
        list<subject__c> subjlist1= [select name from subject__c];
        for(subject__c e:subjlist1){
            selectteacher1.add(new selectoption(e.name,e.name));
        }
        return selectteacher1;
    }
    
    public list<selectoption> gettechlist1(){
        list<selectoption> selectsubject2= new list<selectoption>();
        list<junction__c> junlist2= [select name, teacher__r.name,subject__r.name  from junction__c where subject__r.name=:searchsubject];
        for(junction__c e:junlist2){
            selectsubject2.add(new selectoption(e.teacher__r.name,e.teacher__r.name));
        }
        return selectsubject2;
    }
    
    
}




Visualforce Page :-


<apex:page controller="junction3">
    <apex:form >
        <apex:pageBlock title="Teacher to Subject Objects" mode="edit">
            <apex:pageBlockSection title="It's a simple Teacher to Subject relationship...">
                <apex:outputPanel style="float:middle">
                    <apex:selectList value="{!searchteach}" size="1">
                        <apex:selectOptions value="{!techlist}"/>
                        <apex:actionSupport event="onchange" reRender="refresh"/>
                    </apex:selectList> 
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <apex:selectList id="refresh" size="1">
                        <apex:selectOptions value="{!sublist}"/>
                    </apex:selectList> 
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
        
        <apex:pageBlock title="Subject to Teacher Junction Objects" mode="edit">
            <apex:pageBlockSection title="It's a simple Subject to Teacher relationship...">
                <apex:outputPanel style="float:middle">
                    <apex:selectList value="{!searchsubject}" size="1">
                        <apex:selectOptions value="{!sublist1}"/>
                        <apex:actionSupport event="onchange" reRender="refreshed"/>
                    </apex:selectList> 
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <apex:selectList id="refreshed" size="1">
                        <apex:selectOptions value="{!techlist1}"/>
                    </apex:selectList> 
                </apex:outputPanel>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output Screen 1  :-


Output Screen 2  :-


Fancy Mobile UI With Different Themes



Static Resource :-

First download file and save it into "Static Resource".

Download Link



Visualforce Pages :-


<apex:page docType="html-5.0" standardStylesheets="false" showHeader="false" sidebar="false">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
  <title>Contacts in Backbone.js</title>

  <!-- ========= -->
  <!--    CSS    -->
  <!-- ========= -->
  <link href="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/css/jquery.mobile-1.3.0.min.css')}" rel="stylesheet" />

  <!-- ========= -->
  <!-- Libraries -->
  <!-- ========= -->
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/jquery-2.0.0.min.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/underscore-1.4.4.min.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/backbone-1.0.0.min.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/forcetk.js')}" type="text/javascript"></script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/force.entity.js')}" type="text/javascript"></script>
  <script>
    $( document ).on( "mobileinit",
      // Set up the "mobileinit" handler before including jQuery Mobile
      function() {
        $.mobile.ajaxEnabled = false;
        $.mobile.linkBindingEnabled = false;
      }
    )
  </script>
  <script src="{!URLFOR($Resource.MobileSample_Resources_Backbone, 'resources/lib/jquerymobile.js')}" type="text/javascript"></script>
</head>
<body>

  <!-- ========= -->
  <!-- HTML CODE -->
  <!-- ========= -->
  <div id="contacts" data-role="page" data-title="Contacts">
    <div data-role="header">
      <h1>Contacts</h1>
    </div><!-- /header -->
    <div data-role="content" id="contacts-content">
    </div>
  </div>

  <div id="contact" data-role="page" data-title="Contact">
    <div data-role="header">
        <a href='#' id="back" class='ui-btn-left' data-icon='arrow-l'>Back</a>
        <h1>Contact</h1>
    </div><!-- /header -->
    <div data-role="content" id="contact-content">
    </div>
  </div>

   <!-- ========= -->
  <!-- Templates -->
  <!-- ========= -->
  <script type="text/template" id="contacts-template">
    <form>
        <button data-role="button" class="new">New Contact</button>
    </form>
    <ul data-role="listview" data-inset="true" id="contact-list">
    </ul>
    <div data-role="footer">
      <div data-role="fieldcontain">
        <label for="select-theme" class="select">UI Theme:</label>
        <select class="theme-selector" name="select-theme" id="select-theme">
          <option value="default">default</option>
          <option value="a">a</option>
          <option value="b">b</option>
          <option value="c">c</option>
          <option value="d">dr</option>
          <option value="e">e</option>
        </select>
      </div>
    </div>
  </script>

  <script type="text/template" id="contact-template">
    <% if (typeof(Id) !== 'undefined') { %>
      <a href="#<%= Id %>"><%- Name %></a> 
    <% } else { %>
      <%- Name %>
    <% } %>
  </script>

  <script type="text/template" id="contact-detail-template">
    <form name="contactform" id="contactform">
      <% if (typeof(Id) !== 'undefined') { %>
        <input type="hidden" name="Id" id="Id" value="<%- Id %>" />
      <% } %>
      <div data-role="fieldcontain">
        <label for="Name">First Name:</label>
        <% if (typeof(FirstName) !== 'undefined') { %>
          <input name="FirstName" id="FirstName" value="<%- FirstName %>" />
        <% } else { %>
          <input name="FirstName" id="FirstName" />
        <% } %>
      </div>
      <div data-role="fieldcontain">
        <label for="Name">Last Name:</label>
        <% if (typeof(LastName) !== 'undefined') { %>
          <input name="LastName" id="LastName" value="<%- LastName %>" />
        <% } else { %>
          <input name="LastName" id="LastName" />
        <% } %>
      </div>
      <div data-role="fieldcontain">
        <label for="Email">Email:</label>
        <% if (typeof(Email) !== 'undefined') { %>
          <input name="Email" id="Email" value="<%- Email %>" />
        <% } else { %>
          <input name="Email" id="Email" />
        <% } %>
      </div>
      <button data-role="button" data-icon="check" data-inline="true" data-theme="b" class="save">Save</button>
      <% if (typeof(Id) !== 'undefined') { %>
        <button data-role="button" data-icon="delete" data-inline="true" class="destroy">Delete</button>
      <% } %>
    </form>
  </script>

  <!-- =============== -->
  <!-- Javascript code -->
  <!-- =============== -->
  <script type="text/javascript">


    function changeTheme(theme){
      var hfTheme = theme, 
          cTheme = theme;

      if (theme === 'default') {
        // "If no theme swatch letter is set at all, the framework uses the 
        // "a" swatch (black in the default theme) for headers and footers 
        // and the "c" swatch (light gray in the default theme) for the page 
        // content to maximize contrast between the both."
        // http://jquerymobile.com/demos/1.2.1/docs/api/themes.html
        hfTheme = "a";
        cTheme = "c";
      }

      $.mobile.activePage.find('.ui-btn').not('.ui-li-divider')
                         .removeClass('ui-btn-up-a ui-btn-up-b ui-btn-up-c ui-btn-up-d ui-btn-up-e ui-btn-hover-a ui-btn-hover-b ui-btn-hover-c ui-btn-hover-d ui-btn-hover-e')
                         .addClass('ui-btn-up-' + cTheme)
                         .attr('data-theme', cTheme);
      
      $.mobile.activePage.find('.ui-li-divider').each(function (index, obj) {
        if ($(this).parent().attr('data-divider-theme') == 'undefined') {
            $(this).removeClass('ui-bar-a ui-bar-b ui-bar-c ui-bar-d ui-bar-e')
                   .addClass('ui-bar-' + cTheme)
                   .attr('data-theme', cTheme);
        }
      })
                         
      $.mobile.activePage.find('.ui-header, .ui-footer')
                         .removeClass('ui-bar-a ui-bar-b ui-bar-c ui-bar-d ui-bar-e')
                         .addClass('ui-bar-' + hfTheme)
                         .attr('data-theme', hfTheme);
      $.mobile.activePage.removeClass('ui-body-a ui-body-b ui-body-c ui-body-d ui-body-e')
                         .addClass('ui-body-' + cTheme)
                         .attr('data-theme', cTheme);
    }

    $(document).ready(function() {
      var creds = {
        accessToken: '{!$Api.Session_ID}'
      };
    
      Force.init(creds);

      myapp();
    });

    function myapp() {
      var app = {}; // create namespace for our app

      //--------------
      // Models
      //--------------
      app.Contact = Force.SObject.extend({
        sobjectType:'Contact',
        fieldlist:['Id', 'FirstName', 'LastName', 'Email']
      });

      //--------------
      // Collections
      //--------------
      app.ContactsCollection = Force.SObjectCollection.extend({
        model: app.Contact,
        fieldlist:['Id', 'Name', 'FirstName', 'LastName', 'Email'],
        config: function() {
          return {type:"soql", query:"SELECT " + this.fieldlist.join(",") + " FROM Contact ORDER BY Name LIMIT 25"};
        }
      }),

      //--------------
      // Views
      //--------------

      // renders individual Contact list item (li)
      app.ContactView = Backbone.View.extend({
        tagName: 'li',
        template: _.template($('#contact-template').html()),
        render: function(){
          this.$el.html(this.template(this.model.toJSON()));
          return this; // enable chained calls
        },
        initialize: function(){
        }
      });

      // renders individual Contact for editing
      app.ContactDetailView = Backbone.View.extend({
        template: _.template($('#contact-detail-template').html()),
        render: function(){
          this.$el.html(this.template(this.model.toJSON()));
          return this; // enable chained calls
        },
        initialize: function(){
          this.model.on('destroy', this.remove, this);
          this.render();
        },
        events: {
          'change' : 'change',
          'click .save' : 'save',
          'click .destroy': 'destroy'
        },
        change: function (event) {
            // Apply the change to the model
            var target = event.target;
            var change = {};
            change[target.name] = target.value;
            this.model.set(change);
        },
        save: function(){
          this.model.save(null, {
            success: function(model) {
              app.router.navigate('contacts', {trigger: true});
            },
            error: function () {
              alert('Error saving');
            }
          });
          return false;
        },
        destroy: function(){
          this.model.destroy({
            success: function() {
              app.router.navigate('contacts', {trigger: true});             
            },
              error: function () {
                alert('Error deleting');
              }
          });
          return false;
        }
      });

      // renders the full list of Contacts calling ContactView for each one.
      app.ContactsView = Backbone.View.extend({
        template: _.template($('#contacts-template').html()),
        initialize: function() {
          this.render();
          this.model.on('add', this.render, this);
          this.model.on('reset', this.render, this);
        },
        events: {
          'click .new' : 'newContact',
          'change .theme-selector' : 'changeTheme'
        },
        renderOne: function(contact){
          var view = new app.ContactView({model: contact});
          this.$('#contact-list').append(view.render().el);
        },
        render: function(){
          this.$el.html(this.template());
          this.$('#contact-list').empty();
          for (var i = 0, l = this.model.models.length; i < l; i++) {
            this.renderOne(this.model.models[i]);
          }
        },
        changeTheme: function(event){
          event.preventDefault();
          
          var theme = $(event.target).children("option").filter(":selected").text();

          changeTheme(theme);
        },
        newContact: function(){
          app.router.navigate('/new', true);
          return false;
        }
      });

      //Define the Application Router
      app.Router = Backbone.Router.extend({ 
        routes: {
          "": "contacts",
          "contacts":"contacts",
          "new": "newContact",
          ":id": "contact"
        },          
        contacts: function() {
          var contactsCollection = new app.ContactsCollection();
          $.mobile.loading( "show", { text: 'Loading Contacts', textVisible: true } );
          contactsCollection.fetch({success: function(){
            $.mobile.loading( "hide" );
            $("#contacts-content").html(new app.ContactsView({model: contactsCollection}).el);
            // Let jQuery Mobile do its stuff
            $("#contacts-content").trigger( 'create' );
            $.mobile.changePage( "#contacts" , { reverse: false, changeHash: false } );
          }});
        },
        contact: function(id) {
          var contact = new app.Contact({Id: id});
          $.mobile.loading( "show", { text: 'Loading Contact', textVisible: true } );
          contact.fetch({success: function(){
            $.mobile.loading( "hide" );
            $("#contact-content").html(new app.ContactDetailView({model: contact}).el);
            $("#contact-content").trigger( 'create' );
            $.mobile.changePage( "#contact" , { reverse: false, changeHash: false } );
          }});
        },
        newContact: function(id) {
          var contact = new app.Contact();
          $("#contact-content").empty();
          $("#contact-content").html(new app.ContactDetailView({model: contact}).el);
          $("#contact-content").trigger( 'create' );
          $.mobile.changePage( "#contact" , { reverse: false, changeHash: false } );
        }
      });

      app.router = new app.Router();
      Backbone.history.start();
    }
  </script>

</body>
</apex:page>



Screenshot 1:-



Screenshot 2:-



Screenshot 3:-



Screenshot 4:-




Select All Checkbox Using One CheckBox




Static Resource -

Download file and Save in Static Resource :- Download Link





Visualforce Page :-


<apex:page standardController="account">
 

 <apex:includeScript value="{!$Resource.home2}"/>

<script>
$(document).ready(function () {
    $(".ckbCheckAll").click(function () {
        $(".checkBoxClass").prop('checked', $(this).prop('checked'));
        $(".checkBoxClass1").prop('checked', $(this).prop('checked'));
        $(".checkBoxClass2").prop('checked', $(this).prop('checked'));
    });


    
});
</script>

<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >

 
     <apex:inputCheckbox value="{!account.Check_All__c}"  styleClass="ckbCheckAll" /> 
 
      <apex:inputCheckbox value="{!account.salesforce__c}" styleClass="checkBoxClass"  /> 

      <apex:inputCheckbox value="{!account.PHP__c}" styleClass="checkBoxClass1" /> 

      <apex:inputCheckbox value="{!account.Java__c}" styleClass="checkBoxClass2" /> 
      

  
   
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Screenshot 1 :-



Screenshot 2:-


Hover PopUp in Visualforce Page



Controller code :-


public with sharing class PopupTest {
    public PopupTest(ApexPages.StandardController controller) {
    }

    public String getOwner() {
        return null;
    }
 
    public List<account> getAccounts()
    {
        List<account> accounttList = new List<account>();
        accounttList = [Select Id, Name,ownerId,Owner.Name from Account LIMIT 1];
        return accounttList ;
    }
}

Visualforce page code :-


<apex:page standardController="Account" extensions="PopupTest" standardStylesheets="true">
 <!-- <apex:includeScript value="{!$Resource.JQuery}"/>-->
 <apex:form >
<style type="text/css">
      body {
        margin: 0;
        padding: 0;
        font-family: Arial, Helvetica, sans-serif;
        background: #000 url(bg-texture.png) repeat;
        color: #dddddd;
      }
     
           
      a {
        color: #EB067B;
      }
     
        
      /* HOVER STYLES */
      div#pop-up {
        display: none;
        z-index: 10;
        position: absolute;
        width: 200px;
        padding: 30px;
        background: #FFFFFF;
        color: #000000;
        border: 3px solid #C0C0C0;
        font-size: 100%;
      }
   
    </style>
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
 <script type="text/javascript">
 
      $(function() {
        var moveLeft = 10;
        var moveDown = 5;
       
        $('a#trigger').hover(function(e) {
          $('div#pop-up').show();
                  }, function() {
          $('div#pop-up').hide();
        });
       
        $('a#trigger').mousemove(function(e) {
          $("div#pop-up").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft);
        });
       
      });
    </script>
    <apex:repeat value="{!accounts}" var="acc">     
        <a href="/{!acc.ownerId}" id="trigger" >{!acc.Owner.Name}</a>.
  </apex:repeat>
    <!-- HIDDEN / POP-UP DIV -->
    <div id="pop-up">
      <div> <table> <tr>
                           <td>
                             <b>  Name  </b> :
                           </td>
                           <td >  
                             {!$User.FirstName} {!$User.LastName}<br/>
                           </td>
                     </tr>
                     <tr>
                           <td>
                               <b>  Role  </b> :
                           </td>
                           <td>  
                                {!$UserRole.Name}<br/>
                           </td>
                     </tr>
                     <tr>
                         <td>
                             <b>  Phone </b> :
                          </td>
                          <td> 
                              {!$User.Phone}<br/>
                          </td>
                     </tr>
                     <tr>
                        <td>
                           <b>  Email </b> :
                         </td>
                         <td>
                           {!$User.Title}<br/></td>
                     </tr>
                </table>
            </div>
    </div>
   </apex:form>
</apex:page>

Output Screen 1 :-




Output Screen 2 :-



Wednesday, 17 August 2016

PopUp Box To Save Record in Visualforce page



Controller Code :-


public class saveaccountshowrecord {
public account acc{get;set;}
public account acc1{get;set;}
public list<account> acclist2{get; set;}
public string userid{get; set;}
public list<account> acclist3{get; set;}

public saveaccountshowrecord (){
acc= new account();
userid = Apexpages.currentPage().getParameters().get('id');
acclist3=[select name,site,annualrevenue, createddate, description,Email_Id__c from account order by createddate desc];



}


    public void saveinfo(){
    string tempid;
    
    account acclist= new account();
    acclist.name=acc.name;
    acclist.site=acc.site;
    acclist.annualrevenue=acc.annualrevenue;
    acclist.description=acc.description;
    acclist.Email_Id__c=acc.Email_Id__c;

   insert acclist;


        acclist3=[select name,site,annualrevenue, createddate, description,Email_Id__c from account order by createddate desc];



}


public pagereference showrecord(){


return null;


}



}

Visualforce Page :-


<apex:page sidebar="false" controller="saveaccountshowrecord" id="refresh">

        <style>
        .hideBox
        {
        diplay:none;
        visibility:hidden;
        border:6px solid DeepSkyBlue ;
        box-shadow: 0px 0px 10px #888888;
        position:absolute;
        top:50px;
        left:200px;
        }
        </style>

    <apex:form >
        <apex:pageBlock title="Save Account and Show Records">
        
     <apex:pageBlockButtons >
     
           
         
           
            <apex:commandButton title="ShowBox"  value="Show Box" onclick="showmydiv()"  reRender="efg"/><br/>
            </apex:pageBlockButtons>  
         
         
         <apex:outputPanel id="refresh">
           
           <apex:pageBlockTable value="{!acclist3}" var="acc">
               <apex:column headerValue="Account Name">
                   <apex:outputField value="{!acc.name}"/>
               </apex:column>
               
               <apex:column headerValue="Account Site">
                   <apex:outputField value="{!acc.Site}"/>
               </apex:column>
               
              
             
               
               <apex:column headerValue="Account Site">
                   <apex:outputField value="{!acc.Email_Id__c }"/>
               </apex:column>
               
               
           </apex:pageBlockTable>
                    
            </apex:outputPanel>
         
            
        
       <div id="mybox" class="hideBox" >
       <apex:pageBlock >
       
           <apex:pageBlockButtons >
                <apex:commandButton action="{!saveinfo}" value="Save Record" onclick="Hidemydiv()" reRender="refresh"/>
                <apex:commandButton title="Hide Box"  value="Hide Box" onclick="Hidemydiv()" reRender="abc"/><br/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Save Record">
                <apex:inputField value="{!acc.name}"/>
                <apex:inputField value="{!acc.site}"/>
                <apex:inputField value="{!acc.annualrevenue}"/>
                <apex:inputField value="{!acc.description}"/>
                <apex:inputField value="{!acc.Email_Id__c}"/>
            </apex:pageBlockSection>
            </apex:pageBlock>
       </div>
              
        </apex:pageBlock>
    </apex:form>
        <script language="javascript">
        function showmydiv() {
        document.getElementById('mybox').style.visibility= 'visible';
        }
        function Hidemydiv() {
document.getElementById('mybox').style.visibility= 'hidden';
}
        
</script>

</apex:page>

Oupput Screen 1 :-



Oupput Screen 2 :-



Oupput Screen 3 :-