• Ajaz
  • NEWBIE
  • 95 Points
  • Member since 2015

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 14
    Replies
I want to make a VF page that shows members of a campaign as well as has a searchfield to find contacts to add to the campaign. So the action for the search field will find all contacts that match and display them on a list. Then the user can select a contact and click on the name and that contact would be added to the campaign. 

My problem is that I don't know how to implement that last bit. Since the list of contats is displayed with a pageBlockTable how does the controller know which contact was selected.

Here is my VF page markup

<apex:page standardController="Campaign" extensions="showCampaignMembers">
  <apex:form >
    <apex:pageBlock title="{!campaign.name}">
      <apex:pageBlockSection title="Criteria">
      <apex:outputLabel value="Enter Name Snippet"/>
      <apex:inputText value="{!nameQuery}"/>
      <apex:commandButton action="{!executeSearch}" value="Search"/>
   </apex:pageBlockSection>
    
   <apex:pageBlockTable value="{!contacts}" var="con">
      <apex:column headerValue="Name">
         <apex:outputLink value="/{!con.id}/e?retURL={!URLENCODE('/apex/RetUrlSearchPage?query='+nameQuery)}">{!con.Name}</apex:outputLink>
      </apex:column>
      <apex:column value="{!con.Participant__c}"/>
   </apex:pageBlockTable>
   <apex:pageBlockSection title="Participants in Campaign">
     <apex:pageBlockTable value="{!participants}" var="part">
       <apex:column value="{!part.FirstName}"/>
       <apex:column value="{!part.LastName}"/>
       <apex:column value="{!part.Email}"/>
       <apex:column value="{!part.Status}"/>
                 
     </apex:pageBlockTable>
   </apex:pageBlockSection>
 </apex:pageBlock>
  </apex:form>
</apex:page>

-----------
And the controller
-----------

public class showCampaignMembers 
{
 public String nameQuery {get; set;}
 public List<Contact> contacts {get; set;}
 Public List<CampaignMember> participants {get; set;}
 private ApexPages.StandardController std;
 
 public PageReference executeSearch()
 {
  String queryStr='%' + nameQuery + '%';
  contacts=[select id, Name, Participant__c 
            from Contact 
            where name like :queryStr];
            
  return null;
 }
  
 public showCampaignMembers(ApexPages.StandardController stdCtrl)
 {
   Std = stdCtrl;
    Participants = [SELECT id, FirstName, LastName, Email, Status FROM CampaignMember
        WHERE CampaignId = :std.getId() ORDER BY FirstName];
  }

}

I appreciate any help.
I have a multi picklist on the User record for Business Unit.  I have a VF Page that shows the list of licenses depending on the user logged in and their Business Unit.  

So for instance.  If my Business Unit is A and C, I want to see all licenses with a Business Unit of A and C.  

If I only have one option chosen for Business Unit on the User record, the User sees their licenses fine.  If the User record has more than one Business Unit chosen, the VF Page only shows column headers, no data.  How do I get it to show licenses for both (or more) Business Units?

This isn't all the code, the last half of the class is long and I didn't post it(Its for the first page block)
 

/*
Class/Method Name: LicenseList
Description: creates lists of licenses to be viewed on the LicenseSummaryHomePage VF Page for the License Community
Author/Date: Staci Gilmore 8/31/16
*/


public with sharing class LicenseList { 
private final License_Numbers__c ln; 
public user currentuser{get;set;} 
public id tobeEdited{get;set;}
public decimal aTotal{get;set;}
public decimal tTotal{get;set;}
public decimal aoTotal{get;set;}
public decimal Total{get;set;} 
//public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public LicenseList(ApexPages.StandardSetController controller) { 
currentuser=new User(); 
currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; 
this.ln = (License_Numbers__c)controller.getRecord(); 

} 

//------------------------------------------------------------------------------------

public List<License_Numbers__c> lntypes16 = new List<License_Numbers__c>();

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__c, One_Month_from_2016__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Running_License_Total__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY Order_Number__c, License_Type__c];
       

return lntypes16; 
} 


//-----------------------------------------------------------------------------
//Returns list of 2017 licenses from original order in contract
public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();


public List <License_Numbers__c> getLicenseList17()
{ 

selectedTypes=[select id, Name, BU_Agrees_to_Pay__c, Sum_of_Cost_10__c, X2016_Subtotal__c, One_Month_from_2016__c, Comments__c , 
                      License_Type2__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, 
                      X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c 
               FROM License_Numbers__c 
               where Business_Unit__c =:currentuser.Business_Unit_new__c AND 
                     License_Year__c = '2017' AND 
                     Add_On__c = false 
               ORDER BY Order_Number__c, License_Type__c];
    
aTotal = 0.0;
tTotal = 0.0;       
          for(License_Numbers__c a:selectedTypes){
                aTotal = aTotal + a.X2017_Cost__c; 
                tTotal = tTotal + a.X2017_Subtotal__c;  
        }
return selectedTypes; 




} 


   



//----Added 2/6/17-------------------------------------------------------------------------
//Returns list of 2017 licenses that were added after the 2017 contract was signed
public List<License_Numbers__c> selectedTypesAddon = new List<License_Numbers__c>();
 
