Posts

Showing posts from January 20, 2014

Account and their Contacts

VF page Name: ShowAccountAndContactAsHierarchyView <apex:page controller="accconhierarchy">   <apex:form >       <apex:pageBlock >       <style type="text/css">         .showContacts {             background: transparent url('/img/alohaSkin/twisty_sprite.png') 0 0 no-repeat;         }         .hideContacts {             background: transparent url('/img/alohaSkin/twisty_sprite.png') 0 -11px no-repeat;         }     </style>                   <apex:outputPanel layout="none"                         rendered="{!accountList.size!=0}">                         <table id="tableAccount" class="list" border="0" cellpadding="0" cellspacing="0">                             <thead>                                 <tr class="headerRow">                                     <th class="actionColumn">

onAccountCalculateTotalAssestPriceOnUpdateAccount on Account

trigger onAccountCalculateTotalAssestPriceOnUpdateAccount on Account (before update) {       Set<Id>accId = new Set<Id>();   List<Asset> lstass = new List<Asset>();   Map<Id,List<Asset>> mapAss = new Map<id,List<Asset>>();       for(Account acc:trigger.new)   {     accId.add(acc.id);   }     lstAss= [Select price ,id, accountId from Asset where accountId In:accId];   if(lstAss.size()>0&&lstAss!=null)   {   for(Asset assObj:lstAss)   {     if(mapAss.get(assObj.AccountId)==null)     {         mapAss.put(assObj.AccountId, new List<Asset>());     }     mapAss.get(assObj.AccountId).add(assObj);       }     for(Account accObj:trigger.new)   {     if(mapAss !=null && mapAss.get(accObj.Id)!=null)   {    List<Asset> lstasset = new List<Asset>();    Decimal total=0;    lstasset = mapAss.get(accObj.id);      for(Asset assObj:lstasset)    {

onAccountAddTotalAmountOfOppAmount on Account

trigger onAccountAddTotalAmountOfOppAmount on Account (before update) {     if(clsForStatusofType.thirdrun == false)     {          clsForStatusofType.thirdrun=true;     }     else     {         return;     }     Set<Id>accid = new Set<Id>();     map<Id,List<Opportunity>> mapopp= new map<Id,List<Opportunity>>();         List<Opportunity> lstopp = new List<Opportunity>();     List<Account>lstacc = new List<Account>();     for(Account acc:trigger.new)     {          accid.add(acc.id);     }         lstopp =[Select Amount,Id,AccountId from Opportunity where AccountId In:accid];     if(lstopp.size()>0 && lstopp!=null)     {     for(Opportunity opp:lstopp)     {          if(mapopp.get(opp.AccountID)==null)         {             mapopp.put(opp.AccountID,new List<Opportunity>());         }         mapopp.get(opp.AccountId).add(opp);     }   for(Account accObj:trigger.new)   {        

onAssestWhenAssestAddedOppAndOPLCreated on Asset

trigger onAssestWhenAssestAddedOppAndOPLCreated on Asset (after insert) {   List<Opportunity> lstopp = new List<Opportunity>();   List<OpportunityLineItem> lstopl = new List<OpportunityLineItem>();   List<PricebookEntry> lstpbe = new List<PricebookEntry>();   for(Asset a:trigger.new)   {    Opportunity opp = new Opportunity();    opp.Name= a.Name+'_'+'Opportunity';    opp.CloseDate=Date.Today();    opp.stageName='won';    opp.AccountId=a.AccountId;     lstopp.add(opp);     }             lstpbe =[select id from PricebookEntry limit 2];   if(lstopp.size()>0)   {   insert lstopp;       if(lstpbe.size()>0)  {   for(Opportunity oppObj:lstopp)    {     for(PricebookEntry ids:lstpbe)              {   OpportunityLineItem opl = new OpportunityLineItem();   opl.OpportunityId=oppObj.id;   opl.Description='just for chek';

onContactAddTotalNumOfConAtAccLabel

trigger onContactAddTotalNumOfConAtAccLabel on Contact (after delete, after insert) {         List<Account> lstacc=new List<Account>();     set<ID> accid= new Set<Id>();     list<Account> lstAccountToUpdate = new list<Account>();     if(trigger.isInsert && trigger.IsAfter)  {                   for(Contact con:trigger.new)               {                 accid.add(con.AccountID);               }              lstacc= [Select ID, TotalContact__c from Account where ID In: accid];          if(lstacc.size()>0)      {                               for(Account accObj:lstacc)                   {                              for(Contact conObj:trigger.new)                              {                                  if(accObj.ID==conObj.AccountID)                                  {                                         Integer i=0;                                             if(accObj.TotalContact__C!=null)        

S2S

trigger trgOnBankS2SExample on Bank__c (after Insert) { List<Contact>lstCon = new List<Contact>();         lstCon =[Select Id from Contact where id='0039000000mi2am'];       List<PartnerNetworkConnection>    lstPnC = new List<PartnerNetworkConnection>();         lstPnC = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ContactId =:lstCon[0].id and ConnectionStatus='Accepted'];                 List<PartnerNetworkRecordConnection> recordConnectionToInsert  = new List<PartnerNetworkRecordConnection>  ();         for (Bank__C BObj : Trigger.new){               PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();             newrecord.ConnectionId = lstPnC[0].Id;             newrecord.LocalRecordId = BObj .id;             recordConnectionToInsert.add(newrecord);                   }         if (recordConnectionToInsert.size() > 0){             System.debug(

OnAddProductUpdateTotalProductAtAccount

trigger OnAddProductUpdateTotalProductAtAccount on OpportunityLineItem (after Insert,after update) {         set<id> setOpli=new set<id>();     set<id> opportunityId=new set<id>();         for(OpportunityLineItem oppLi:trigger.new){         setOpli.add(oppLi.id);         opportunityId.add(oppLi.opportunityId);     }     List<Opportunity> lstOpp = [select Id,Name,Price_and_Quantity__c from Opportunity where Id In :opportunityId];     List<OpportunityLineItem> lstOpplI = [select Id,Quantity,TotalPrice,OpportunityId from OpportunityLineItem where Id In :setOpli];         Map<id,Opportunity> mapOpp=new Map<id,Opportunity>();     Map<Id,List<OpportunityLineItem>> mapOppIdOPLI = new Map<Id,List<OpportunityLineItem>>();         for(Opportunity opp :lstOpp){         mapOpp.put(opp.Id ,opp);     }         for(OpportunityLineItem opli :lstOpplI){         if(mapOppIdOPLI.get(opli.OpportunityId)==null){