Posts

Showing posts from January 9, 2014

Write a trigger on Account when account is insert then calcuate total account those are vendor or buyer

Write a trigger on Account when Account is insert then calculate the  MaxCount for Account Type:Create Two custom field on account one field is AccountType(PickList) and add two value "Vendor" and other is "Buyer" and create Second field MaxCount(Number). when Account is added and AccountType__c = Vendor or Buyer the calculate the No of Account those have AccountType__C = Vendor or Buyer and Add value in MaxCount__c field. trigger onAccountUpdateAccoutType on Account (before insert) {       AggregateResult aggResBuyer = [select max(maxcount__c) from account where AccoutType__c='buyer'];        AggregateResult aggResVendor = [select max(maxcount__c) from account where AccoutType__c='vendor'];        Integer buyer,vendor;        if(aggResBuyer.get('expr0')==null)        {         buyer=0;        }        else        {          buyer = integer.valueof(aggResBuyer.get('expr0'));                }        if