• kpriya Aggarwal
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
I want to show the no of  contacts in Account ilike this:
If I have 5 contacts under an Account then these contacts should be shown in account as 1,2,3,4,5 (This sequence must be show in Text field (Show_Contacts__c) )
 
I have a custom picklist field name Status__c and its values : Active & Inactive  on Account. Whenever I select Active value then other records should be change to Inactive.

Suppose I have 10 records in Account object. According to the requirement, So if I update one record with Active value then other 9 records should be update to Inactive?

Thanks
VF Page
<apex:page Controller="Contactsrd" sidebar="false">  
  <style type="text/css">  
  .popup {  
  background-color: White;  
  border-width: 2px;  
  border-style: solid;  
  z-index: 9999;  
  left: 50%;  
  padding:10px;  
  position: absolute;  
  width: 400px;  
  margin-left: -250px;  
  top:80px;  
  }  
  .popupBg{  
  background-color:grey;  
  opacity: 0.20;  
  filter: alpha(opacity = 70);  
  position: absolute;  
  width: 100%;  
  height: 100%;  
  top: 0;  
  left: 0;  
  z-index: 9998;  
  }  
  </style>  
  <apex:form id="form">  
  <apex:pageblock id="pb">   
  <apex:pageBlockTable id="pbt" value="{!getcontactt}" var="ct">  
  <apex:column headerValue="Contact Name">  
  <apex:outputText value="{!ct.name}"></apex:outputText>   
  </apex:column>  
  <apex:column headerValue="Detail">  
  <apex:outputPanel >  
  <apex:actionSupport event="onclick" action="{!detailPage}" rerender="popup,pb">  
  <input type="radio" name="det" />  
  <apex:param value="{!ct.id}" assignTo="{!id}" name="id"/>  
  </apex:actionSupport>  
  </apex:outputPanel>  
  </apex:column>  
  </apex:pageBlockTable>  
 </apex:pageblock>  
 <!--popup code starts-->  
  <apex:outputPanel id="popup">  
  <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!displayPopUp}"/>  
  <apex:outputPanel styleClass="popup" layout="block" rendered="{!displayPopUp}">  
  <apex:messages />  
  <center><h2>{!ct_name} Information</h2></center>  
  <apex:panelGrid columns="2" >  
  <apex:outputLabel value="Contacts"/>
      <apex:inputText value="{!ct_name}"></apex:inputText>
  <apex:commandButton value="Update" action="{!updaterec}"/>  
  <apex:commandButton value="cancel" action="{!closePopup}" rerender="popup,pb"/>  
  </apex:panelGrid>
      
  </apex:outputPanel>  
  </apex:outputPanel>  
 <!-- end of popup code-->  
  </apex:form>  
 </apex:page>
Controller:
public class Contactsrd{
  Public String ct_name { get; set; }  
  public boolean displayPopUp { get; set; }  
  Contact cont {get; set;}
   List<Contact> clist= new List<Contact>();
     //cont= new contact();
 public PageReference closePopup() {//hide method  
  displayPopup = false;  
  return null;  
  }  
 public PageReference detailPage() {// action method which shows popup on selection  
  displayPopup = true;  
  system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
  String id = ApexPages.currentPage().getParameters().get('id'); 
  Contact ac = [select id,name from Contact where id =: id];
  ct_name = ac.name; 
  //update ac;
  return null;  
  }  
  public list<Contact> getGetContactt() {  
  list<Contact> ctl = [select id,name from Contact];  
  return ctl;  
  }  
  public Contactsrd(){
  Id id= ApexPages.currentPage().getParameters().get('id');
  cont=(id==null)? new Contact():[Select lastName FROM Contact Where Id= :id];
  }
 public PageReference updaterec() {//update popup record   
  //displayPopup = true; 
  Try{upsert(cont);}catch(system.DMLException e){ApexPages.addMessages(e); return null;}
  //try{
  //contact c= [SELECT Id FROM Contact WHERE Id=:id];
  //c.Salutation= ct_name;
  //c.FirstName=ct_name;
  //c.LastName=ct_name;
  //update cont;
  return null;  
  }  
  }
See below image.I got an error while upserting record.