public List <License_Numbers__c> getLicenseList17Addon(){ 

selectedTypesAddon=[select id, Name, True_Up_Cost__c, Sum_of_Cost_10__c, X2016_Subtotal__c, BU_Agrees_to_Pay__c, One_Month_from_2016__c, Comments__c , License_Type2__c, Add_On__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2017'AND Add_On__c = True ORDER BY Order_Number__c, License_Type__c]; 
aoTotal = 0.0;
       
        for(License_Numbers__c a:selectedTypesAddon){
                aoTotal = aoTotal + a.True_Up_Cost__c;  
        }
return selectedTypesAddon; 
} 


}
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" sidebar="false">
<!------------------------------------------------------------------------------------------------------>
<!--Based on option chosen for License Type, will show description of that license type-->
<apex:pageBlock title="License Definitions">
<apex:form id="theForm">
<apex:pageBlockSection columns="1">
<apex:selectList label="Please select a License Type"  value="{!discountScheduleID}" size="1" >
   <apex:actionSupport event="onchange" action="{!displayDescription}" rerender="description"/>
   <apex:selectOptions value="{!schedules}" />
</apex:selectList> 

<apex:outputText label="Description" id="description" value="{!OutPutString}"/>

<br></br><br></br><br></br><br></br>
</apex:pageBlockSection>
</apex:form>


<!--------------------------------------------------------------------------------------------------


<apex:pageBlockTable value="{!LicenseList17Total}" var="lntot">

<apex:outputLink value="{!lntot.Id}">{!lntot.Name}</apex:outputLink>

<apex:column headerValue="                           ">

  <apex:facet name="footer">
  <apex:outputPanel layout="block" style="text-align:left"> 
  SLA Cost + Add-on Cost:
  <apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!Total}" />
    </apex:outputText>
  
  
  </apex:outputPanel>
  </apex:facet>
</apex:column> 
 

</apex:pageBlockTable>-->

</apex:pageBlock>



<!--------------------------------------------------------------------------------------------------------->
<apex:form id="theForm">
<apex:pageBlock id="blockId" title="2017 Licenses">
<!--<apex:pageBlockSection columns="1">

<tr>
<apex:outputText style="font-weight:800" label="Total Contract + Add-on Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!Total}" />
</apex:outputText>

<apex:outputText style="font-weight:800" label="Total 2017 SLA" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aTotal}" />
</apex:outputText>

</tr>
</apex:pageBlockSection>-->

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17}" var="ln17">

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<!--ONLY NEEDED FOR LICENSE NEGOTIATIONS
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId" rendered="{!!(tobeEdited == ln17.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveRecord}" reRender="blockId" rendered="{!tobeEdited == ln17.id}"/>
</apex:column> -->

<apex:column value="{!ln17.Org__c}" />
<apex:column value="{!ln17.Business_Unit__c}"/>

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17.BMS_Code__c}" rendered="{!tobeEdited == ln17.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17.BMS_Code__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column value="{!ln17.License_Type2__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 

<apex:column value="{!ln17.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17.id)}"/>

 
 
</apex:column> 

<apex:column headerValue="Annualized Cost" value="{!ln17.X2017_Subtotal__c}">
<!--<apex:facet name="footer">
    <apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!tTotal}" />
    </apex:outputText>

   
</apex:facet>-->


</apex:column>
<apex:column headerValue="Sum of Cost + 10%" value="{!ln17.Sum_of_Cost_10__c}"/>

<apex:column headerValue="1 month from 2016" value="{!ln17.One_Month_from_2016__c}">
    <apex:facet name="footer">
  <apex:outputPanel layout="block" style="text-align:right"> 
  SLA Cost:

  </apex:outputPanel>
  </apex:facet>
  </apex:column>

<apex:column headerValue="Total 2017 SLA" value="{!ln17.X2017_Cost__c}">
  <apex:facet name="footer">
              <apex:outputText style="font-weight:800" value="${0, number, ###,###,###,##0.00}">
              <apex:param value="{!aTotal}" />
              </apex:outputText>
               
</apex:facet>
</apex:column>
<apex:column headerValue="Comments">
    <apex:inputfield value="{!ln17.Comments__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.Comments__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 


</apex:pageBlockTable>


</apex:pageBlock>





<!----ONLY NEEDED FOR LICENSE NEGOTIATIONS-------------------------------------------------------------------------------------->
<!--<apex:pageBlock title="New Licenses Needed for 2017" id="newblock">

<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

<apex:column HeaderValue="Org">
<apex:inputField value="{!wrapper.lic.Org__c}" />
</apex:column>

<apex:column HeaderValue="Business Unit">
<apex:inputField value="{!wrapper.lic.Business_Unit__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type2__c}"  />
</apex:column>

<apex:column HeaderValue="BU Agrees to Pay">
<apex:inputField value="{!wrapper.lic.BU_Agrees_to_Pay__c}" />
</apex:column>

<apex:column HeaderValue="2017 Number Needed">
<apex:inputField value="{!wrapper.lic.X2017_Total_Needed__c}"/>
</apex:column>

<apex:column HeaderValue="Comments">
<apex:inputField value="{!wrapper.lic.Comments__c}"/>
</apex:column>


</apex:pageBlockTable>


</apex:pageBlock>-->

<!--<apex:commandButton value="Save" action="{!addsave}" />-->




        

<apex:pageBlock id="blockId2" title="2017 Add-Ons">
<!--
<apex:pageBlockSection columns="1">

<td>
<apex:outputText style="font-weight:800" label="Total Add-on Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aoTotal}" />
</apex:outputText>
</td>

</apex:pageBlockSection>-->

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17Addon}" var="ln17ao">

