• cfdude
  • NEWBIE
  • 30 Points
  • Member since 2011

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

I'm fairly new to Apex development and am trying to get the hang of how to write these tests for triggers, but am having a tough time with this.  Any help is appreciated.

 

Here is the trigger:

 

trigger updOpportunityFromLeadConvert on Lead (before update) {

    Map<Id,String> leadIndustry     = new Map<Id,String>(); 
    Map<Id,String> leadHowHear      = new Map<Id,String>(); 
    Map<Id,String> leadOther        = new Map<Id,String>(); 
    Map<Id,String> leadDescription  = new Map<Id,String>();
    Map<Id,String> leadSource       = new Map<Id,String>();
    Map<Id,String> iiSolution       = new Map<Id,String>(); 
    
    date myDate = date.today();
    date trialCloseDate = myDate.addDays(30);
    
    for(Lead lead : Trigger.new) {
        if (lead.IsConverted) {
            leadIndustry.put(lead.ConvertedOpportunityId,lead.Industry);
            leadHowHear.put(lead.ConvertedOpportunityId,lead.How_did_you_hear_about_us__c);
            leadOther.put(lead.ConvertedOpportunityId,lead.Other__c);
            leadDescription.put(lead.ConvertedOpportunityId,lead.Description);
            if(lead.LeadSource=='Web Trial'){
                leadSource.put(lead.ConvertedOpportunityId,'In Trial');
            }else{
                leadSource.put(lead.ConvertedOpportunityId,'Targeted Leads');
            }
            if(lead.LeadSource=='Web Trial'){
                iiSolution.put(lead.ConvertedOpportunityId,'i2Dashboard');
            }
        }
    }
    
    List<Opportunity> conOpp = [Select  Id  From Opportunity  WHERE Opportunity.Id IN :leadIndustry.keySet()];
    
    for ( Opportunity o : conOpp) {
        o.Industry_Sector__c = leadIndustry.get(o.Id);
        o.How_did_you_hear_about_us__c = leadHowHear.get(o.Id);
        o.Other__c = leadOther.get(o.Id);
        o.Description = leadDescription.get(o.Id);
        o.StageName = leadSource.get(o.Id);
        o.iiSolution__c = iiSolution.get(o.Id);
        o.Type = 'New (N)';
        o.CloseDate = trialCloseDate;
        
    }
    update conOpp;
}

 

Here is the test I've written so far (with a few errors in the code already that I'm aware of).  I'm just stuck on this.

 

@isTest
private class updOpportunityFromLeadConvertTest {

    static testMethod void testUpdOpportunityFromLeadConvert(){
    	
    	// set 30 days from now
        date myDate = date.today();
    	date trialCloseDate = myDate.addDays(30);
    	
    	// create list to hold leads
    	List<Lead> leads = new List<Lead>{};
    	converts = new List[];
    	
    	// loop 200 times to make 200 leads, add to list
        for(Integer i=0; i < 200; i++){
        	Lead ld = new Lead(
        		Company='TestCo' + i, 
        		Description='Refer/Browser/Ip Info', 
        		Email='user@testco.com', 
        		Industry='Alternative Energy', 
        		LeadSource='Web Trial', 
        		Status='Incomplete Registration', 
        		FirstName='Joe', 
        		LastName='Blow', 
        		Phone='310-555-1212', 
        		Title='Senior Janitor', 
        		How_did_you_hear_about_us__c='i2live event', 
        		Other__c='beetlemania', 
        		Type__c='Lead');
        	leads.add(ld);	
       }
        
        // start test
        test.startTest();
       
        // insert lead        
        insert leads;

        
        for(Lead l : leads){
	        //Convert the lead
	        Database.LeadConvert lc = new database.LeadConvert();
	        lc.setLeadId(l.Id);
	        
	        
	        //Set the converted status
	        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
			lc.setConvertedStatus(convertStatus.MasterLabel);
	        
	        // Commit the converted lead
	        Database.Leadconvertresult lcr = Database.convertLead(lc); 
	        
	        converts.add(lcr.getOpportunityId());
        }
        
        // stop test
        test.stopTest();
        
        // Query the db for Opportunities converted from Lead
        List<Opportunity> convertOpp = [Select Industry_Sector__c, How_did_you_hear_about_us__c, Other__c,
        									  Description, StageName, iiSolution__c, Type, CloseDate
        								from Opportunity
        								Where Id IN :leads.Id];

        // Assert fields have right values
        for(Opportunity o : convertOpp){
    		System.assertEquals('Alternative Energy', o.Industry_Sector__c); 
    		System.assertEquals('i2live event', o.How_did_you_hear_about_us__c); 
    		System.assertEquals('beetlemania', o.Other__c);
			System.assertEquals('Refer/Browser/Ip Info', o.Description); 
    		System.assertEquals('In Trial', o.StageName);
    		System.assertEquals('i2Dashboard', o.iiSolution__c);
    		System.assertEquals('New (N)', o.Type);
			System.assertEquals(trialCloseDate, o.CloseDate);
    		
        }
        
        
    
    }


}

 

 

 

