Pages

Friday, March 1, 2013

Adding Custom Campaign Member Status

Hello Friends,
Today am gonna show you how to add custom status values for a campaign member while adding campaign members to the campaign in salesforce.com.

Requirement:-  Business needs to have additional values to choose while adding campaign members to a particular campaign recordtype. Salesforce provides only two values to choose from while adding campaign members to a campaign. Now a specific set of business users need to have additional values to choose while adding up campaignmembers.


Solution:
We cannot add or remove the values to this dropdown through customization's. In order to achieve this business need, I have written a trigger on the campaign object to remove the old values and Add new values to the dropdown. 



trigger Campaign_AI on Campaign (after insert,after update) {


List<CampaignMemberStatus> cms2Delete = new List<CampaignMemberStatus>();
    List<CampaignMemberStatus> cms2Insert = new List<CampaignMemberStatus>(); 


RecordType rt = [Select Id, Name from RecordType where Name = 'Meeting' limit 1];
    //change default member statuses (Sent and Responded) for                        //select campaigns
    Set <Id> cmpns = new Set <Id>();    
    for (Campaign c: trigger.new){ 
        if (c.RecordTypeId == rt.Id)
            cmpns.add(c.Id);
    }

    for (CampaignMemberStatus cm: [Select Id, Label, CampaignID  FROM CampaignMemberStatus WHERE CampaignID IN :cmpns]){
      if(cm.Label == 'Responded' ){
            cms2Delete.add(cm);
      }  else if(cm.Label == 'Sent'){           
    //          cms2Delete.add(cm);
            cm.SortOrder = 5; 
            cms2Insert.add(cm);
            CampaignMemberStatus cms1 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Active', HasResponded=false, IsDefault = True, SortOrder=3);          
            System.debug(cms1);         
            cms2Insert.add(cms1);
            CampaignMemberStatus cms6 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Send Email', HasResponded=false, SortOrder=4);
            System.debug(cms6);
            cms2Insert.add(cms6);
            CampaignMemberStatus cms3 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Accepted', HasResponded=true, SortOrder=6);
            System.debug(cms3);
            cms2Insert.add(cms3);   
            CampaignMemberStatus cms4 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Declined', HasResponded=true, SortOrder=7);
            System.debug(cms4);
            cms2Insert.add(cms4);   
            CampaignMemberStatus cms8 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Tentative', HasResponded=true, SortOrder=8);
            System.debug(cms8);
            cms2Insert.add(cms8);   
            CampaignMemberStatus cms5 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Attended', HasResponded=true, SortOrder=9);
            System.debug(cms5);
            cms2Insert.add(cms5);
            CampaignMemberStatus cms7 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Cancelled', HasResponded=true, SortOrder=10);
            System.debug(cms7);
            cms2Insert.add(cms7);
            CampaignMemberStatus cms9 = new CampaignMemberStatus(CampaignId=cm.CampaignID, Label='Invited', HasResponded=true, SortOrder=11);
            System.debug(cms9);
            cms2Insert.add(cms9);                                             
      }

    } 
    //perform insert before delete because system requires at //least one CMS for a Campaign
    upsert cms2Insert;
    delete cms2Delete; 
}



use sort order to arrange the dropwown values.

once this trigger is saved we can go back and crosscheck the to see the Add with Status values that are available while adding campaign members to a campaign.

** make sure you go the campaign that is of the record type that we mentioned in the trigger.(In this case "Meeting")



This is how i met the business needs.
hopefully this will help you.


happy coding.

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.