• santoshk.behera1.3878016627537622E12
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 5
    Replies
scenario:
1) when i will enter any wrong data to the input text field and click the button , it shold show an error message below the field.

2)when i should enter the correct data to the input text field, and click the button, it should call the action method of that button which is writtten in controller.
Should i create a merge button on pagelayout or create a link on the page layout. "Merge account records" one standard link is available in account tab homepage. how I should get exact replica of that functionality through custom link or custom button.other then system administrator ,the standard users have the facility to merge records.Please some one give suggestion me.
Should i create a merge button on pagelayout or create a link on the page layout. "Merge account records" one standard link is available in account tab homepage. how I should get exact replica of that functionality through custom link or custom button.other then system administrator ,the standard users have the facility to merge records.Please some one give suggestion me..  
I have created custom object.when error will generate ,it has to logged into the custom object with excsption message and record Id. kindly help me.

trigger  countNoOfContact on Contact (after insert,after update,after delete,after undelete) {
  
HandllingError__c errObj=new HandllingError__c();
    try
    {  
Set<ID> setAccId=new Set<ID>();
   
    if((trigger.IsInsert)||(trigger.IsUndelete)||(trigger.IsUpdate))
    {
  for(Contact con1:trigger.new)
        {   
   if(con1.AccountId!=null)
            {
                setAccId.add(con1.AccountId);
            }
       } 
    }
   
    if((trigger.IsDelete)||(trigger.IsUpdate))
    {       
  for(Contact con1:trigger.new)   // error will generate here, delete operation deals with trigger.old. Problem is :erroris not logged into object.
        {   
   if(con1.AccountId!=null)
            {
    setAccId.add(con1.AccountId);
            }
       }    
    }
   
Map<ID,Account> mapToAccount=new Map<ID,Account>([select id,No_Of_Contacts__c,(select id from Contacts) from Account where id in:setAccId ]);
   
    for(ID accId:mapToAccount.keySet())
    {
        Account acc=mapToAccount.get(accId);
  acc.No_Of_Contacts__c=acc.Contacts.size();
    }    
   
    update mapToAccount.values();
}

catch(DMLException excp)
{
        errObj.Exception_Message__c=excp.getMessage();
        errObj.Line_Number__c=excp.getLineNumber();
        //errObj.Name=excp.getTypeName();
        insert errObj;
    }
}
trigger  countNoOfContact on Contact (before insert,after insert,after update,after delete,after undelete) {
   
 
      Set<ID> setAccId=new Set<ID>();
       Set<ID> oldAccId = new Set<ID>();
   Map<Id,Integer> newContactMapping=new Map<Id,Integer>();
 
    if((trigger.IsInsert)||(trigger.IsUndelete))
    {
        
    for(Contact con1:trigger.new)
    {   
       if(con1.AccountId!=null)
       {
          setAccId.add(con1.AccountId);
           if(newContactMapping.containsKey(con1.AccountId)){
               newContactMapping.put(con1.AccountId,  newContactMapping.get(con1.AccountId)+1);
              
           }
           else
           {
              newContactMapping.put(con1.AccountId, 0);  
           }
          
       }
   
   } 
    }
   
    else if((trigger.IsDelete)){
       
      for(Contact con1:trigger.old)
    {   
       if(con1.AccountId!=null)
       {
          setAccId.add(con1.AccountId);
           if(newContactMapping.containsKey(con1.AccountId)){
               newContactMapping.put(con1.AccountId,  newContactMapping.get(con1.AccountId)+1);
              
           }
           else
           {
              newContactMapping.put(con1.AccountId, 0);  
           }
          
       }
   
   }   
       
   
    }
   
    else if(trigger.IsUpdate)
       
    {
      
        for(Contact con1:trigger.new)
        {
          
            if(con1.AccountId!=trigger.oldMap.get(con1.id).AccountId)
            setAccId.add(con1.AccountId);
            oldAccId.add(trigger.oldMap.get(con1.id).AccountId);
            if(con1.AccountId!=null)  
               
            {     
               
                if(newContactMapping.containsKey(con1.AccountId)){
               newContactMapping.put(con1.AccountId,  newContactMapping.get(con1.AccountId)+1);
              
           }
           else
           {
              newContactMapping.put(con1.AccountId, 0);  
           }
            }
           
           
        }
       
    
    }
           
       
       
       Map<ID,Account> mapToAccount=new Map<ID,Account>([select id,No_Of_Contacts__c,(select id from Contacts )from Account where id in:setAccId ]);
       Map<ID,Account> mapToAccount1=new Map<ID,Account>([select id,No_Of_Contacts__c,(select id from Contacts)from Account where id in:oldAccId ]);
   
   
   
                for(ID accId:mapToAccount.keySet())
                {
                    Account acc=mapToAccount.get(accId);
                    if(trigger.IsInsert){
                    acc.No_Of_Contacts__c=acc.Contacts.size()+ newContactMapping.get(accId);
                    }
                    else{
                         acc.No_Of_Contacts__c=acc.Contacts.size()- newContactMapping.get(accId);
                    }
                }      
                   
                   
                 update mapToAccount.values();

             for(ID accId:mapToAccount1.keySet())
                {
                    Account acc=mapToAccount1.get(accId);
                    if(trigger.IsInsert){
                    acc.No_Of_Contacts__c=acc.Contacts.size()+ newContactMapping.get(accId);
                    }
                    else{
                         acc.No_Of_Contacts__c=acc.Contacts.size()- newContactMapping.get(accId);
                    }
                }      
                   
                   
                 update mapToAccount1.values();   
                       
}
scenario:
1) when i will enter any wrong data to the input text field and click the button , it shold show an error message below the field.

2)when i should enter the correct data to the input text field, and click the button, it should call the action method of that button which is writtten in controller.
I have created custom object.when error will generate ,it has to logged into the custom object with excsption message and record Id. kindly help me.

trigger  countNoOfContact on Contact (after insert,after update,after delete,after undelete) {
  
HandllingError__c errObj=new HandllingError__c();
    try
    {  
Set<ID> setAccId=new Set<ID>();
   
    if((trigger.IsInsert)||(trigger.IsUndelete)||(trigger.IsUpdate))
    {
  for(Contact con1:trigger.new)
        {   
   if(con1.AccountId!=null)
            {
                setAccId.add(con1.AccountId);
            }
       } 
    }
   
    if((trigger.IsDelete)||(trigger.IsUpdate))
    {       
  for(Contact con1:trigger.new)   // error will generate here, delete operation deals with trigger.old. Problem is :erroris not logged into object.
        {   
   if(con1.AccountId!=null)
            {
    setAccId.add(con1.AccountId);
            }
       }    
    }
   
Map<ID,Account> mapToAccount=new Map<ID,Account>([select id,No_Of_Contacts__c,(select id from Contacts) from Account where id in:setAccId ]);
   
    for(ID accId:mapToAccount.keySet())
    {
        Account acc=mapToAccount.get(accId);
  acc.No_Of_Contacts__c=acc.Contacts.size();
    }    
   
    update mapToAccount.values();
}

catch(DMLException excp)
{
        errObj.Exception_Message__c=excp.getMessage();
        errObj.Line_Number__c=excp.getLineNumber();
        //errObj.Name=excp.getTypeName();
        insert errObj;
    }
}