• sfdc.dev.ax856
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 7
    Replies

Hello,

 

I am trying to write a trigger that updates the value of a field on an object when records are created on another object that references that particular record on the first object. For instance, I have a field on the ACCOUNT object called "Available number of contacts," I would like the value in this field to reduce by 1 whenever a record in the CONTACT object is created that references the particular Account. Here is the code, but I keep getting the same error when I hit save: "Variable Available_Number_of_Contacts does nto exist. Please review my code and let me know where I went wrong. Thank you.

 

 

trigger decreaseAvailableContactsOnAccount on Contact (after insert) {
  Map<Id,Integer> accountTotal = new Map<Id,Integer>();
  for(Contact c:Trigger.new) {
    if(c.accountid==null)
      continue;
    if(accountTotal.get(c.accountid)==null)
      accountTotal.put(c.accountid,1);
    else
      accountTotal.put(c.accountid,accountTotal.get(c.accountId)+1);
  }
  List<Account> accounts = new List<Account>();
  for(Account a:[SELECT id, Number_of_Available_Contacts__c 
                 FROM Account
                 WHERE id in :accountTotal.keyset()]) 
  {
    a.Number_of_Available_Contacts__c -= accountTotal.get(a.id);
    accounts.add(a);
  }
  update accounts;
}

 

Hi,

          I need to write a trigger to  get most recent record from related list "CampaignMember"  and update to it a custom field on parent "Contact".Any Idea?

Thanks

Hi ,

           Notes and Attachments related list on the Account displays Attachments not just from Account but also from Cases, Contacts, and Opportunities linked to the Account.I need to replicate the same behavior for my custom object.Is it possible to create a vf page as related list ? Any Idea..

 

Thanks



Hi All,

 

            I need to count related records in trigger and it should work in bulk.Any Idea ?

Hi All,

 

        I have a similar req   http://success.salesforce.com/ideaview?id=08730000000BrLkAAK.Any help is greatly appreciated.

 

Thanks.

Is there any possiblity to place a dashboard in to a vf page? if yes just post me the idea to implement.

 

 

Thank you..

 

 

Regards,

 

kiran