• Yelena Glezer
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Trigger_Test__c is successfully updating, however the  Account Owner Alias String is not - any idea what is the reason?

================================
//Class Logic

public with sharing class LeadTriggerHandler {
    public LeadTriggerHandler() {
       
    }

    public void OnBeforeInsert(Lead[] Leads){

        String companyName;
        for (Lead newLead : Leads){
            companyName = newLead.Company;
            break;
        }

        for ( Account existingAccount : [select Id, Name from Account where Name =: companyName limit 1  ]){
            //Leads[0].Company.addError('[Warning] Account exists.');
Leads[0].Trigger_Test__c=companyName;
Leads[0].Existing_Account_Owner__c= existingAccount.Account_Owner_Alias_string__c;
PEOPLE, HELP!!!!

We are trying to find a way to flag a new lead from an existing Company.

Example:
1. John Smith submites a web -to-lead form (John works at company 'ABC")
2. The code checks the salesforce database for an existing company "ABC"

Ideal Result: We would like that lead to be assigned to the existing account owner and if possible we would like to have two custom fields on the lead object that will be populated with the name of the Account and the existing account owner

We tried to use the code provided by another salesforce community member, but ran into the issue below.

Any help is greatly appreciated. 

 
Issue:
*** Deployment Log ***
Result: FAILED
Date: July 14, 2014 3:34:27 PM PDT

# Deployed From:
   Project name: Lead Trigger
   Username: yelena@visual.ly.sandbox
   Endpoint: test.salesforce.com

# Deployed To:
   Username: yelena@visual.ly
   Endpoint: www.salesforce.com

# Deploy Results:
   File Name:    triggers/LeadTrigger.trigger
   Full Name:  LeadTrigger
   Action:  NO ACTION
   Result:  FAILED
   Problem: Invalid type: LeadTriggerHandler

   File Name:    package.xml
   Full Name:  package.xml
   Action:  UPDATED
   Result:  SUCCESS
   Problem: n/a

# Test Results:
   n/a

This is what we did:

1. Created an APEX Class
LeadTriggerHandlerTests
//Test Class
@isTest (SeeAllData = true)

private class LeadTriggerHandlerTests {

    public static void init(){

        Account testAccount = new Account(
            Name = 'Test Company'
            );

        insert testAccount;

        System.debug('DEBUG'+testAccount);

    }
   
     static testMethod void test_method_one() {
       
        init();

        Lead testLead = new Lead(
            FirstName = 'Test', LastName = 'Test', Company = 'Test Company'
            );
       
        try{
            Test.startTest();
            insert testLead;
            System.debug('DEBUG'+testLead);
                Test.stopTest();   
        }
       
        catch (Exception e){
           
            Boolean expectedExceptionThrown =  e.getMessage().contains('[Warning] Account exists.') ? true : false;
            system.assertEquals(expectedExceptionThrown,true);
           
        }
       

    }
   
}

2. Created an APEX Class
LeadTriggerHandler
//Class Logic


public with sharing class LeadTriggerHandler {
    public LeadTriggerHandler() {
       
    }

    public void OnBeforeInsert(Lead[] Leads){

        String companyName;
        for (Lead newLead : Leads){
            companyName = newLead.Company;
            break;
        }

        for ( Account existingAccount : [select Id, Name from Account where Name =: companyName limit 1  ]){
            Leads[0].Company.addError('[Warning] Account exists.');

        }
    }
}


3. Created an APEX Trigger

LeadTrigger


//Final part, the trigger which calls it


trigger LeadTrigger on Lead (before insert) {

    LeadTriggerHandler handler = new LeadTriggerHandler();

  if(Trigger.isInsert && Trigger.isBefore){

    handler.OnBeforeInsert(Trigger.new);
  }

}
Trigger_Test__c is successfully updating, however the  Account Owner Alias String is not - any idea what is the reason?

================================
//Class Logic

public with sharing class LeadTriggerHandler {
    public LeadTriggerHandler() {
       
    }

    public void OnBeforeInsert(Lead[] Leads){

        String companyName;
        for (Lead newLead : Leads){
            companyName = newLead.Company;
            break;
        }

        for ( Account existingAccount : [select Id, Name from Account where Name =: companyName limit 1  ]){
            //Leads[0].Company.addError('[Warning] Account exists.');
Leads[0].Trigger_Test__c=companyName;
Leads[0].Existing_Account_Owner__c= existingAccount.Account_Owner_Alias_string__c;
PEOPLE, HELP!!!!

We are trying to find a way to flag a new lead from an existing Company.

Example:
1. John Smith submites a web -to-lead form (John works at company 'ABC")
2. The code checks the salesforce database for an existing company "ABC"

Ideal Result: We would like that lead to be assigned to the existing account owner and if possible we would like to have two custom fields on the lead object that will be populated with the name of the Account and the existing account owner

We tried to use the code provided by another salesforce community member, but ran into the issue below.

Any help is greatly appreciated. 

 
Issue:
*** Deployment Log ***
Result: FAILED
Date: July 14, 2014 3:34:27 PM PDT

# Deployed From:
   Project name: Lead Trigger
   Username: yelena@visual.ly.sandbox
   Endpoint: test.salesforce.com

# Deployed To:
   Username: yelena@visual.ly
   Endpoint: www.salesforce.com

# Deploy Results:
   File Name:    triggers/LeadTrigger.trigger
   Full Name:  LeadTrigger
   Action:  NO ACTION
   Result:  FAILED
   Problem: Invalid type: LeadTriggerHandler

   File Name:    package.xml
   Full Name:  package.xml
   Action:  UPDATED
   Result:  SUCCESS
   Problem: n/a

# Test Results:
   n/a

This is what we did:

1. Created an APEX Class
LeadTriggerHandlerTests
//Test Class
@isTest (SeeAllData = true)

private class LeadTriggerHandlerTests {

    public static void init(){

        Account testAccount = new Account(
            Name = 'Test Company'
            );

        insert testAccount;

        System.debug('DEBUG'+testAccount);

    }
   
     static testMethod void test_method_one() {
       
        init();

        Lead testLead = new Lead(
            FirstName = 'Test', LastName = 'Test', Company = 'Test Company'
            );
       
        try{
            Test.startTest();
            insert testLead;
            System.debug('DEBUG'+testLead);
                Test.stopTest();   
        }
       
        catch (Exception e){
           
            Boolean expectedExceptionThrown =  e.getMessage().contains('[Warning] Account exists.') ? true : false;
            system.assertEquals(expectedExceptionThrown,true);
           
        }
       

    }
   
}

2. Created an APEX Class
LeadTriggerHandler
//Class Logic


public with sharing class LeadTriggerHandler {
    public LeadTriggerHandler() {
       
    }

    public void OnBeforeInsert(Lead[] Leads){

        String companyName;
        for (Lead newLead : Leads){
            companyName = newLead.Company;
            break;
        }

        for ( Account existingAccount : [select Id, Name from Account where Name =: companyName limit 1  ]){
            Leads[0].Company.addError('[Warning] Account exists.');

        }
    }
}


3. Created an APEX Trigger

LeadTrigger


//Final part, the trigger which calls it


trigger LeadTrigger on Lead (before insert) {

    LeadTriggerHandler handler = new LeadTriggerHandler();

  if(Trigger.isInsert && Trigger.isBefore){

    handler.OnBeforeInsert(Trigger.new);
  }

}