• Sarah Osburn 3
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 7
    Replies
I am trying to create a campaign member when my lead status and custom field lead sub status move to a certain PL value.  I am not getting errors but the trigger is not firing.  Can I get some help on understanding why this may not be working, please.  Thanks in advance!
 
trigger CreateCampaignMember on Lead (before update) {
    List<CampaignMember> members = new List<CampaignMember>();

for (Lead CovL : Trigger.new) {
    if (CovL.Status == 'Unqualified' && CovL.Lead_Sub_Status__c == 'No Contact, Workflow Complete') {
        CampaignMember cm = new CampaignMember(CampaignId = '7010x0000000e3j', 
                              LeadId = LeadId.Name, Status = 'Sent');
        System.debug(Lead.Id);
        members.add(cm);
    }

    try{
        insert members;
    } catch(DmlException e) {
        System.debug('An unexpected error has occured: ' + e.getMessage());
    }
}
}

 
Hi All,

I am getting the above error on my trigger (wrote a class and then added the class to my trigger) and I can't figure out how to resolve.  All help is so greatly appreciated!

Error: Compile Error: Method does not exist or incorrect signature: ContactExtIdUpdates.updatecalled.remove(Id) at line 6 column 72

Class:
public with sharing class ContactExtIdUpdates {
    public static set<ID> updatedcalled = new set<id>();
}
Here is the trigger and location of the error:
trigger ContactID on Contact (before insert, before update, after update, after delete)
{
    // creates a "lock" by adding the object Id into the "updatecalled" set of IDs.
    for (Contact Cc : Trigger.New) {
            if (Trigger.isAfter) {
                if (!ContactExtIdUpdates.updatecalled.Contains(Cc.Id)) ContactExtIdUpdates.updatecalled.remove(Cc.Id); //Removes lock once updated <------THIS LINE IS CAUSING ERROR
        } else if (!ContactExtIdUpdates.updatecalled.Contains(Cc.Id)) {//Checks lock, executing code only if no lock
        ContactExtIdUpdates.updatecalled.Add(Cc.Id); //Adds lock
        //


 
I have a trigger that updates the contact owner to whoever the account owner is when the account owner is changed.  I also need the trigger to allow for account teams and dataloading the account owner changes.  Trigger works on a 1 for 1 basis but still has 0% coverage and test class fails.  Any help is really greatly appreciated.

Trigger:
trigger reassignContactOwnerToAccountOwner on Contact ( after insert ) {

    List<Id> accountIds = new List<Id>();
    Map<Id, Id> accountOwnerIdMap = new Map<Id, Id>();

    // all the accounts whose owner ids to look up
    for ( Contact c : Trigger.new ) {
        accountIds.add( c.accountId );
    }
    
    // look up each account owner id
    for ( Account acct : [ SELECT id, ownerId FROM account WHERE id IN :accountIds ] ) {
        accountOwnerIdMap.put( acct.id, acct.ownerId );
    }
    
    // change contact owner to its account owner
    for ( Contact c : Trigger.new ) {
        c.ownerId = accountOwnerIdMap.get( c.accountId );
    }
   
}

Test Class:
@IsTest
private class AccountContactOwner {
    static TestMethod void testTrigger()
    { 
        test.StartTest();
        
        //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(Account=a, FirstName='John',LastName='Doe');
        update c;
        
        
        test.startTest();
        
        
        //Perform the dml action on which trigger gets fired , like insert, update ,delete , undelete, in your case you have to update account record that you created in above  
        //create test user
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
      User u1 = new User(Alias = 'standa', Email='saplingstandarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='saplingstandarduser@testorg.com');


      System.runAs(u1) {
      // The following code runs as user 'u'  
       // create test contact
        Contact c1 = new Contact(FirstName='Jane',LastName='Doe', Account=a);
        insert c1;
        
        //assert your results using system.assert and system.asserEquals

//reload objects to make sure values are loaded
   a= [select id, ownerId from Account where id=:a.id];
                
        
        
        test.stopTest();
    }
}
}
I am trying to create a campaign member when my lead status and custom field lead sub status move to a certain PL value.  I am not getting errors but the trigger is not firing.  Can I get some help on understanding why this may not be working, please.  Thanks in advance!
 
trigger CreateCampaignMember on Lead (before update) {
    List<CampaignMember> members = new List<CampaignMember>();

for (Lead CovL : Trigger.new) {
    if (CovL.Status == 'Unqualified' && CovL.Lead_Sub_Status__c == 'No Contact, Workflow Complete') {
        CampaignMember cm = new CampaignMember(CampaignId = '7010x0000000e3j', 
                              LeadId = LeadId.Name, Status = 'Sent');
        System.debug(Lead.Id);
        members.add(cm);
    }

    try{
        insert members;
    } catch(DmlException e) {
        System.debug('An unexpected error has occured: ' + e.getMessage());
    }
}
}

 
Hi All,

I am getting the above error on my trigger (wrote a class and then added the class to my trigger) and I can't figure out how to resolve.  All help is so greatly appreciated!

Error: Compile Error: Method does not exist or incorrect signature: ContactExtIdUpdates.updatecalled.remove(Id) at line 6 column 72

Class:
public with sharing class ContactExtIdUpdates {
    public static set<ID> updatedcalled = new set<id>();
}
Here is the trigger and location of the error:
trigger ContactID on Contact (before insert, before update, after update, after delete)
{
    // creates a "lock" by adding the object Id into the "updatecalled" set of IDs.
    for (Contact Cc : Trigger.New) {
            if (Trigger.isAfter) {
                if (!ContactExtIdUpdates.updatecalled.Contains(Cc.Id)) ContactExtIdUpdates.updatecalled.remove(Cc.Id); //Removes lock once updated <------THIS LINE IS CAUSING ERROR
        } else if (!ContactExtIdUpdates.updatecalled.Contains(Cc.Id)) {//Checks lock, executing code only if no lock
        ContactExtIdUpdates.updatecalled.Add(Cc.Id); //Adds lock
        //


 
I have a trigger that updates the contact owner to whoever the account owner is when the account owner is changed.  I also need the trigger to allow for account teams and dataloading the account owner changes.  Trigger works on a 1 for 1 basis but still has 0% coverage and test class fails.  Any help is really greatly appreciated.

Trigger:
trigger reassignContactOwnerToAccountOwner on Contact ( after insert ) {

    List<Id> accountIds = new List<Id>();
    Map<Id, Id> accountOwnerIdMap = new Map<Id, Id>();

    // all the accounts whose owner ids to look up
    for ( Contact c : Trigger.new ) {
        accountIds.add( c.accountId );
    }
    
    // look up each account owner id
    for ( Account acct : [ SELECT id, ownerId FROM account WHERE id IN :accountIds ] ) {
        accountOwnerIdMap.put( acct.id, acct.ownerId );
    }
    
    // change contact owner to its account owner
    for ( Contact c : Trigger.new ) {
        c.ownerId = accountOwnerIdMap.get( c.accountId );
    }
   
}

Test Class:
@IsTest
private class AccountContactOwner {
    static TestMethod void testTrigger()
    { 
        test.StartTest();
        
        //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(Account=a, FirstName='John',LastName='Doe');
        update c;
        
        
        test.startTest();
        
        
        //Perform the dml action on which trigger gets fired , like insert, update ,delete , undelete, in your case you have to update account record that you created in above  
        //create test user
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
      User u1 = new User(Alias = 'standa', Email='saplingstandarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='saplingstandarduser@testorg.com');


      System.runAs(u1) {
      // The following code runs as user 'u'  
       // create test contact
        Contact c1 = new Contact(FirstName='Jane',LastName='Doe', Account=a);
        insert c1;
        
        //assert your results using system.assert and system.asserEquals

//reload objects to make sure values are loaded
   a= [select id, ownerId from Account where id=:a.id];
                
        
        
        test.stopTest();
    }
}
}

When someone takes the time/effort to repspond to your question, you should take the time/effort to either mark the question as "Solved", or post a Follow-Up with addtional information.  

 

That way people with a similar question can find the Solution without having to re-post the same question again and again. And the people who reply to your post know that the issue has been resolved and they can stop working on it.