Hi, I'm using ColdFusion 9.01 and the Enterprise Soap API, version 22.0.  I'm trying to call the convertLead() method and I'm getting the following error.

 

Request sent:

 

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <urn:SessionHeader>
            <urn:sessionId>(sessionid removed for clarity)</urn:sessionId>
        </urn:SessionHeader>
    </soapenv:Header>
    <soapenv:Body>
        <urn:convertLead>
            <urn:leadConverts>
                <OPPORTUNITYNAME>Joe Blow - 30 Day Trial</OPPORTUNITYNAME>
                <SENDNOTIFICATIONEMAIL>1</SENDNOTIFICATIONEMAIL>
                <CONTACTID/>
                <DONOTCREATEOPPORTUNITY>false</DONOTCREATEOPPORTUNITY>
                <LEADID>00QE0000001z3XC</LEADID>
                <OWNERID>005ExxxxxxxXa7hIAC</OWNERID>
                <OVERWRITELEADSOURCE>1</OVERWRITELEADSOURCE>
                <CONVERTEDSTATUS>Qualified</CONVERTEDSTATUS>
                <ACCOUNTID/>
            </urn:leadConverts>
        </urn:convertLead>
    </soapenv:Body>
</soapenv:Envelope>

 

 

Response:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>Element {}OPPORTUNITYNAME invalid at this location</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>

 

The thing is, if I rearrange the leadConverts elements it will always bark at whatever the first one is.  If i remove all but one, then it barks at the only remaining one.  Please help.  Thanks!

 



I'm using ColdFusion 9 and a SalesForce cfc that I updated to work with version 22.  Everything had been working fine for a while but this week, all of a sudden, I'm getting the above "invalid_type" error when trying to create a lead.  I'm sending to Enterprise API, btw.

 

Here is a sample soap request:

 

<?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:urn="urn:enterprise.soap.sforce.com"
        xmlns:urn1="urn:sobject.enterprise.soap.sforce.com"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <urn:SessionHeader>
            <urn:sessionId>(removed for clarity)</urn:sessionId>
        </urn:SessionHeader>
        <urn:AssignmentRuleHeader>
            <urn:useDefaultRule>true</urn:useDefaultRule>
        </urn:AssignmentRuleHeader>
    </soapenv:Header>
    <soapenv:Body>
        <urn:create>
            <urn:sObjects xsi:type="urn1:Lead">
                <COMPANY>TestCo</COMPANY>
                <DESCRIPTION>Signed up at: Referring IP: 127.0.0.1 </DESCRIPTION>
                <HOW_DID_YOU_HEAR_ABOUT_US__C>general event</HOW_DID_YOU_HEAR_ABOUT_US__C>
                <LEADSOURCE>Web Trial</LEADSOURCE>
                <STATUS>Incomplete Registration</STATUS>
                <OWNER>Jimbo Smith</OWNER>
                <INDUSTRY>Computing</INDUSTRY>
                <PHONE>310-555-1212</PHONE>
                <FIRSTNAME>Joe</FIRSTNAME>
                <DATE_OF_INQUIRY__C>2011-07-25</DATE_OF_INQUIRY__C>
                <EMAIL>test@here.com</EMAIL>
                <OTHER__C>Aug 4th Japan style inflation</OTHER__C>
                <TYPE__C>Lead</TYPE__C>
                <LASTNAME>Blow</LASTNAME>
                <TITLE>Chief Janitor</TITLE>
            </urn:sObjects>
        </urn:create>
    </soapenv:Body>
