• snyhan
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I'm pretty new to Apex and am trying to create a test class for a trigger that should update the status of the person account. When I ran the test, I got the following failure message:

 

System.AssertException: Assertion Failed: Expected: Needs Introduction Email, Actual: Active

 

I have no idea if I've written the trigger incorrectly or if the issue is in my test. I wrote a similar trigger that works perfectly to update the contact and then another to update the business account from the contact status. If you need to see those as well to help, let me know. It almost seems like the trigger is the issue since the status is not updating, but I'm not sure.

 

Here is the trigger:

trigger NeedsIntroductionEmailPrimary1PA on S_C__c (after update) {

List<id> paIds = new List<Id>();
for(S_C__c sc:trigger.new){
if(sc.E_o_T_Status__c == 'Needs Introduction Email' && sc.Primary_Contact1__c != null &&
sc.Primary_Contact_1_Is_Person_Account__c == 'Person Account'){
paIds.add(sc.Primary_Contact1__c);
system.debug('Name is' + sc.Primary_Contact1__c);
}
}

List<Account> paList = [SELECT Id, Status__pc FROM Account WHERE Id IN: paIds];
for(Account pa: paList){
system.debug('Found Person Account' + pa);
pa.Status__pc = 'Needs Introduction Email';
}

try{
update paList;
system.debug('Person Accounts to update list size' + paList.size());
}

catch(Dmlexception e){
system.debug('Person Account update failed' + e);
}
}

 

And here is the test:

@isTest
private class TestNeedsIntroductionEmailPrimary1PA {

static testMethod void testPAStatusChange() {

Account[] newpa = new Account[]{
//create two Person Accounts by filling in the Account's LastName field
new Account(FirstName='Bob', LastName='Smith', PersonMailingStreet='1 ABC Way',
PersonMailingCity='Boston', PersonMailingState='MA', PersonMailingPostalCode='02210',
PersonEmail='bsmith@me.com.sandbox', Phone='6029483917', Status__pc='Active'),
new Account(FirstName='Tracy', LastName='Jones', PersonMailingStreet='1 Polar Drive',
PersonMailingCity='Miami', PersonMailingState='FL', PersonMailingPostalCode='23984',
PersonEmail='tjones@me.com.sandbox', Phone='8243882346', Status__pc='Active')
};
insert newpa;

S_C__c[] sc = new S_C__c[]{
//create two new S Cs, add new PersonAccounts as Primary Contact 1
new S_C__c(Name='S 1', Status__c='PSO',
E_o_T_Status__c='None', Primary_Contact1__c=newpa[0].PersonContactId),
new S_C__c(Name='S 2', Status__c='PSO',
E_o_T_Status__c='None', Primary_Contact1__c=newpa[1].PersonContactId)
};
insert sc;

sc[0].E_o_T_Status__c = 'Needs Introduction Email';
Test.startTest();
update sc;
Test.stopTest();

newpa = [SELECT id, Status__pc FROM Account WHERE id IN: newpa];

{system.assertEquals('Needs Introduction Email', String.valueOf(newpa[0].Status__pc));
}
}
}

 

Thank you in advance for any help you might be able to provide,

 

Sam

  • February 03, 2012
  • Like
  • 0

Is it possible to override the Download button in Salesforce CRM Content? When our users click the download button on specific documents, I would like to re-direct them to either a Visualforce page or pop-up reminding them that the document is for internal purposes only. Once they click OK on the Visualforce page or pop-up, I would like the document to download. Any help would be greatly appreciated. I know things like this are possible in other objects, but I can't seem to find the Buttons and Links section that's available for most objects for Salesforce CRM Content.

  • January 18, 2012
  • Like
  • 0

I've created a trigger, but cannot figure out how to cover the dml exception in my test class. Please help! Trigger & test included below:

 

trigger LeadRespondedToCampaign on CampaignMember (after update) {
//update Lead Score by adding a value (10) to the Lead Responded to Campaign field
//if the Campaign Member Status is "Responded"

    List<id> leadIds=new List<Id>();
   
    for(CampaignMember cm:trigger.new){
        if(cm.LeadId !=null){
            System.debug('Status is ' + cm.Status);
            if(cm.Status=='Responded'){
                leadIds.add(cm.LeadId);
                System.debug('Id is ' + cm.LeadId);
            }
        }
    }
    List<Lead> leads=[SELECT Id, Lead_Responded_to_Campaign__c FROM Lead WHERE Id IN: leadIds];
   
    for(Lead l:leads){
        System.debug('Found lead ' + l);
        l.Lead_Responded_to_Campaign__c=10;
    }
    try{
    update leads;
    System.debug('Leads to update list size ' + leads.size());
    }catch (Dmlexception e){
        system.debug('lead update failed: '+e);
    }
}

 

 

 

@isTest
private class TestLeadRespondedToCampaign {

    static testMethod void testStatusChange() {
        Campaign newc = new Campaign(Name = 'Test Campaign', IsActive = True);
        insert newc;
       
        Lead[] newl = new Lead[]{
            new Lead(FirstName = 'Barbara', LastName = 'Jones', State = 'HI'),
            new Lead(FirstName = 'Tim', LastName = 'McElroy', State = 'NH')
        };
        insert newl;
               
        CampaignMember[] cm = new CampaignMember[]{
            new CampaignMember(CampaignId = newc.id, LeadId = newl[0].id, Status = 'Sent'),
            new CampaignMember(CampaignId = newc.id, LeadId = newl[1].id, Status = 'Sent')
        };
        insert cm;
       
        cm[0].Status = 'Responded';
           Test.StartTest();
        update cm;
           Test.StopTest();
         
          newl = [SELECT id, Lead_Responded_to_Campaign__c FROM Lead WHERE id IN :newl];
          {system.assertEquals(String.valueOf(newl[0].Lead_Responded_to_Campaign__c), '10');
          }
    }
}

 

