You need to sign in to do that
Don't have an account?
Yelena Glezer
Invalid type: LeadTriggerHandler
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);
}
}
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);
}
}
Thank you for your reply.
Sorry I couldn't zoom the image and recognize the details...
But have you already deployed LeadTriggerHandler and its test class?
It seems you selected only trigger to deploy and not other 2 files.
All Answers
My name is Shingo Yamazaki.
Would you give me some more info?
1. Do you know on which line the error occurs? (Invalid Type: LeadTriggerHandler)
2. How do you deploy the code? What tool do you use? (Force.com IDE, Eclipse, Force.com migration tool, etc.)
3. Does the test code above(LeadTriggerHandlerTests) pass?
Regards,
Shingo.
Thank you very much for your quick response.
1. Do you know on which line the error occurs? (Invalid Type: LeadTriggerHandler) - we get this error when validating the deployment
2. How do you deploy the code? What tool do you use? (Force.com IDE, Eclipse, Force.com migration tool, etc.) - Eclipse
3. Does the test code above(LeadTriggerHandlerTests) pass? - I don't know
Hope this helps!
Thank you
Thank you for your reply.
Sorry I couldn't zoom the image and recognize the details...
But have you already deployed LeadTriggerHandler and its test class?
It seems you selected only trigger to deploy and not other 2 files.
Please add it to the deployment package and you are good to go :)
If you're able to deploy successfully, please close this question...