• Wendy Tanner 11
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
Email to case is set up. Detail comes in to the description: 

First Name: xxxxx
Last Name: Test
Email: test@gmail.com
Phone: xxxxxxxx
Country: US
Comment: Last Test!
TextAlertsOptIn: Yes

I ahve Fields for each option and I need to pass the information in to those fields. the format is the same every time. 

Any suggestions or examples of how this can be done, Trigger? New to apex and any detail is appreciated. 

 
Hello! I have an apex class that was working great in sandbox. 
Using it in a process builder. Any one doing this, can you provide guidance? 


Public class AutoConvertLeads
{
    @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);
           
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
            System.assert(Leadconverts.isSuccess());
   }
}


When trying to push to prod, it states i need a test class. Tried the example below and i am not able to get it to work. Any input appreciated. When i run test it says lead already converted? 
@isTest 
      public class TestAutoConvertLeads{
      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= userToCreate.id;
      leadToCreate.LastName ='Test1';
      leadToCreate.LeadSource='Employee Referral';
      leadToCreate.Rating='';
      leadToCreate.Status='';
      insert leadToCreate; 
      
      Ids.add(leadToCreate.id);
      AutoConvertLeads.LeadAssign(Ids);
      
      Test.stopTest();
   }
}