Posts

Showing posts from January 21, 2014

onContactAddTotalNumOfConAtAccLabel: When Contact is inserted or deleted then count the contact at Account Level

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)        

WAT on Account when phone is update then send the mail

trigger sendMailOnAccoutPhoneUpdate on Account (after update) { Set<Id> setAccountId= new Set<Id>(); List<Contact> lstContact= new List<Contact>(); List<String> lstEmail= new List<String>(); for(Account acc:trigger.new) { if(acc.phone != trigger.oldmap.get(acc.id).phone) {    setAccountId.add(acc.id); } } if(setAccountId!= null && setAccountId.size()>0) {   lstContact = [SELECT Id, Email, Name FROM Contact WHERE AccountId IN: setAccountId];  if(lstContact != null && lstContact.size()>0)  {    for(Contact objCon:lstContact)    {     if(objCon.Email != NULL)                 {                                                         lstEmail.add(objCon.Email);                 }    }    } } if(lstEmail != NULL && lstEmail.size()>0)     {         Messaging.SingleEmailMessage objMail = new Messaging.SingleEmailMessage();         objMail.setToAddresses(lstEmail);         objMail.setPlainTex

WAT on Contact when contact insert then send mail to that contact Email with EmailTemplate

trigger sendMailAfterContactInsert on Contact (after Insert) {     List<Contact> lstContact= new List<Contact>();     List<Messaging.SingleEmailMessage> lstEmailId=new List<Messaging.SingleEmailMessage>();     for(Contact con:trigger.new)     {       lstContact.add(con);     }     EmailTemplate emailTemp = [Select id from EmailTemplate where name= 'MyTestTemp'];     for(Contact conObj : lstContact)     {         Messaging.SingleEmailMessage msgObj = new Messaging.SingleEmailMessage();          if(conObj.Email!=null)          {              msgObj.setTargetObjectId(conObj.Id);              msgObj.setTemplateId(emailTemp.Id);              lstEmailId.add(msgObj);          }            else          {              conObj.Email.addError('Plz enter Email Id');          }             }     if(lstEmailId.size()>0)     {         Messaging.SendEmail(lstEmailId);     } }

Show Opp and OPL

public class myOppwithOppLineItem {         public boolean isCheck{get;set;}     public String getOpp() {         return null;     }     public List<Opportunity> lstOpp{get;set;}         public List<wrapperClass> lstwrapperClass {get;set;}         public class wrapperClass{         public string OpportunityName {get;set;}        // public boolean isCheck{get;set;}         public List<wrapperChild> lstopli {get;set;}         public wrapperClass(string OppName){             this.OpportunityName = OppName ;             lstopli  = new List<wrapperChild>();         }     }         public class wrapperChild{         public OpportunityLineItem opplI {get;set;}         public wrapperChild(OpportunityLineItem opli){             this.opplI = opli;         }     }     Map<string,wrapperClass> mapOppNameClass = new Map<string,wrapperClass>();     public myOppwithOppLineItem (){         lstwrapperClass = new List<wrapperClass>