• Jessica Rainbow 4
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi all, 

I wouldn't call myself a developer per se, more like an overreaching admin.

Trying to build an invocable class that converts a lead if it meets a criteria set in Process Builder. 

The class itself appears to be working, but my test is failing and I have 0% code coverage. *cries*

Class: 
---------------------------------------------------------------------------------
Public class AutoConvertLead
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(LeadIds[0]);
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            Leadconvert.setConvertedStatus(Leads.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE); 
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
            System.assert(Leadconverts.isSuccess());
   }
}


---------------------------------------
Test:
----------------------------------------------

@isTest 
      public class TestAutoConvertLead{
            static testMethod void createnewlead() {
      User userToCreate = [Select id from user where profile.name='System Administrator' Limit 1];
      
      Test.startTest();    
      Lead leadToCreate =new Lead();
      List<id> Ids= New List<Id>();
      leadToCreate.Ownerid = '005D0000005sPGcIAM';
      leadToCreate.LastName ='Bertha';
      leadToCreate.Company='Salesforce';
      leadToCreate.Status='Sales Qualified';
      leadToCreate.SalesCountry__r.id = 'a002000000F9XHaAAN';
      leadToCreate.Email = 'bigbertha@testing.com';
      leadToCreate.Street ='1 Union Street';
      leadToCreate.City = 'London';
      leadToCreate.State = 'London';
      leadToCreate.PostalCode = 'SW8 2LN';
      leadToCreate.Country = 'United Kingdom';
      insert leadToCreate; 
 
      Ids.add(leadToCreate.id);
      AutoConvertLead.LeadAssign(Ids);
      
      Test.stopTest();
   }
}

------------------------------------------
Error: 
--------------------------------------------
System.NullPointerException: Attempt to de-reference a null object 
Stack Trace: Class.TestAutoConvertLead.createnewlead: line 13, column 1


Any help, or a nudge in the right direction would be appreciated.  

Thanks, 
Jess 
We are looking to push sales and trend data in to Salesforce from iTunes Connect - as it stands it doesn't look like there is an app or solution for that. It was suggested that we might need to write up a custom API for iTunes Connect to get data into Salesforce. I wondered if it was even possible and how to go about it, if it was. Any help would be greatly appreciated. 

Thanks!