<apex:outputLink value="{!ln17ao.Id}">{!ln17ao.Name}</apex:outputLink>
<!--ONLY NEEDED FOR LICENSE NEGOTIATIONS
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId2" rendered="{!!(tobeEdited == ln17ao.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17ao.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveAddonRecord}" reRender="blockId2" rendered="{!tobeEdited == ln17ao.id}"/>
</apex:column> -->

<apex:column value="{!ln17ao.Org__c}" />

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17ao.BMS_Code__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17ao.BMS_Code__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column>    

<apex:column value="{!ln17ao.License_Type2__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17ao.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column> 

<apex:column value="{!ln17ao.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17ao.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column>    

<apex:column headerValue="Annualized Cost" value="{!ln17ao.X2017_Subtotal__c}" >
 <apex:facet name="footer">
      <apex:outputPanel layout="block" style="text-align:right"> 
      True-up Cost: 
      </apex:outputPanel>
  </apex:facet>
</apex:column>
  
<apex:column headerValue="2017 True-Up Cost" value="{!ln17ao.True_Up_Cost__c}">
  <apex:facet name="footer">
        <apex:outputText style="font-weight:800" value="${0, number, ###,###,###,##0.00}">
        <apex:param value="{!aoTotal}" />
        </apex:outputText>
</apex:facet> 
</apex:column>
<apex:column headerValue="Comments">
    <apex:inputfield value="{!ln17ao.Comments__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.Comments__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column> 


</apex:pageBlockTable>


</apex:pageBlock>
</apex:form>

<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="2016 Licenses">
<apex:pageBlockSection columns="1">

<apex:pageBlockTable value="{!LicenseList}" var="ln">

<apex:outputLink value="{!ln.Id}">{!ln.Name}</apex:outputLink>

<apex:column value="{!ln.Org__c}" />
<apex:column value="{!ln.Business_Unit__c}" />
<apex:column value="{!ln.BMS_Code__c}" />
<apex:column value="{!ln.License_Type__c}" />
<apex:column value="{!ln.Monthly_Unit_Price__c}" />
<apex:column headerValue="2016 Starting Amount" value="{!ln.X2016_Starting_Amount__c}" />
<apex:column headerValue="2016 Running License Total" value="{!ln.Running_License_Total__c}" />
<apex:column headerValue="Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Charge" value="{!ln.X2016_Cost__c}"/>
<apex:column headerValue="One Month charge in 2017" value="{!ln.One_Month_from_2016__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>




<!--------------------------------------------------------------------------------------------------------->
</apex:page>

 
  • March 16, 2017
  • Like
  • 0
Below is the code. Can someone help to get the count outside for loop 

public static void generateInvoiceIds(Map<Id, Payment__c> newMap) {
    
        List<Payment__c> updatednewPaymentRecords = new List<Payment__c>();
         for(Payment__c record :newMap.values()) {
            if(record.TransactionStatus__c == 'Credit note'  && record.InvoiceNumberAuto__c == null){
                Payment__c record1 = new Payment__c(id=record.id);
                record1.InvoiceDate__c = System.today();
           // system.debug('CLINIC ID - ' + newPaymentRecord.ClinicIdAuto__c + ' --- APPOINTMENT MONTH - ' + newPaymentRecord.OpportunityAppointmentMonthAuto__c);
            Integer numberOfInvoices = [select count() from Payment__c where Opportunity__r.Clinic__c = :record.ClinicIdAuto__c and InvoiceNumberAuto__c != null and (TransactionStatus__c = 'Paid' OR  TransactionStatus__c = 'Credit note') and OpportunityAppointmentMonthAuto__c = :record.OpportunityAppointmentMonthAuto__c];
            if(record.TransactionStatus__c == 'Credit note')
            record1.InvoiceNumberAuto__c = 'G-VU-' + record.OpportunityAppointmentDate__c.format('MMYY') + '-' + record.ClinicInvoiceCodeAuto__c + '-' + (numberOfInvoices + 1);
            else
            record1.InvoiceNumberAuto__c = 'TR-VU-' + record.OpportunityAppointmentDate__c.format('MMYY') + '-' + record.ClinicInvoiceCodeAuto__c + '-' + (numberOfInvoices + 1);
            updatednewPaymentRecords.add(record1);
        }
            
        }
        update updatednewPaymentRecords;
    }
Today I have encountered a wierd problem while sharing the records through Apex. Appreciate if someone can help me understand the root cause or faced the similar issue earlier.

Flow of the Code is :
Trigger -> Apex Controller

Objects =>
1. CustomObject__c [ lookup to Account ]
2. AccountTeam__c [ Custom Object having a lookup to Account, It behave like standard AccountTeamMember Object but is a custom defined. This contains all the TeamMembers to a particular Account]

The idea is to share CustomObject__c records (After Insert) with the referred Account.

Below is the code :

TRIGGER
trigger createSharingTrigger on CustomObj__c (after insert) {

  list <CustomObj__c >  recordsList = new list<CustomObj__c > ();
  // Below controller has the logic to share records with Team Members
  sharingRuleController SRObj = new sharingRuleController();

  if (Trigger.isInsert){
    for(CustomObj__c  rec : trigger.new){
    recordsList.add(rec);
    }
   
    if (!recordsList.isEmpty()) {
       SRObj.createSharingRecords(recordsList);
    }
  }
}

APEX Controller :
public without sharing class sharingRuleController
{
    public void createSharingRecords(List<CustomObject__c> shareThisRecords)
      {
         set<Id> accountIdSet = new set<Id>();
         list<CustomObject__Share> shareObjectList = new list<CustomObject__Share>();
    
         for (CustomObject__c cObj: shareThisRecords){
              accountIdSet.add(cObj.Account__c);
          }
    
         list <AccountTeam__c> accTeamMembersList = [select Account__c, TeamMemberID__c, from AccountTeam__c  where Account__c IN :accountIdSet];
     
        for (CustomObject__c cObj: shareThisRecord){

            for (AccountTeam__c TeamMember : accTeamMembersList){
       
                if (TeamMember.Account__c == shareThisRecord.Account__c){
                    CustomObject__Share cShare = new CustomObject__Share();
                    cShare.ParentId = shareThisRecord.Id; // -> This does not show records in Table, although it has same ID value. The ID is generated for sharing record but cannot query the ID, returns no rows.
                        //GAPShare.ParentId = 'a0p17000000NhM9AAK'; -> This Works
                    cShare.UserorGroupId = TeamMember.TeamMemberID__c;
                    cShare.AccessLevel = 'Read';
                    shareObjectList.add(cShare);
                }
            }   
        }

    try{        
             Database.SaveResult[] shareInsertResult = Database.insert(shareObjectList, false);
             system.debug('GAPShareInsertResult => ' + GAPShareInsertResult); -> GetID has an ID value, and isSuccess is "TRUE". But the record when retrieved using the generated ID returns no rows.
    }catch(Exception e){
       // No exceptions thrown either.
       System.debug("Thrown an exception");
    }
}

Really Appreciate if someone can help me identify the issue here. The confusion is that the records are being saved and their respective generated IDs are shown in Debug logs (saveResult[]). And also, if the parentID of the sharedRecord is hardcoded, it works !!!

Thanks in Advance,
Ajaz.
  • October 28, 2015
  • Like
  • 0
Hi everybody.
I am new into salesforce and I have a question.

Is it possible to add my free developer user to a customer production "developer sandbox"?

I tried to add a user in the production org with my credentials but only could add as "Chatter..."
I like to transfer the customer production Data (Meta and Apex) to my developer org via eclipse.

Does a user need a special configuration/setting to achieve this?
Special role or profile settings?
All the posts I found didn't help me.

Anyone a suggestion, tip or links?

Thanks in advance and kind regards
Marcus
picklist values to view the selected particular details
if the picklist values are submitted,rejected and approved
when i selecting the submitted then it will show only submitted details without search button
I would like to validate if an account is in the Account Contact Relationship object. I can't find the Account Contact Relationship  API name.
As it is not possible to do it with the Lookup filter criteria, I 'd like to do in the trigger, but I am begining to think this is not possible neither.

Any tip with this issue?

Thanks
I want to make a VF page that shows members of a campaign as well as has a searchfield to find contacts to add to the campaign. So the action for the search field will find all contacts that match and display them on a list. Then the user can select a contact and click on the name and that contact would be added to the campaign. 

My problem is that I don't know how to implement that last bit. Since the list of contats is displayed with a pageBlockTable how does the controller know which contact was selected.

Here is my VF page markup

<apex:page standardController="Campaign" extensions="showCampaignMembers">
  <apex:form >
    <apex:pageBlock title="{!campaign.name}">
      <apex:pageBlockSection title="Criteria">
      <apex:outputLabel value="Enter Name Snippet"/>
      <apex:inputText value="{!nameQuery}"/>
      <apex:commandButton action="{!executeSearch}" value="Search"/>
   </apex:pageBlockSection>
    
   <apex:pageBlockTable value="{!contacts}" var="con">
      <apex:column headerValue="Name">
         <apex:outputLink value="/{!con.id}/e?retURL={!URLENCODE('/apex/RetUrlSearchPage?query='+nameQuery)}">{!con.Name}</apex:outputLink>
      </apex:column>
      <apex:column value="{!con.Participant__c}"/>
   </apex:pageBlockTable>
   <apex:pageBlockSection title="Participants in Campaign">
     <apex:pageBlockTable value="{!participants}" var="part">
       <apex:column value="{!part.FirstName}"/>
       <apex:column value="{!part.LastName}"/>
       <apex:column value="{!part.Email}"/>
       <apex:column value="{!part.Status}"/>
                 
     </apex:pageBlockTable>
   </apex:pageBlockSection>
 </apex:pageBlock>
  </apex:form>
</apex:page>

-----------
And the controller
-----------

public class showCampaignMembers 
{
 public String nameQuery {get; set;}
 public List<Contact> contacts {get; set;}
 Public List<CampaignMember> participants {get; set;}
 private ApexPages.StandardController std;
 
 public PageReference executeSearch()
 {
  String queryStr='%' + nameQuery + '%';
  contacts=[select id, Name, Participant__c 
            from Contact 
            where name like :queryStr];
            
  return null;
 }
  
 public showCampaignMembers(ApexPages.StandardController stdCtrl)
 {
   Std = stdCtrl;
    Participants = [SELECT id, FirstName, LastName, Email, Status FROM CampaignMember
        WHERE CampaignId = :std.getId() ORDER BY FirstName];
  }

}

I appreciate any help.
All,

I'm trying to populate the Account Website field based on a child Contact's Email field. I need to grab the characters that occur after (to the right of) the '@' character. What is the proper String Method to use here?
a.Website = String.valueOf(con.Email.Split('@')); //Incorrect String Method
Below is the full trigger I've written so far:

Class:
public class Update_AccountWebsite {
    protected final Contact[] contactNewList;
    protected final Contact[] contactOldList;
    
    public Update_AccountWebsite (Contact[] contactOldList, Contact[] contactNewList) {
        this.contactNewList = contactNewList;
        this.contactOldList = contactOldList;
    }
    
    public void executeUpdate_AccountWebsite() {
        List<Contact> contList = new List<Contact>(contactNewList);
        Set<Id> accountIds = new Set<Id>();
        for(Contact c :contactNewList){
            if(c.id != null && c.Email != null){
                accountIds.add(c.AccountId);
            }
        }
        List<Account> acctList = [Select Id, Name, Website, (Select Id, AccountId, Email From Contacts) From Account Where Id in :accountIds];
        for(Account a :acctList){
            for(Contact con :a.Contacts){
                a.Website = String.valueOf(con.Email.Split('@')); //Incorrect String Method
                a.Contacts.add(con);
                system.debug(acctList);
                system.debug(contList);
                system.debug(a.Contacts);
            }
        }
    }
}

Trigger:
trigger MasterContactTrigger on Contact (
    before insert, after insert, 
    before update, after update, 
    before delete, after delete) {
        Contact[] contactOldList = trigger.IsDelete ? null : trigger.old;
        Contact[] contactNewList = trigger.IsDelete ? trigger.old : trigger.new;
        
        if (Trigger.isBefore) {
            if (Trigger.isInsert) {
            }
            if (Trigger.isUpdate) {
            }
            if (Trigger.isDelete) {
            }
        }
        
        if (Trigger.IsAfter) {
            if (Trigger.isInsert) {
                new Update_AccountWebsite(contactOldList, contactNewList).executeUpdate_AccountWebsite();
            }
            if (Trigger.isUpdate) {
                new Update_AccountWebsite(contactOldList, contactNewList).executeUpdate_AccountWebsite();
            }
            if (Trigger.isDelete) {
            }
        }
}

 
Hi !

Is there a tool out there to save SOQL query results as JSON in AWS S3? We are planning to write a system to cache SOQL query results using SalesForce API, before start coding I would like to know if such solution already exists.

thanks,
Alex.
i am trying to update a date field on my contacts that are marked as "admin Contacts" everytime a matching date field on my accounts are updated. 

Class:
public with sharing class AdminUsersAccount
	{
		public void leadAlerts(List<Account> lstAcct)
		{
			sendAlertsPrivate(lstAcct);
		}
	
		private void sendAlertsPrivate(List<Account> lstAcct)
		{
			List<Contact> lstUpdateCon = new List<Contact>();
			
			Set<Id> accID = new Set<Id>();
			for (Account a : lstAcct)
				accID.add(a.Id);	
			map<Id, Contact> conMap = new map<Id, Contact>([SELECT Id, Admin_User__c, Account_Expiration__c FROM Contact WHERE Admin_User__c = true AND AccountId IN :accID]);
	
			for(Account acc : lstAcct)
			{	
				
				if(conMap.containsKey(acc.Id))
				{
					if(acc.Approved_Date__c != null)
					{
						Date tdy = date.today();
						Date expire = acc.Approved_Date__c.addDays(365);
						boolean approved = expire >= tdy;
						lstUpdateCon.add(new Contact(Account_Expiration__c = approved?conMap.get(acc.Id).Account_Expiration__c: null));
					}
					else
					{
						lstUpdateCon.add(new Contact(Account_Expiration__c = null));
					}
				}
			}
			if(!lstUpdateCon.isEmpty())
				update lstUpdateCon;		
		}
	}

Trigger:
 
trigger AdminUsersAccountTrigger on Account (after update) 
	{
		AdminUsersAccount objAcctHandler = new AdminUsersAccount();
		
		if (Trigger.IsUpdate)
		{
			objAcctHandler.leadAlerts(Trigger.New);
		}
	    
	}

im really not sure where this is going wrong... i get no errors but nothing happens when updating the field on the account. 
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger eventCreateJobOutcome caused an unexpected exception, contact your administrator: eventCreateJobOutcome: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.eventCreateJobOutcome: line 2, column 1
Hi,

I trying to do roll up summary on Opportunity amount but I need to exclude the duplicate records.

We have this custom obj and Opportunity (Master detail relation) Custom obj is master and opp is detail object. We add Opp records to Cust Obj record via related list. We want to have a roll up summary on opportunity records amount but need to exclude the duplicates Opportunities if there are any. Any help is appreciated
Hi there:
Let me start by saying I'm not a developer and very new to development. I'm trying to update a field in on all leads where the business logic results to true, I want the logic to run every 65 minutes. I've written my batch schedule class and schedule class. My batch schedule class works and I can save it in my apex class. However, my schedule class does not work outside of the developer console - everytime I save it as a apex class - it gives me an error message "unexpected token: 'MQLEscalationBatch' at line 1 column 0". Any assistance would be greatly appreciated.

 Batch Class:

global class MQLEscalationBatch implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC)    {
      String query= 'SELECT Id, Company, OwnerId, Escalation_Calculation__c,Status, Inside_Sales_Representative__c 
FROM Lead WHERE Escalation_Calculation__c > 7.50 AND Escalation_Calculation__c < 19.00 AND Inside_Sales_Representative__c != NULL AND IsConverted = FALSE AND Sales_Initial_Last_Modification__c = NULL AND LastActivityDate = NUll ';

        //return Database.QueryLocator(query);

        return Database.getQueryLocator(query);

    }
     
    global void execute(Database.BatchableContext bc, List<Lead> scope)

    {
        for(Lead l: scope)
        {
            l.MQL_Alert__c = TRUE;
            system.debug(l);
        }
        update scope;
        }
        
    global void finish(Database.BatchableContext bc){
        
    }
}