User-added image
VF Page:
<apex:page sidebar="false" standardController="Order__c" extensions="ordercreationExt"  standardStylesheets="false" showHeader="false" applyHtmlTag="false">
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
          <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <apex:stylesheet value="{!URLFOR($Resource.style_resources, '/styles/salesforce-lightning-design-system.min.css')}" />
            <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js">script>
            <script src='js/jquery-sortable.js'></script>
                <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"/>
                <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
                <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet"/>
                <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
                <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
            <script src="//code.jquery.com/jquery-1.10.2.js"></script>
            <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
          </head>
    <apex:form id="frm">
        <script type= "text/javascript">
        function fieldalert(){
            var x = document.getElementById("{!$Component.frm.bl1.sec1.nm}").value;
            if(x==''){
                alert("Please enter your Name in Account Name field");
            }
            else{
                alert("Do you really want to insert the new record with Name : "+x);    
            }
        }
        </script>
    <apex:pageBlock id="bl1">
      <div class="slds"></div>
        <apex:pageBlockSection id="sec1" title="Enter your details here" collapsible="false"><br/>
            <div class="slds-form-element"><br/>
               <div class="slds-form-element__control slds-p-bottom_xx-small slds-m-horizontal--x-small">
                  <apex:inputField value="{!Order__c.Name}" id="nm"/>
               </div>
             </div>
             <!--<div class="slds-form-element">-->
                 <!--<div class="slds-form-element__control slds-p-bottom_xx-small slds-m-left--x-small">-->
                  <apex:inputField value="{!Order__c.myfirstcontapp__Product__c}" id="ac"/>
                <!--</div>-->
             <!--</div>-->
             <div class="slds-form-element">
                 <div class="slds-form-element__control slds-p-bottom_xx-small">
                  <apex:inputField value="{!Order__c.myfirstcontapp__Quantity__c}" id="qty"/>
                </div>
             </div>
             <div class="slds-form-element">
                <div class="slds-form-element__control slds-p-bottom_xx-small slds-m-left--x-small">
                  <apex:inputField value="{!Order__c.myfirstcontapp__Conformation__c}" id="cnf"/>
                </div>
             </div>
          </apex:pageBlockSection>
           <div class="slds-modal__footer">
             <apex:commandButton action="{!create}" value="Create" onclick="fieldalert" id="btn1"
              styleClass="slds-p-top_xx-small slds-button slds-button--neutral slds-button__icon_left"
                                 style="margin-right: 50%;"/>
           </div>
        </apex:pageBlock>
    </apex:form>
  </html>
</apex:page>
O/P:

User-added image
 
Here is the code:
<apex:page standardController="Contact"  sidebar="false" recordSetVar="contacts" tabStyle="Contact">
    <apex:pageBlock>
        <apex:pageBlockTable value="{!contacts}" var="c">
            <apex:column value="{!c.Name}" HeaderValue="Name"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
VF Page
<apex:page Controller="Contactsrd" sidebar="false">  
  <style type="text/css">  
  .popup {  
  background-color: White;  
  border-width: 2px;  
  border-style: solid;  
  z-index: 9999;  
  left: 50%;  
  padding:10px;  
  position: absolute;  
  width: 400px;  
  margin-left: -250px;  
  top:80px;  
  }  
  .popupBg{  
  background-color:grey;  
  opacity: 0.20;  
  filter: alpha(opacity = 70);  
  position: absolute;  
  width: 100%;  
  height: 100%;  
  top: 0;  
  left: 0;  
  z-index: 9998;  
  }  
  </style>  
  <apex:form id="form">  
  <apex:pageblock id="pb">   
  <apex:pageBlockTable id="pbt" value="{!getcontactt}" var="ct">  
  <apex:column headerValue="Contact Name">  
  <apex:outputText value="{!ct.name}"></apex:outputText>   
  </apex:column>  
  <apex:column headerValue="Detail">  
  <apex:outputPanel >  
  <apex:actionSupport event="onclick" action="{!detailPage}" rerender="popup,pb">  
  <input type="radio" name="det" />  
  <apex:param value="{!ct.id}" assignTo="{!id}" name="id"/>  
  </apex:actionSupport>  
  </apex:outputPanel>  
  </apex:column>  
  </apex:pageBlockTable>  
 </apex:pageblock>  
 <!--popup code starts-->  
  <apex:outputPanel id="popup">  
  <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!displayPopUp}"/>  
  <apex:outputPanel styleClass="popup" layout="block" rendered="{!displayPopUp}">  
  <apex:messages />  
  <center><h2>{!ct_name} Information</h2></center>  
  <apex:panelGrid columns="2" >  
  <apex:outputLabel value="Contacts"/>
      <apex:inputText value="{!ct_name}"></apex:inputText>
  <apex:commandButton value="Update" action="{!updaterec}"/>  
  <apex:commandButton value="cancel" action="{!closePopup}" rerender="popup,pb"/>  
  </apex:panelGrid>
      
  </apex:outputPanel>  
  </apex:outputPanel>  
 <!-- end of popup code-->  
  </apex:form>  
 </apex:page>
