• Paul Zamsky
  • NEWBIE
  • 10 Points
  • Member since 2014

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

Hi.

I"m pretty new to apex and coding in general but have done a few triggers on our platform so far. Once that I need to get done is one that can update the account manager from "Account" to "Contacts" through the "Account Contact Role" object. Because we have severl company for several users we only use the account contact role and not the lookup in contact. The code I got so far is below. I've been stuck for a couple of days and was wondering if anybody had any suggestions or could help.
 

Thanks

 

trigger RMUpdateContactRole on Account (after update) {
    
    String relationshipmanager;
    String CompanyID;
    
    for(Account act : trigger.new)
    {
        {relationshipmanager = act.relationship_manager__c;
         CompanyID = act.id;}

    }  
  
     List<AccountContactRole> AcrList =[SELECT contactid, accountid FROM AccountContactRole WHERE accountid =: companyid];
    
     List<Contact> contactlist = [SELECT id, relationship_manager__c FROM Contact WHERE id IN: AcrList.contactid];
    	for(Contact cnt:contactlist)
        {
            cnt.relationship_manager__c = relationshipmanager;
        }
    
    	update contactlist;
    
}
Hi Guys,

I need help increasing my Test Code Coverage for an apex trigger I have. I'm new to Apex and I'm learning on the spot.  I'm at 69% with this but need to get it over 75%. The higher the better.

Thanks

Paul


Trigger

trigger Lead_To_Candidate_2 on Lead (after insert, after update)
{
    set<string> phoneNumbers = new set<string>();
    String disposition;
    String email;
    String firstname;
    String lastname;
      
    for(Lead obj: Trigger.new)
    {
        if (obj.disposition__c != NULL  )
        {
            phoneNumbers.add(obj.Phone);
            disposition = obj.disposition__c;
            firstname = obj.firstName;
            lastname = obj.lastName;
            email = obj.email;
         
                }
    }
 
    List<Candidate_Non_Member__c> candidate = [SELECT Id, Formated_Phone_Number__c, Called__c, Latest_Dispostion__c, Contact_Email__c, Contact_First_Name__c, Contact_Last_Name__c FROM Candidate_Non_Member__c WHERE Formated_Phone_Number__c IN :phoneNumbers];
    List<Candidate_Non_Member__c> candidateUpdateList = new List<Candidate_Non_Member__c>();
 
    for(Candidate_Non_Member__c c: candidate)
    {
        c.Called__c = 1; //this is if called__c is a number field. If it is a text field, the line should be c.Called__c = '1';
        c.Latest_Dispostion__c = disposition;
        c.Contact_Email__c = email;
        c.Contact_First_Name__c = firstname;
        c.Contact_Last_Name__c = lastname;
      
        candidateUpdateList.add(c);
    }
    if(candidateUpdateList.size() > 0)
    {
        update candidateUpdateList;
    }
}




Test Class:

@isTest

/*
* Tests
*/


/*
* This is the basic test
*/

public with sharing class TestLead_To_Candidate_2 {


     public static final String DISPOSITION = 'Registered';
     public static final String COMPANY = 'Test Company';
     public static final String EMAIL = 'tuser15@salesforce.com';
     public static final String FIRSTNAME = 'John';
     public static final String LASTNAME = 'Doe';
     public static final String PHONE = '+12125555403';

    static testMethod void basicTest() {

        // Create dummy lead
        Lead testLead = new Lead(Company='Test Company',FirstName='John',LastName='Doe', Email='tuser15@salesforce.com', disposition__c = 'Registered', Phone = '+12125555403');
        insert testLead;
  
            
        List<Candidate_Non_Member__c> Candidate = [select id, Latest_Dispostion__c, Contact_Email__c, Called__c, Formated_Phone_Number__c, Contact_First_Name__c FROM Candidate_Non_Member__c where Formated_Phone_Number__c=:testLead.Phone];
   
        for (Candidate_Non_Member__c c : Candidate){
        //   System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT);
      
            System.assertEquals(testLead.Email, c.Contact_Email__c);
            System.assertEquals(testLead.FirstName, c.Contact_First_Name__c);
            System.assertEquals(c.Called__c, 1);
      
          
          
         
                         
        }
      
      

      

    }


}

Hi Everybody,

I'm pretty new to Apex and have been trying to do a cross object field update. I have two objects Lead and Candidate_Non_Member_c and I want to have the field Candidate_Non_Member__c.Called_C equal to 1 when the Lead.Disposition = ' Registered'.  Also the only way to find the corresponding candidate to the lead is by phone number. Lead.Phone and Candidate_Non_Member__c.Formated_Phone_Number__c. 

This is what I have so far but I've been getting "Error: Compile Error: Expression cannot be assigned at line -1 column -1"

Any help would be great. 
 

Thanks!

trigger Lead_To_Candidate_2 on Lead (after insert, after update)
{
    String objemail;
    String objfirstname;
    String objphone;
   
    for(Lead obj: Trigger.new)
    {
        if (Lead.disposition__c = 'Registered')
        {
            objemail = obj.Email;
            objfirstname = obj.Name;
            objphone = obj.Phone;
        }
    }
   
    List<Candidate_Non_Member__c> candidate = new List<Candidate_Non_Member__c>([SELECT Id, Formated_Phone_Number__c, Called__c FROM Candidate_Non_Member__c WHERE Formated_Phone_Number__c = :objphone]);
    List<Candidate_Non_Member__c> candidateUpdateList = new List<Candidate_Non_Member__c>();
   
    for(Candidate_Non_Member__c c: candidate)
    {
        Candidate_Non_Member__c.Called__c = 1;
    }
        if(candidateUpdateList.size() > 0)
    {
        update candidateUpdateList;
    }
    }

Hi Everybody,

I'm pretty new to Apex and have been trying to do a cross object field update. I have two objects Lead and Candidate_Non_Member_c and I want to have the field Candidate_Non_Member__c.Called_C equal to 1 when the Lead.Disposition = ' Registered'.  Also the only way to find the corresponding candidate to the lead is by phone number. Lead.Phone and Candidate_Non_Member__c.Formated_Phone_Number__c. 

This is what I have so far but I've been getting "Error: Compile Error: Expression cannot be assigned at line -1 column -1"

Any help would be great. 
 

Thanks!

trigger Lead_To_Candidate_2 on Lead (after insert, after update)
{
    String objemail;
    String objfirstname;
    String objphone;
   
    for(Lead obj: Trigger.new)
    {
        if (Lead.disposition__c = 'Registered')
        {
            objemail = obj.Email;
            objfirstname = obj.Name;
            objphone = obj.Phone;
        }
    }
   
    List<Candidate_Non_Member__c> candidate = new List<Candidate_Non_Member__c>([SELECT Id, Formated_Phone_Number__c, Called__c FROM Candidate_Non_Member__c WHERE Formated_Phone_Number__c = :objphone]);
    List<Candidate_Non_Member__c> candidateUpdateList = new List<Candidate_Non_Member__c>();
   
    for(Candidate_Non_Member__c c: candidate)
    {
        Candidate_Non_Member__c.Called__c = 1;
    }
        if(candidateUpdateList.size() > 0)
    {
        update candidateUpdateList;
    }
    }