Schedule Class: it gives me an error message "unexpected token: 'MQLEscalationBatch' at line 1 column 0

MQLEscalationBatch b = new MQLEscalationBatch();
database.executeBatch(b);
String sch = '0 05 * * * ?';
String jobID = database.executeBatch(b);
I have a multi picklist on the User record for Business Unit.  I have a VF Page that shows the list of licenses depending on the user logged in and their Business Unit.  

So for instance.  If my Business Unit is A and C, I want to see all licenses with a Business Unit of A and C.  

If I only have one option chosen for Business Unit on the User record, the User sees their licenses fine.  If the User record has more than one Business Unit chosen, the VF Page only shows column headers, no data.  How do I get it to show licenses for both (or more) Business Units?

This isn't all the code, the last half of the class is long and I didn't post it(Its for the first page block)
 

/*
Class/Method Name: LicenseList
Description: creates lists of licenses to be viewed on the LicenseSummaryHomePage VF Page for the License Community
Author/Date: Staci Gilmore 8/31/16
*/


public with sharing class LicenseList { 
private final License_Numbers__c ln; 
public user currentuser{get;set;} 
public id tobeEdited{get;set;}
public decimal aTotal{get;set;}
public decimal tTotal{get;set;}
public decimal aoTotal{get;set;}
public decimal Total{get;set;} 
//public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public LicenseList(ApexPages.StandardSetController controller) { 
currentuser=new User(); 
currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; 
this.ln = (License_Numbers__c)controller.getRecord(); 

} 