</soapenv:Envelope> 



Hi, I'm using ColdFusion 9.01 and the Enterprise Soap API, version 22.0.  I'm trying to call the convertLead() method and I'm getting the following error.

 

Request sent:

 

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <urn:SessionHeader>
            <urn:sessionId>(sessionid removed for clarity)</urn:sessionId>
        </urn:SessionHeader>
    </soapenv:Header>
    <soapenv:Body>
        <urn:convertLead>
            <urn:leadConverts>
                <OPPORTUNITYNAME>Joe Blow - 30 Day Trial</OPPORTUNITYNAME>
                <SENDNOTIFICATIONEMAIL>1</SENDNOTIFICATIONEMAIL>
                <CONTACTID/>
                <DONOTCREATEOPPORTUNITY>false</DONOTCREATEOPPORTUNITY>
                <LEADID>00QE0000001z3XC</LEADID>
                <OWNERID>005ExxxxxxxXa7hIAC</OWNERID>
                <OVERWRITELEADSOURCE>1</OVERWRITELEADSOURCE>
                <CONVERTEDSTATUS>Qualified</CONVERTEDSTATUS>
                <ACCOUNTID/>
            </urn:leadConverts>
        </urn:convertLead>
    </soapenv:Body>
</soapenv:Envelope>

 

 

Response:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>Element {}OPPORTUNITYNAME invalid at this location</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>

 

The thing is, if I rearrange the leadConverts elements it will always bark at whatever the first one is.  If i remove all but one, then it barks at the only remaining one.  Please help.  Thanks!

 



I'm using ColdFusion 9 and a SalesForce cfc that I updated to work with version 22.  Everything had been working fine for a while but this week, all of a sudden, I'm getting the above "invalid_type" error when trying to create a lead.  I'm sending to Enterprise API, btw.

 

Here is a sample soap request:

 

<?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:urn="urn:enterprise.soap.sforce.com"
        xmlns:urn1="urn:sobject.enterprise.soap.sforce.com"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <urn:SessionHeader>
            <urn:sessionId>(removed for clarity)</urn:sessionId>
        </urn:SessionHeader>
        <urn:AssignmentRuleHeader>
            <urn:useDefaultRule>true</urn:useDefaultRule>
        </urn:AssignmentRuleHeader>
    </soapenv:Header>
    <soapenv:Body>
        <urn:create>
            <urn:sObjects xsi:type="urn1:Lead">
                <COMPANY>TestCo</COMPANY>
                <DESCRIPTION>Signed up at: Referring IP: 127.0.0.1 </DESCRIPTION>
                <HOW_DID_YOU_HEAR_ABOUT_US__C>general event</HOW_DID_YOU_HEAR_ABOUT_US__C>
                <LEADSOURCE>Web Trial</LEADSOURCE>
                <STATUS>Incomplete Registration</STATUS>
                <OWNER>Jimbo Smith</OWNER>
                <INDUSTRY>Computing</INDUSTRY>
                <PHONE>310-555-1212</PHONE>
                <FIRSTNAME>Joe</FIRSTNAME>
                <DATE_OF_INQUIRY__C>2011-07-25</DATE_OF_INQUIRY__C>
                <EMAIL>test@here.com</EMAIL>
                <OTHER__C>Aug 4th Japan style inflation</OTHER__C>
                <TYPE__C>Lead</TYPE__C>
                <LASTNAME>Blow</LASTNAME>
                <TITLE>Chief Janitor</TITLE>
            </urn:sObjects>
        </urn:create>
    </soapenv:Body>
</soapenv:Envelope>