• jmansford
  • 0 Points
  • Member since 2008

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 1
I want to implement some basic support functionality whereby when a support person sends an e-mail to the contact regarding a case the from address is automatically changed to a generic e-mail address but retains their display name e.g. "Support Smith <support@mycomp.com>"

I also want to manipulate the subject line to include some kind of tracking token (probably the caseID) which I will use to process inbound e-mails.

Does anyone have any pointers? I can't find any relevant triggers.

Thanks in advance!

Joel Mansford

***Let me start off by saying Enforce Validation and Triggers from Lead Convert setting is already set for our organization.


Moving forward...


I have a trigger that is supposed to set 3 custom lookup fields on an Opportunity when an opportunity is created. The value of these fields is based on the owner of the opportunity record.


The trigger functions properly in all use cases except when a lead is converted. For some reason the OwnerId of the Opportunity is the running user when the trigger executes instead of the Id set in the LeadConvert obj. This really perplexes me as I specifically set the OwnerId via the setOwnerId() method in my unitTest before calling the convertLead method.


Could anyone shed some light on to why the ownerId's are not being properly set?



trigger SetOpportunityOwnerManager on Opportunity (before insert, before update) 
//Create unique set of ownerId's
Set<ID> ownerIds = new Set<ID>();
for(Opportunity o : Trigger.new)
system.debug('OWNERID: ' + o.OwnerId);

//Business logic to run ONLY on Insert
//Create map of OwnerId's to their corresponding manager's
Map<ID, User> userMap = new Map<ID, User>([SELECT Id, Name, ManagerId, Processor__c, InterchangeDirector__c FROM User WHERE Id IN :ownerIds]);

//Set the manager field on the list of opportunities
for(Opportunity o : Trigger.new)
system.debug('***updating ' + o.Name);
o.OwnerManager__c = userMap.get(o.OwnerId).ManagerId;
o.Processor__c = userMap.get(o.OwnerId).Processor__c;
o.InterchangeDirector__c = userMap.get(o.OwnerId).InterchangeDirector__c;


Here is my unit test:


//create lead
Lead l = new Lead();
l.OwnerId = RAM.Id;
l.Status = 'Fresh';
l.Company = 'Test Co.';
l.FirstName = 'Jonny';
l.LastName = 'Quest';
l.Phone = '(480) 123-4567';
insert l;

//start testing

//verify lead owner information
Lead lTest = [SELECT Id, OwnerId FROM Lead WHERE Id=:l.Id];
system.assertEquals(RAM.Id, lTest.OwnerId); //PASSED

//convert lead
Database.Leadconvert lc = new database.Leadconvert();
lc.setConvertedStatus('QC Verified');

Database.Leadconvertresult lcr = database.convertLead(lc);

//verify lead successfully converted
system.assert(lcr.isSuccess()); //PASSED

//verify manager, icd, & processor fields were populated on the created opportunity
Opportunity o = [SELECT Id, OwnerId, OwnerManager__c, InterchangeDirector__c, Processor__c FROM Opportunity WHERE Id=:lcr.getOpportunityId()];
system.assertEquals(RAM.Id, o.OwnerId); //PASSED
system.assertEquals(ISM.Id, o.OwnerManager__c); //FAILED
system.assertEquals(icd.Id, o.InterchangeDirector__c);
system.assertEquals(Processor.Id, o.Processor__c);

//end testing



Thanks in advance!