Thank you!

  • August 18, 2011
  • Like
  • 0

I have created a trigger (posted below) to update a lead field with a number when the Campaign Member Status is changed to 'Responded', however I am having trouble writing the test code for it. The test class I created came back with a warning that 0% of my trigger was covered by the test class. If anyone can please help me write the test I would greatly appreciate your help!

 

Here is the trigger:

trigger LeadRespondedToCampaign on CampaignMember (after update) {
    List<id> leadIds=new List<Id>();
    for(CampaignMember cm:trigger.new){
        if(cm.LeadID!=null){
            if(cm.Status=='Responded'){
                leadIds.add(cm.LeadId);
            }
        }
    }
    List<Lead> leads=[SELECT Id, Lead_Responded_to_Campaign__c FROM Lead WHERE Id IN: leadIds];
    for(Lead l:leads){
        l.Lead_Responded_to_Campaign__c=10;
    }
}

  • August 08, 2011
  • Like
  • 0

I have been tasked with creating a lead management system that will update the lead status at certain Last Activity Date intervals. While the workflow rule I created did allow me to update the lead status upon Last Activity Date changes, I am unable to manually change the lead status. Also, is there any way to get the rule or trigger to fire without manually updating each lead in our database? We would like this to run in the background to create less work for our sales reps and marketing team.

 

Ultimately, I need a workflow rule or trigger that will do the following:

 

If Last Activity Date is within the last 120 days, the status should be Active unless the salesperson has manually changed the status. The Last Activity Date should not include mass emails.

If Last Activity Date took place between 120 and 180 days, the status should be Paused unless the salesperson has manually changed the status. The Last Activity Date should not include mass emails.

If Last Activity Date is over 180 days ago, the status should be lapsed unless the salesperson has manually changed the status. The Last Activity Date should not include mass emails.

 

I've included my workflow rules below. Unfortunately they worked like a sledgehammer and I was unable to manually update the lead status. Also, I could not figure out how to exclude mass emails from the last activity date.

 

Workflow Rule 1: ActiveLeadStatusUpdate

Evaluate when a record is created, or when a record is edited and did not previously meet the rule criteria.

Rule Criteria: AND((( TODAY() - LastActivityDate ) <= 120), OR( ISPICKVAL( Status , "Not right now"), ISPICKVAL(Status, "Not in market")))

Field Update: Field to Update = Lead Status, New Field Value = Active

 

Workflow Rule 2: Reminder/PausedLeadStatusUpdate

Evaluate when a record is created, or when a record is edited and did not previously meet the rule criteria.

Rule Criteria: AND(OR(( TODAY() - LastActivityDate ) > 120,(TODAY()-LastActivityDate) < 180),OR( ISPICKVAL( Status , "Not right now"), ISPICKVAL(Status, "Not in market")))

Field Update: Field to Update = Lead Status, New Field Value = Reminder/Paused

 

Workflow Rule 3: LapsedLeadStatusUpdate

Evaluate when a record is created, or when a record is edited and did not previously meet the rule criteria.

Rule Criteria: AND((( TODAY() - LastActivityDate ) => 180), OR( ISPICKVAL( Status , "Not right now"), ISPICKVAL(Status, "Not in market")))

Field Update: Field to Update = Lead Status, New Field Value = Lapsed

 

As you can probably tell, I'm pretty new to workflow rules, apex triggers, and developing as a whole. Any guidance will be greatly appreciated.

 

Thank you!

 

I'm extremely new in attempting to use AJAX and Javascript and am having quite a bit of trouble creating a button that will allow for the conversion of a business account to a person account. I found some code on the developer board got an error after copying and pasting the original script. Since then, I have continued to modify the code but am still getting error messages that vary depending on the browser I'm using.

 

If I'm using Firefox and click the new button, I get the following error message:

 

"A problem with the OnClick JavaScript for this button or link was encountered:

Account is not defined"

 

However, if I'm using Internet Explorer, I get a different error message:

 

"A problem with the OnClick JavaScript for this button or link was encountered:

 

Syntax error"

 

I'm not sure why I'm getting a different error message from the different browsers and I cannot figure out where I went wrong in the code. If someone could please help me out I'd really appreciate it as I've been working on this for the past 3 days and have gotten nowhere. The script I am trying to use can be found below:

 

<script src="/soap/ajax/22.0/connection.js" type="text/javascript"></script>
var ready = true;
if(ready && confirm("Are you sure you want to convert this Account and Contact to a single Person Account? This is NOT reversible.")) {
var account = new sforce.SObject('Account');
Account.Id = "{!Account.Id}";
Account.RecordTypeId = "012A00000004E7C";
result = sforce.connection.update([Account]);
alert(result);
location.reload(true);
}

I have created a trigger (posted below) to update a lead field with a number when the Campaign Member Status is changed to 'Responded', however I am having trouble writing the test code for it. The test class I created came back with a warning that 0% of my trigger was covered by the test class. If anyone can please help me write the test I would greatly appreciate your help!

 

Here is the trigger:

trigger LeadRespondedToCampaign on CampaignMember (after update) {
    List<id> leadIds=new List<Id>();
    for(CampaignMember cm:trigger.new){
        if(cm.LeadID!=null){
            if(cm.Status=='Responded'){
                leadIds.add(cm.LeadId);
            }
        }
    }
    List<Lead> leads=[SELECT Id, Lead_Responded_to_Campaign__c FROM Lead WHERE Id IN: leadIds];
    for(Lead l:leads){
        l.Lead_Responded_to_Campaign__c=10;
    }
}

  • August 08, 2011
  • Like
  • 0