//------------------------------------------------------------------------------------

public List<License_Numbers__c> lntypes16 = new List<License_Numbers__c>();

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__c, One_Month_from_2016__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Running_License_Total__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY Order_Number__c, License_Type__c];
       

return lntypes16; 
} 


//-----------------------------------------------------------------------------
//Returns list of 2017 licenses from original order in contract
public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();


public List <License_Numbers__c> getLicenseList17()
{ 

selectedTypes=[select id, Name, BU_Agrees_to_Pay__c, Sum_of_Cost_10__c, X2016_Subtotal__c, One_Month_from_2016__c, Comments__c , 
                      License_Type2__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, 
                      X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c 
               FROM License_Numbers__c 
               where Business_Unit__c =:currentuser.Business_Unit_new__c AND 
                     License_Year__c = '2017' AND 
                     Add_On__c = false 
               ORDER BY Order_Number__c, License_Type__c];
    
aTotal = 0.0;
tTotal = 0.0;       
          for(License_Numbers__c a:selectedTypes){
                aTotal = aTotal + a.X2017_Cost__c; 
                tTotal = tTotal + a.X2017_Subtotal__c;  
        }
return selectedTypes; 




} 


   



//----Added 2/6/17-------------------------------------------------------------------------
//Returns list of 2017 licenses that were added after the 2017 contract was signed
public List<License_Numbers__c> selectedTypesAddon = new List<License_Numbers__c>();
 