Controller:
public class Contactsrd{
  Public String ct_name { get; set; }  
  public boolean displayPopUp { get; set; }  
  Contact cont {get; set;}
   List<Contact> clist= new List<Contact>();
     //cont= new contact();
 public PageReference closePopup() {//hide method  
  displayPopup = false;  
  return null;  
  }  
 public PageReference detailPage() {// action method which shows popup on selection  
  displayPopup = true;  
  system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
  String id = ApexPages.currentPage().getParameters().get('id'); 
  Contact ac = [select id,name from Contact where id =: id];
  ct_name = ac.name; 
  //update ac;
  return null;  
  }  
  public list<Contact> getGetContactt() {  
  list<Contact> ctl = [select id,name from Contact];  
  return ctl;  
  }  
  public Contactsrd(){
  Id id= ApexPages.currentPage().getParameters().get('id');
  cont=(id==null)? new Contact():[Select lastName FROM Contact Where Id= :id];
  }
 public PageReference updaterec() {//update popup record   
  //displayPopup = true; 
  Try{upsert(cont);}catch(system.DMLException e){ApexPages.addMessages(e); return null;}
  //try{
  //contact c= [SELECT Id FROM Contact WHERE Id=:id];
  //c.Salutation= ct_name;
  //c.FirstName=ct_name;
  //c.LastName=ct_name;
  //update cont;
  return null;  
  }  
  }
See below image.I got an error while upserting record.

User-added image
VF Page
<apex:page Controller="Contactsrd" sidebar="false">  
  <style type="text/css">  
  .popup {  
  background-color: White;  
  border-width: 2px;  
  border-style: solid;  
  z-index: 9999;  
  left: 50%;  
  padding:10px;  
  position: absolute;  
  width: 400px;  
  margin-left: -250px;  
  top:80px;  
  }  
  .popupBg{  
  background-color:grey;  
  opacity: 0.20;  
  filter: alpha(opacity = 70);  
  position: absolute;  
  width: 100%;  
  height: 100%;  
  top: 0;  
  left: 0;  
  z-index: 9998;  
  }  
  </style>  
  <apex:form id="form">  
  <apex:pageblock id="pb">   
  <apex:pageBlockTable id="pbt" value="{!getcontactt}" var="ct">  
  <apex:column headerValue="Contact Name">  
  <apex:outputText value="{!ct.name}"></apex:outputText>   
  </apex:column>  
  <apex:column headerValue="Detail">  
  <apex:outputPanel >  
  <apex:actionSupport event="onclick" action="{!detailPage}" rerender="popup,pb">  
  <input type="radio" name="det" />  
  <apex:param value="{!ct.id}" assignTo="{!id}" name="id"/>  
  </apex:actionSupport>  
  </apex:outputPanel>  
  </apex:column>  
  </apex:pageBlockTable>  
 </apex:pageblock>  
 <!--popup code starts-->  
  <apex:outputPanel id="popup">  
  <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!displayPopUp}"/>  
  <apex:outputPanel styleClass="popup" layout="block" rendered="{!displayPopUp}">  
  <apex:messages />  
  <center><h2>{!ct_name} Information</h2></center>  
  <apex:panelGrid columns="2" >  
  <apex:outputLabel value="Contacts"/>
      <apex:inputText value="{!ct_name}"></apex:inputText>
  <apex:commandButton value="Update" action="{!updaterec}"/>  
  <apex:commandButton value="cancel" action="{!closePopup}" rerender="popup,pb"/>  
  </apex:panelGrid>
      
  </apex:outputPanel>  
  </apex:outputPanel>  
 <!-- end of popup code-->  
  </apex:form>  
 </apex:page>
