Pages

Wednesday, February 27, 2013

Mass Updating records with Visualforce pages

Mass updating records:
Well the first thing that strikes everyone is to use "Data-Loader". Now if there is a need that we have to give this functionality to the end user and they are not comfortable to use Data-Loader. They wanted more out of the platform,like the ability to search for the desired records and update them at once.
Business use case can be any thing like below :


  • Updating the cases with a particular status or
  • Updating the selected Accounts fields or 
  • Updating the lead source created today by any particular user or
  • updating the records that might have same Name or any thing like this which involve manual searching and updating the selected records.
We can make this possible using Visualforce pages and its controllers with wrapper methods.
In order to show this more detail, I have created a custom Tab for the visualforce page and called it as Account MassUpdate as shown below:



On clicking the tab,It will be redirected to our visualforce page. Now you can see that there is a search button. Put any character or word to search for all 
the accounts starting with that value.


In this case i have just used a single character "g "  to search the Account object and it resulted in 2 records that start with  letter "g". if we can think that there can be hundreds or thousands of records resulting in search, we can add up another input field to refine our search. More over we can add pagination to it also.


We can observe one other thing after the search i have given the functionality of multiple selection or checkboxes and check All check box, this will help user a lot in real time.


Now once we have selected the records that needs to be updated and click on Update selected Accounts,
it will show up another section where you can actually update your records. In this case i have used only few fields to while updating. we can change it to meet any business need. 
Once the new values are entered click on Update Accounts button, This will do the stuff for You. I will update the Accounts the new values mentioned. we can cross check this by going back to the Account records. 
 Hope fully this will help people who are searching for the solution of Mass Updating  records.

***With the size limitation of the post am not able to provide code on this post. But if you need a sample code or any approach feel free to drop me an email.

Happy Coding.

Tuesday, February 26, 2013

Error on Fetching, Saving ,Refreshing and Creating force.com Project in Eclipse.


Hi Guys,
Recently I was trying to update some of my code on Eclipse.  It was throwing so wearied Error that i havent seen before.
  
Save error: Unable to perform save on all files: com.salesforce.ide.api.metadata.types.Metadata$JaxbAccessorF_fullName cannot be cast to com.sun.xml.internal.bind.v2.runtime.reflect.Accessor Antibiogram_Survey.page/Cubist Dev/src/pages line 1Force.com save problem

Then i thought may be i have older version of code on my eclipse and i was trying to refresh from the instance and the same error message showed up again. 

Then I thought may be my project got screwed up and was trying to create a new Force.com project, and the error was back.This was driving me crazy and went on doing google and found few solutions online.
  • Downgrading JRE to 1.6 instead of 1.7.
  • Working as an Admin.
  • using -clean
  • Switching between the workspaces.
Then with the above options i was trying to see which option will fix my problem. Firstly I was trying to downgrade my JRE but found it to be  little difficult and lengthy process.
Then i wanted some thing quick to solve my problem. I choose to use switching workspace. magically it started working. 
Follow the following steps to switch between workspaces.
  • Open your eclipse
  • File > Switch workspace >other
  • Now select the same workspace and click on  "ok"
  • This will restart your Eclipse and read to use.
Note : Make sure to copy all your code modifications before choosing this option. Since eclipse will restart after switching between workspaces and all the unsaved data will be lost.


I haven't got a chance to test and comment on the use of "-clean" way of fixing this issue. Eclipse say -clean will remove the loading and cache problems.

hope this helps.


Happy coding. 

Multiple Trigger's on an Object in Salesforce.com

Aim :-Combining Multiple triggers on an object to a Single trigger:

This post is about he error's that arise when you have More than 1  trigger on any Object.
Salesforce.com or force.com platform gives you a feasibility to write more than 1 trigger on any standard or custom object. which is a bad practice.
These Multiple triggers on an object which tend to Fire at specific DML operations or an events, may sometimes fire other triggers on the object and result in unnecessary data changes(Data corruption )  or recursive triggering or Show some wearied errors and break the business process.

 Salesforce.Com  says it's always a good practice to maintain  a single trigger on any object. To meet different business logic on the the same object we might want to have different triggers on the object.
This can be solved by using simple techniques as shown below.
  • Make your trigger to fire on a criteria.
  • Try and create methods or apex classes where you can put all logic.Your trigger should initiate and process logic in methods.
  • Make sure write code to meet governor limits.
Here is the sample how to write you trigger :

trigger TriggerName on ObjectName (after insert, before update,after update, before delete) 
{
    if(Trigger.isBefore)
    {  
        if (Trigger.isUpdate) 
        {
            CheckAndDeleteOldRecords();
        }    
        if(Trigger.isDelete) 
        {
            DeleteRelatedCases();
        }
    }      
    if(trigger.isAfter)
    {
        if(Trigger.isInsert) 
        {
            MigrateContacts();  
        }        
        if (Trigger.isInsert || Trigger.isUpdate) 
        {
            CheckAndCreateCasesAndTasks();
            if(Trigger.isUpdate)
            {
                UpdateYearSummaryWithStatus();
                UpdateStatus();
                ApprovalSubmitterForCase();
            }
        }     
    }  /// End of trigger 

/// These methods can be in the same trigger but should start after the trigger.

private void UpdateStatus()
    {
      for(Contact c :trigger.new)
      {
       // Do your code here.
       }  
    }
private void CheckAndDeleteOldRecords()
    {
      for(Contact c :trigger.new)
      {
       // Do your code here.
       }  
    }
private void ApprovalSubmitterForCase()
    {
      for(Contact c :trigger.new)
      {
       // Do your code here.
       }  
    }
private void UpdateYearSummaryWithStatus()
    {
      for(Contact c :trigger.new)
      {
       // Do your code here.
       }  
    }

So On...
This will reduce the risk and unwanted errors.Hoping this will help you.
Happy Coding.