public List <License_Numbers__c> getLicenseList17Addon(){ 

selectedTypesAddon=[select id, Name, True_Up_Cost__c, Sum_of_Cost_10__c, X2016_Subtotal__c, BU_Agrees_to_Pay__c, One_Month_from_2016__c, Comments__c , License_Type2__c, Add_On__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2017'AND Add_On__c = True ORDER BY Order_Number__c, License_Type__c]; 
aoTotal = 0.0;
       
        for(License_Numbers__c a:selectedTypesAddon){
                aoTotal = aoTotal + a.True_Up_Cost__c;  
        }
return selectedTypesAddon; 
} 


}
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" sidebar="false">
<!------------------------------------------------------------------------------------------------------>
<!--Based on option chosen for License Type, will show description of that license type-->
<apex:pageBlock title="License Definitions">
<apex:form id="theForm">
<apex:pageBlockSection columns="1">
<apex:selectList label="Please select a License Type"  value="{!discountScheduleID}" size="1" >
   <apex:actionSupport event="onchange" action="{!displayDescription}" rerender="description"/>
   <apex:selectOptions value="{!schedules}" />
</apex:selectList> 

<apex:outputText label="Description" id="description" value="{!OutPutString}"/>

<br></br><br></br><br></br><br></br>
</apex:pageBlockSection>
</apex:form>


<!--------------------------------------------------------------------------------------------------


<apex:pageBlockTable value="{!LicenseList17Total}" var="lntot">

<apex:outputLink value="{!lntot.Id}">{!lntot.Name}</apex:outputLink>

<apex:column headerValue="                           ">

  <apex:facet name="footer">
  <apex:outputPanel layout="block" style="text-align:left"> 
  SLA Cost + Add-on Cost:
  <apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!Total}" />
    </apex:outputText>
  
  
  </apex:outputPanel>
  </apex:facet>
</apex:column> 
 

</apex:pageBlockTable>-->

</apex:pageBlock>



<!--------------------------------------------------------------------------------------------------------->
<apex:form id="theForm">
<apex:pageBlock id="blockId" title="2017 Licenses">
<!--<apex:pageBlockSection columns="1">

<tr>
<apex:outputText style="font-weight:800" label="Total Contract + Add-on Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!Total}" />
</apex:outputText>

<apex:outputText style="font-weight:800" label="Total 2017 SLA" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aTotal}" />
</apex:outputText>

