feed-icon-32x32.png

Subscribe in Feed Reader
Subscribe by Email

Learn how Salesforce.com can help your business
arrowpointe @ twitter
  • anyone use Salesforce's knowledge base? (the old school one) Notice scrollbars appearing in the content recently? 4 days ago
  • yes, i can use aggregate functions in dynamic soql. asked too soon, sorry 4 days ago
  • can i use aggregate functions in the Database.query() method? 4 days ago
  • what's the timing for new IDE? will it run just as well on eclipse 3.4 as 3.5? major benefits of 3.5 (i only use eclipse for salesforce)? 5 days ago
  • anyone use campaignmonitor with salesforce? no integration, but seems like a slick tool. curious about your process re: subscriber sync 5 days ago
  • is there a apex method or query that can tell me whether a subscriber org has a Trial vs. Active license of my package they installed? 6 days ago
  • feels like the new salesforce ui uses JavaScript libraries and rendering more friendly to fitefox's memory issues. Real or my imagination? 1 week ago
  • More updates...

Powered by Twitter Tools

Archive for February, 2009

Set Defaults for Opportunity Contact Roles (when converting)

It’s always bugged me that the Primary flag and a Role are not set on Opportunity Contact Roles when converting a Lead.  After every convert, I manually set these.  Typically, I set the Role to “Decision Maker”and the Primary Flag to True.  I got sick of doing this manually, so I wrote a trigger for it and I am sharing it with you all.

Trigger

trigger Opportunities on Opportunity (after insert) {

	Opportunities o = new Opportunities();
	o.SetContactRoleDefaults(Trigger.new);

}

Class

public class Opportunities {

    // Default Constructor
    public Opportunities()
    {
    }

    // Sets default values on the Contact Role record created during Conversion. Called on AFTER INSERT
    public void SetContactRoleDefaults(Opportunity[] opptys)
    {
    	/***************
        * Variables
        ***************/
		set<ID> set_opptyIDs = new set<ID>();

		/***************
        * Initial Loop
        ***************/
        // Get a set of the Opportunity IDs being affected.
		for(Opportunity o:opptys) {
			set_opptyIDs.add(o.id);
		}

		/***************
        * Process Records
        ***************/
        // Update the Contact Role record to be Primary and the Decision Maker
        list<OpportunityContactRole> list_opptyContactRolesToUpdate = new list<OpportunityContactRole>();
		for(OpportunityContactRole ocr:[select Id,IsPrimary,Role from OpportunityContactRole where OpportunityId in :set_opptyIDs]) {
			ocr.IsPrimary = true;
			ocr.Role = 'Decision Maker';
			list_opptyContactRolesToUpdate.add(ocr);
		}

		if (list_opptyContactRolesToUpdate.size() > 0) {
			update list_opptyContactRolesToUpdate;
		}

    }
}

Test Class

@isTest
private class Opportunities_Test {

    static testMethod void SetContactRoleDefaults_Test() {

        // Create a Lead
        Lead l = new Lead();
        l.lastname = 'Lastname';
        l.firstname = 'FirstName';
        l.company = 'Company';
        insert l;

        // Convert the Lead
        Database.LeadConvert lc = new database.LeadConvert();
		lc.setLeadId(l.id);

		LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
		lc.setConvertedStatus(convertStatus.MasterLabel);

		Database.LeadConvertResult lcr = Database.convertLead(lc);
		System.assert(lcr.isSuccess());

		// Query Contact Role Records and Asserts all was set correctly.
		for (OpportunityContactRole ocr:[select Id,IsPrimary,Role from OpportunityContactRole where OpportunityId = :lcr.getOpportunityId()]) {
			system.AssertEquals('Decision Maker', ocr.Role);
			system.AssertEquals(true, ocr.IsPrimary);
		} 

    }

}

Comments (11) comments feed

Auto vCard Named Best Productivity App of 2008

best-of-2008
Salesforce has announced the Best Apps of 2008 and I am pleased to report that Auto vCard was named Best Productivity Application!  The “Best App” honor is given to the application in each AppExchange category receiving the most 4 and 5 star reviews.

In case you didn’t hear, Auto vCard 2.0 was released.  This is a major improvement to the app, allowing for total flexibilty and configurability in the creation of vCards from Salesforce data.  In fact, you can now create vCards from any object, pass any field through, use International characters and it all runs on the force.com platform!

To learn more…

Comments (1) comments feed