Posts

Showing posts from January, 2014

Based on Profile Select Sobjects............

Cls:  SobjectListcls public class SobjectListcls {      set<string> salesforceObjectSet = new set<string>();     Map<Id,List<ObjectPermissions>> permissionsetIdAndlstObjectPermissions = new Map<Id,List<ObjectPermissions>>();       public string strSobjectName{get;set;}     public SobjectListcls()     {       onlyReadPerrmission();       system.debug('sobject...'+salesforceObjectSet);     }     public void onlyReadPerrmission()     {         String userid = UserInfo.getUserId();         User thisUser = [select id, profile.Name from User where id=:userid];          system.debug('UserName...'+thisUser);         permissionset perset = [select id from permissionset where PermissionSet.Profile.id =:thisUser.profileId];         system.debug('check ---------perset'+perset);             PermissionSetAssignment[] lstPermissionSetAssignment =[SELECT AssigneeId,PermissionSetId FROM PermissionSetAssignment where Assi

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>

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){  

Use Of Standard Set Of Controller

Image
The Code used is as follows : VF Page :  <apex:page controller="opportunityList2Con">      <apex:form >         <apex:pageBlock >             <apex:pageBlockTable value="{!opportunities}" var="o">                 <apex:column value="{!o.name}"/>                 <apex:column value="{!o.closedate}"/>             </apex:pageBlockTable>                          <apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}"/>             <apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}"/>             <apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) < setCon.ResultSize}" value="{!setCon.pageNumber * setCon.pageSize} Of {!setCon.ResultSize}"></apex:outputText>             <apex:outputText ren

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