</tr>
</apex:pageBlockSection>-->

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17}" var="ln17">

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<!--ONLY NEEDED FOR LICENSE NEGOTIATIONS
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId" rendered="{!!(tobeEdited == ln17.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveRecord}" reRender="blockId" rendered="{!tobeEdited == ln17.id}"/>
</apex:column> -->

<apex:column value="{!ln17.Org__c}" />
<apex:column value="{!ln17.Business_Unit__c}"/>

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17.BMS_Code__c}" rendered="{!tobeEdited == ln17.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17.BMS_Code__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column value="{!ln17.License_Type2__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 

<apex:column value="{!ln17.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17.id)}"/>

 
 
</apex:column> 

<apex:column headerValue="Annualized Cost" value="{!ln17.X2017_Subtotal__c}">
<!--<apex:facet name="footer">
    <apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!tTotal}" />
    </apex:outputText>

   
</apex:facet>-->


</apex:column>
<apex:column headerValue="Sum of Cost + 10%" value="{!ln17.Sum_of_Cost_10__c}"/>

<apex:column headerValue="1 month from 2016" value="{!ln17.One_Month_from_2016__c}">
    <apex:facet name="footer">
  <apex:outputPanel layout="block" style="text-align:right"> 
  SLA Cost:

  </apex:outputPanel>
  </apex:facet>
  </apex:column>

<apex:column headerValue="Total 2017 SLA" value="{!ln17.X2017_Cost__c}">
  <apex:facet name="footer">
              <apex:outputText style="font-weight:800" value="${0, number, ###,###,###,##0.00}">
              <apex:param value="{!aTotal}" />
              </apex:outputText>
               
</apex:facet>
</apex:column>
<apex:column headerValue="Comments">
    <apex:inputfield value="{!ln17.Comments__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.Comments__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 


</apex:pageBlockTable>


</apex:pageBlock>





<!----ONLY NEEDED FOR LICENSE NEGOTIATIONS-------------------------------------------------------------------------------------->
<!--<apex:pageBlock title="New Licenses Needed for 2017" id="newblock">

<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

<apex:column HeaderValue="Org">
<apex:inputField value="{!wrapper.lic.Org__c}" />
</apex:column>

<apex:column HeaderValue="Business Unit">
<apex:inputField value="{!wrapper.lic.Business_Unit__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type2__c}"  />
</apex:column>

<apex:column HeaderValue="BU Agrees to Pay">
<apex:inputField value="{!wrapper.lic.BU_Agrees_to_Pay__c}" />
</apex:column>

<apex:column HeaderValue="2017 Number Needed">
<apex:inputField value="{!wrapper.lic.X2017_Total_Needed__c}"/>
</apex:column>

<apex:column HeaderValue="Comments">
<apex:inputField value="{!wrapper.lic.Comments__c}"/>
</apex:column>


</apex:pageBlockTable>


</apex:pageBlock>-->

<!--<apex:commandButton value="Save" action="{!addsave}" />-->




        

<apex:pageBlock id="blockId2" title="2017 Add-Ons">
<!--
<apex:pageBlockSection columns="1">

<td>
<apex:outputText style="font-weight:800" label="Total Add-on Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aoTotal}" />
</apex:outputText>
</td>

</apex:pageBlockSection>-->

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17Addon}" var="ln17ao">