Controller:
public class Contactsrd{
  Public String ct_name { get; set; }  
  public boolean displayPopUp { get; set; }  
  Contact cont {get; set;}
   List<Contact> clist= new List<Contact>();
     //cont= new contact();
 public PageReference closePopup() {//hide method  
  displayPopup = false;  
  return null;  
  }  
 public PageReference detailPage() {// action method which shows popup on selection  
  displayPopup = true;  
  system.debug('Select Item Id is :'+ApexPages.currentPage().getParameters().get('id'));  
  String id = ApexPages.currentPage().getParameters().get('id'); 
  Contact ac = [select id,name from Contact where id =: id];
  ct_name = ac.name; 
  //update ac;
  return null;  
  }  
  public list<Contact> getGetContactt() {  
  list<Contact> ctl = [select id,name from Contact];  
  return ctl;  
  }  
  public Contactsrd(){
  Id id= ApexPages.currentPage().getParameters().get('id');
  cont=(id==null)? new Contact():[Select lastName FROM Contact Where Id= :id];
  }
 public PageReference updaterec() {//update popup record   
  //displayPopup = true; 
  Try{upsert(cont);}catch(system.DMLException e){ApexPages.addMessages(e); return null;}
  //try{
  //contact c= [SELECT Id FROM Contact WHERE Id=:id];
  //c.Salutation= ct_name;
  //c.FirstName=ct_name;
  //c.LastName=ct_name;
  //update cont;
  return null;  
  }  
  }
See below image.I got an error while upserting record.

User-added image
VF Page:
<apex:page sidebar="false" standardController="Order__c" extensions="ordercreationExt"  standardStylesheets="false" showHeader="false" applyHtmlTag="false">
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
          <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <apex:stylesheet value="{!URLFOR($Resource.style_resources, '/styles/salesforce-lightning-design-system.min.css')}" />
            <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js">script>
            <script src='js/jquery-sortable.js'></script>
                <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"/>
                <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
                <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet"/>
                <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
                <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
            <script src="//code.jquery.com/jquery-1.10.2.js"></script>
            <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
          </head>
    <apex:form id="frm">
        <script type= "text/javascript">
        function fieldalert(){
            var x = document.getElementById("{!$Component.frm.bl1.sec1.nm}").value;
            if(x==''){
                alert("Please enter your Name in Account Name field");
            }
            else{
                alert("Do you really want to insert the new record with Name : "+x);    
            }
        }
        </script>
    <apex:pageBlock id="bl1">
      <div class="slds"></div>
        <apex:pageBlockSection id="sec1" title="Enter your details here" collapsible="false"><br/>
            <div class="slds-form-element"><br/>
               <div class="slds-form-element__control slds-p-bottom_xx-small slds-m-horizontal--x-small">
                  <apex:inputField value="{!Order__c.Name}" id="nm"/>
               </div>
             </div>
             <!--<div class="slds-form-element">-->
                 <!--<div class="slds-form-element__control slds-p-bottom_xx-small slds-m-left--x-small">-->
                  <apex:inputField value="{!Order__c.myfirstcontapp__Product__c}" id="ac"/>
                <!--</div>-->
             <!--</div>-->
             <div class="slds-form-element">
                 <div class="slds-form-element__control slds-p-bottom_xx-small">
                  <apex:inputField value="{!Order__c.myfirstcontapp__Quantity__c}" id="qty"/>
                </div>
             </div>
             <div class="slds-form-element">
                <div class="slds-form-element__control slds-p-bottom_xx-small slds-m-left--x-small">
                  <apex:inputField value="{!Order__c.myfirstcontapp__Conformation__c}" id="cnf"/>
                </div>
             </div>
          </apex:pageBlockSection>
           <div class="slds-modal__footer">
             <apex:commandButton action="{!create}" value="Create" onclick="fieldalert" id="btn1"
              styleClass="slds-p-top_xx-small slds-button slds-button--neutral slds-button__icon_left"
                                 style="margin-right: 50%;"/>
           </div>
        </apex:pageBlock>
    </apex:form>
  </html>
</apex:page>
O/P:

User-added image