• Andrew Gross
  • NEWBIE
  • 30 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Hi Everyone.  I'm embarking on writing my first trigger/unit test and my test class is failing - not sure why.  If you can please provide some insight it would  be greatly appreciated.  Remember - take it easy on me I'm new to code writing =)

 

Scenario:  When a task is created with certain criteria (via user interface or in masse via data loader or whatever) - create a corresponding Opportunity with certain criteria.  That's basically it.

 

I'd like to know how I can dig deeper into what is wrong - does the debug log pick this stuff up?  I'm pretty sure the "test that the trigger worked" part of the test is screwy.  I've tried to take this as far as I can by looking up help files and looking at other posts on these boards. Thanks in advance.

 

Here's the trigger:

 

trigger insertNewDonation on Task (after insert, after update) {

List<Opportunity> listOppor = new List<Opportunity>();

for(Task t : Trigger.new)
{
if(t.Phonathon_Call_Result__c == 'Pledge' || t.Phonathon_Call_Result__c == 'Undecided')
  { 
  Opportunity o = new Opportunity();
  
  o.Amount = t.Pledge__c;
  o.CloseDate = t.ActivityDate;
  o.Name = 'Overwrite';
  o.Donation_Category__c = 'Phonathon';
  o.Contact_Email__c = t.WhoId;
  o.npe01__Contact_Id_for_Role__c = t.WhoId;
  o.AccountId = t.AccountId;
  
  if(t.Phonathon_Call_Result__c == 'Pledge'){
  o.StageName = 'Pledged';}
  else{
  o.StageName = 'Prospecting';
  }
  
listOppor.add(o);
  }
}

if(listOppor.size() > 0)
     try {
        insert listOppor; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }  

 Here's the test Apex Class

 

@isTest 
private class TestTaskDonationInsert {
    static testMethod void testDonationInsert() {
       
       // Prep Data
       List<Task> tasks = new List<Task>();
       for(Integer i = 0;  i < 100; i++){
           
           Task t = new Task(Subject= 'Phonathon Call' +i,Phonathon_Call_Result__c = 'Pledge', ActivityDate = date.today(), Pledge__c=100.0);
           tasks.add(t);
           
        Test.startTest();
        
       // DML Operation
        insert tasks;
        
        Test.stopTest();
           

       // Verify Data
       List<Opportunity> insertedOpps = [SELECT Amount, StageName, Donation_Category__c
                                   FROM Opportunity
                                   WHERE StageName = 'Pledged'];
    
     
       // Test that the trigger worked
       System.assertEquals('Pledged', insertedOpps[0].StageName);
    }
}
}

 

Hi Everyone,

 

According to the Live Agent dev guide, you can pass information through deployment code:

http://www.salesforce.com/developer/docs/live_agent_dev/index.htm

 

My question is, do you need this code to be hosted on a sfdc site?  What if my chat button is exposed on an external website?  Here is the code that they provide, but as you can see it is enclosed in an </apex:page> tag.

 

   <!-- Deployment code --> 
<script type='text/javascript'
src='https://c.la-blitz01.soma.salesforce.com/content/g/deployment.js'></script>

<script type='text/javascript'>
   // An auto query that searches contacts whose email field matches “john@acme.com”     
   liveagent.addCustomDetail(‘Contact E-mail’, ‘john@acme.com’).map(‘Contact’, ‘Email’, false, true);
   // A fast-fill to populate a contact’s name with “John Doe”
   liveagent.addCustomDetail(‘Contact Name’, ‘John Doe’).map(‘Contact’, ‘Name’, true, false); 
   // Saves the custom detail to a custom field on LiveChatTranscript at the end of a chat     
   liveagent.addCustomDetail(‘Company’, ‘Acme’).saveToTranscript(‘Company__c’);     
   // Overrides the display name of the visitor in the agent console when enaged in a chat     
   liveagent.setName(‘John Doe’);      

   liveagent.init('https://d.la-blitz01.soma.salesforce.com/chat', '572D0000000002R', '00DD0000000JXbY'); 
</script>  
</apex:page>

 

Thanks for any insight in advance.

 

-Andrew

Hi Everyone.  I'm embarking on writing my first trigger/unit test and my test class is failing - not sure why.  If you can please provide some insight it would  be greatly appreciated.  Remember - take it easy on me I'm new to code writing =)

 

Scenario:  When a task is created with certain criteria (via user interface or in masse via data loader or whatever) - create a corresponding Opportunity with certain criteria.  That's basically it.

 

I'd like to know how I can dig deeper into what is wrong - does the debug log pick this stuff up?  I'm pretty sure the "test that the trigger worked" part of the test is screwy.  I've tried to take this as far as I can by looking up help files and looking at other posts on these boards. Thanks in advance.

 

Here's the trigger:

 

trigger insertNewDonation on Task (after insert, after update) {

List<Opportunity> listOppor = new List<Opportunity>();

for(Task t : Trigger.new)
{
if(t.Phonathon_Call_Result__c == 'Pledge' || t.Phonathon_Call_Result__c == 'Undecided')
  { 
  Opportunity o = new Opportunity();
  
  o.Amount = t.Pledge__c;
  o.CloseDate = t.ActivityDate;
  o.Name = 'Overwrite';
  o.Donation_Category__c = 'Phonathon';
  o.Contact_Email__c = t.WhoId;
  o.npe01__Contact_Id_for_Role__c = t.WhoId;
  o.AccountId = t.AccountId;
  
  if(t.Phonathon_Call_Result__c == 'Pledge'){
  o.StageName = 'Pledged';}
  else{
  o.StageName = 'Prospecting';
  }
  
listOppor.add(o);
  }
}

if(listOppor.size() > 0)
     try {
        insert listOppor; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }  

 Here's the test Apex Class

 

@isTest 
private class TestTaskDonationInsert {
    static testMethod void testDonationInsert() {
       
       // Prep Data
       List<Task> tasks = new List<Task>();
       for(Integer i = 0;  i < 100; i++){
           
           Task t = new Task(Subject= 'Phonathon Call' +i,Phonathon_Call_Result__c = 'Pledge', ActivityDate = date.today(), Pledge__c=100.0);
           tasks.add(t);
           
        Test.startTest();
        
       // DML Operation
        insert tasks;
        
        Test.stopTest();
           

       // Verify Data
       List<Opportunity> insertedOpps = [SELECT Amount, StageName, Donation_Category__c
                                   FROM Opportunity
                                   WHERE StageName = 'Pledged'];
    
     
       // Test that the trigger worked
       System.assertEquals('Pledged', insertedOpps[0].StageName);
    }
}
}

 

I can't open tab or subtab for Hyperlink in formula field.

formula can do this.

 

HYPERLINK(Id,'Mr. ' &  FirstName & ' ' &  LastName, '_parent') 

 

Thank you so much.

  • July 20, 2011
  • Like
  • 0