<apex:outputLink value="{!ln17ao.Id}">{!ln17ao.Name}</apex:outputLink>
<!--ONLY NEEDED FOR LICENSE NEGOTIATIONS
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId2" rendered="{!!(tobeEdited == ln17ao.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17ao.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveAddonRecord}" reRender="blockId2" rendered="{!tobeEdited == ln17ao.id}"/>
</apex:column> -->

<apex:column value="{!ln17ao.Org__c}" />

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17ao.BMS_Code__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17ao.BMS_Code__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column>    

<apex:column value="{!ln17ao.License_Type2__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17ao.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column> 

<apex:column value="{!ln17ao.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17ao.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column>    

<apex:column headerValue="Annualized Cost" value="{!ln17ao.X2017_Subtotal__c}" >
 <apex:facet name="footer">
      <apex:outputPanel layout="block" style="text-align:right"> 
      True-up Cost: 
      </apex:outputPanel>
  </apex:facet>
</apex:column>
  
<apex:column headerValue="2017 True-Up Cost" value="{!ln17ao.True_Up_Cost__c}">
  <apex:facet name="footer">
        <apex:outputText style="font-weight:800" value="${0, number, ###,###,###,##0.00}">
        <apex:param value="{!aoTotal}" />
        </apex:outputText>
</apex:facet> 
</apex:column>
<apex:column headerValue="Comments">
    <apex:inputfield value="{!ln17ao.Comments__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.Comments__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column> 


</apex:pageBlockTable>


</apex:pageBlock>
</apex:form>

<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="2016 Licenses">
<apex:pageBlockSection columns="1">

<apex:pageBlockTable value="{!LicenseList}" var="ln">

<apex:outputLink value="{!ln.Id}">{!ln.Name}</apex:outputLink>

<apex:column value="{!ln.Org__c}" />
<apex:column value="{!ln.Business_Unit__c}" />
<apex:column value="{!ln.BMS_Code__c}" />
<apex:column value="{!ln.License_Type__c}" />
<apex:column value="{!ln.Monthly_Unit_Price__c}" />
<apex:column headerValue="2016 Starting Amount" value="{!ln.X2016_Starting_Amount__c}" />
<apex:column headerValue="2016 Running License Total" value="{!ln.Running_License_Total__c}" />
<apex:column headerValue="Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Charge" value="{!ln.X2016_Cost__c}"/>
<apex:column headerValue="One Month charge in 2017" value="{!ln.One_Month_from_2016__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>




<!--------------------------------------------------------------------------------------------------------->
</apex:page>

 
  • March 16, 2017
  • Like
  • 0
I have written a validation on the account which causes an exception. Like this validation hitting one trigger.
----------------Error message on Email --------------------
Fwd: Developer script exception from SeamlessDocs : CalculateNoOfContact : CalculateNoOfContact: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0011a00000LnAbbAAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please select Primary Consultation Call Contact for creating opportunity: [Primary_Demo_Contact__c] ()
---------------- Validation -----------------------------------
AND(
ISBLANK( Primary_Demo_Contact__c ),
NOT(ISBLANK( Demo_Date_and_Time__c ))
)
------------------This is the trigger -----------------------------------------
trigger CalculateNoOfContact on Contact (after insert,before delete,after update) {
    
    Set<Id>accid = new Set<Id>();
    List<contact>contactlist = new List<contact>();
    List<account>listacc = new List<account>();
    Map<Id,integer>mapCount = new Map<Id,integer>();
    Map<Id,integer>mapCountOld = new Map<Id,integer>();
    Map<Id,List<Contact>> currentAcc_Contact = new Map<Id,List<Contact>>();


    if(trigger.isinsert || trigger.isupdate){
        for(contact con:trigger.new){
            accid.add(con.accountId);
        }
    }
    if (trigger.isdelete){
        for(contact con:trigger.oldMap.values()){
            accid.add(con.accountId);
            if(currentAcc_Contact.containsKey(con.accountId)){
                List<Contact> currConList=currentAcc_Contact.get(con.accountId);
                currConList.add(con);
                currentAcc_Contact.put(con.accountId,currConList);
            }
            else{
                 currentAcc_Contact.put(con.accountId,new List<Contact>{con});
            }
        }
    } 
    
    if(accid.size() > 0){
         contactlist=[SELECT id,name,accountid,Account.Number_of_Contacts__c FROM contact WHERE accountid IN:accid];
    }
      System.debug('contactlist ::>'+contactlist);
    
    if(contactlist.size() >0 ){
        for(contact c:contactlist){
            if(c.Account.Number_of_Contacts__c > 0){
                    mapCountOld.put(c.accountId,c.Account.Number_of_Contacts__c.intvalue());
            }
            
            if(trigger.isinsert || trigger.isupdate ){
               if(mapCount.ContainsKey(c.accountId)){
                Integer prevCnt=mapCount.get(c.accountId);
                prevCnt++;
                mapCount.put(c.accountId,prevCnt);
                }else {
                   mapCount.put(c.accountId,1);
              }
            }
        
        }
    }
   System.debug('mapCount ::>'+mapCount);
   
   if(mapCount.size() >0 ){
      for(Id tmp:mapCount.keySet()){
          Account acc=new Account();
              acc.Id=tmp;
              acc.Number_of_Contacts__c=mapCount.get(tmp);
          listacc.add(acc);
      }   
    }
    else{
        if(trigger.isdelete && mapCountOld.size() > 0){
            for(Id tmp1:mapCountOld.keySet()){
              Account acc=new Account();
              acc.Id=tmp1;
                 System.debug('tmp1 ::>'+tmp1);
              acc.Number_of_Contacts__c= mapCountOld.get(tmp1) - currentAcc_Contact.get(tmp1).size();
                 System.debug('tmp1 ::>'+mapCountOld.get(tmp1));
                 System.debug('tmp1 ::>'+currentAcc_Contact.get(tmp1).size());
              listacc.add(acc);
            }
        }
        
    }
    
    
    System.debug('listacc ::>'+listacc);

    if(listacc.size()>0){
         update listacc;
    }
   
}



Thanks,
Sumit
Below is the code. Can someone help to get the count outside for loop 

public static void generateInvoiceIds(Map<Id, Payment__c> newMap) {
    
        List<Payment__c> updatednewPaymentRecords = new List<Payment__c>();
         for(Payment__c record :newMap.values()) {
            if(record.TransactionStatus__c == 'Credit note'  && record.InvoiceNumberAuto__c == null){
                Payment__c record1 = new Payment__c(id=record.id);
                record1.InvoiceDate__c = System.today();
           // system.debug('CLINIC ID - ' + newPaymentRecord.ClinicIdAuto__c + ' --- APPOINTMENT MONTH - ' + newPaymentRecord.OpportunityAppointmentMonthAuto__c);
            Integer numberOfInvoices = [select count() from Payment__c where Opportunity__r.Clinic__c = :record.ClinicIdAuto__c and InvoiceNumberAuto__c != null and (TransactionStatus__c = 'Paid' OR  TransactionStatus__c = 'Credit note') and OpportunityAppointmentMonthAuto__c = :record.OpportunityAppointmentMonthAuto__c];
            if(record.TransactionStatus__c == 'Credit note')
            record1.InvoiceNumberAuto__c = 'G-VU-' + record.OpportunityAppointmentDate__c.format('MMYY') + '-' + record.ClinicInvoiceCodeAuto__c + '-' + (numberOfInvoices + 1);
            else
            record1.InvoiceNumberAuto__c = 'TR-VU-' + record.OpportunityAppointmentDate__c.format('MMYY') + '-' + record.ClinicInvoiceCodeAuto__c + '-' + (numberOfInvoices + 1);
            updatednewPaymentRecords.add(record1);
        }
            
        }
        update updatednewPaymentRecords;
    }
Hi,
I have created a custom Case form on VF1 page with a Submit button and a custom Case controller class. When the user clicks on Submit button, a case gets created in Salesforce and navigates to another VF2 page for case acknowledgement stating 'Thank you for submission..'. Now, I, also want to display the Case number generated on VF2 page as soon as the user submits the case. Any ideas??