• Darko Vukasovic
  • NEWBIE
  • 10 Points
  • Member since 2022

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

I have already posted this question but I didn't get the answer I was looking for.

I am trying to create a new Task for each of the filled out fields of the New Lead that I create if 3 or more fields are filled out. So if 3 or more  of the following fields(First Name, Last Name,Email, Phone, Website, Title) are filled out I would like to create a new Task for each filled out field. In addition to that I would also like to create a New Tasks with Subject:WARNING if any of the filled out fields contain word "test".

When you paste the code below in Developer Console you can see that you get an error message "Method does not exist or incorrect signature:void contains(String) from the type Object" for the following line of Code:

if(MyLead.get(NonEmptyFields.get(i)).contains('test')){

So can you please help me with getting rid of this error message.

Here below is my code:

trigger Homework5 on Lead (before insert, after insert) {

List<Task> taskToInsertList = new List<Task>();
            for (Lead myLead:Trigger.new){
                
                List<String> NameOfFields = New List<String>();
                NameOfFields.add('FirstName');
                NameOfFields.add('LastName');
                NameOfFields.add('Email');
                NameOfFields.add('Phone');
                NameOfFields.add('Website');
                NameOfFields.add('Title');
                
                List<String> NonEmptyFields = new List<String>();                                                                                  
                for(Integer i=0;i<NameOfFields.size();i++){
                    if(myLead.get(NameOfFields.get(i)) !=null){
                        NonEmptyFields.add(NameOfFields.get(i));                        
                    }
                } 
                                                
               if(NonEmptyFields.size()>=3){                
                for(Integer i=0;i<NonEmptyFields.size(); i++){
                if(MyLead.get(NonEmptyFields.get(i)).contains('test')){ 
                Task myTask = new Task();
                myTask.whoId = myLead.Id;
                myTask.Subject = 'WARNING';
                myTask.Status = 'Not Started';
                taskToInsertList.add(myTask);
            }
                      
                else{Task myTask = new Task();
                myTask.whoId = myLead.Id;
                myTask.Status = 'Not Started';
                taskToInsertList.add(myTask);}
                
             }    
           
              insert taskToInsertList;  
          }
                
       }
  }

Thank you.

Darko
Hi All, 

I am trying to create a new Task for each of the filled out fields of the New Lead that I create if 3 or more fields are filled out. So if 3 or more  of the following fields(First Name, Last Name,Email, Phone, Website, Title) are filled out I would like to create a new Task for each filled out field. In addition to that I would also like to create a New Tasks with Subject:WARNING if any of the filled out fields contain word "test".

When you paste the code below in Developer Console you can see that you get an error message "Method does not exist or incorrect signature:void contains(String) from the type Object" for the following line of Code:

if(MyLead.get(NonEmptyFields.get(i)).contains('test')){

So can you please help me with getting rid of this error message.

Here below is my code:

trigger Homework5 on Lead (before insert, after insert) {

List<Task> taskToInsertList = new List<Task>();
            for (Lead myLead:Trigger.new){
                
                List<String> NameOfFields = New List<String>();
                NameOfFields.add('FirstName');
                NameOfFields.add('LastName');
                NameOfFields.add('Email');
                NameOfFields.add('Phone');
                NameOfFields.add('Website');
                NameOfFields.add('Title');
                
                List<String> NonEmptyFields = new List<String>();                                                                                  
                for(Integer i=0;i<NameOfFields.size();i++){
                    if(myLead.get(NameOfFields.get(i)) !=null){
                        NonEmptyFields.add(NameOfFields.get(i));                        
                    }
                } 
                                                
               if(NonEmptyFields.size()>=3){                
                for(Integer i=0;i<NonEmptyFields.size(); i++){
                if(MyLead.get(NonEmptyFields.get(i)).contains('test')){ 
                Task myTask = new Task();
                myTask.whoId = myLead.Id;
                myTask.Subject = 'WARNING';
                myTask.Status = 'Not Started';
                taskToInsertList.add(myTask);
            }
                      
                else{Task myTask = new Task();
                myTask.whoId = myLead.Id;
                myTask.Status = 'Not Started';
                taskToInsertList.add(myTask);}
                
             }    
           
              insert taskToInsertList;  
          }
                
       }
  }

Thank you.

Darko
Hi All,

I am just starting to learn to code and I have a small question regarding the code I wrote below. 
My goal is to first calculate the number of fields which are not null(there are 6 fields I am interested in as you can see in the list) and then show that number in the custom Key_Fields_Populated__c  field.
Once I have the Key_Fields_Populated__c filled out with correct number I would also like to create a new Task and link that Task to the Lead.

For some reason when I try to create Lead I get the following message: CreatingTask: execution of AfterInsert caused by: System.FinalException: Record is read-only Trigger.CreatingTask: line 21, column 1
I

Line 21 is this line in the code below
myLead.Key_Fields_Populated__c = NonEmptyFields.size();

Here is my code:

trigger Homework5 on Lead (after insert) {
    
    for (Lead myLead:Trigger.new){

        List<String> NameOfFields = New List<String>();
        NameOfFields.add('FirstName');
        NameOfFields.add('LastName');
        NameOfFields.add('Email');
        NameOfFields.add('Phone');
        NameOfFields.add('Website');
        NameOfFields.add('Title');
        
        List<String> NonEmptyFields = new List<String>();
               
        for(Integer i=0;i<NameOfFields.size();i++){
            if(myLead.get(NameOfFields.get(i)) !=null){
               NonEmptyFields.add(NameOfFields.get(i));
           
            }
        }
      myLead.Key_Fields_Populated__c = NonEmptyFields.size();
        
       Task myTask = new Task();
       myTask.whoId = myLead.Id;
       myTask.Status = 'Not Started';
       insert myTask;
         
    } 
           
}

Thanks in advance.

Darko
Hi All, 

I have already posted this question but I didn't get the answer I was looking for.

I am trying to create a new Task for each of the filled out fields of the New Lead that I create if 3 or more fields are filled out. So if 3 or more  of the following fields(First Name, Last Name,Email, Phone, Website, Title) are filled out I would like to create a new Task for each filled out field. In addition to that I would also like to create a New Tasks with Subject:WARNING if any of the filled out fields contain word "test".

When you paste the code below in Developer Console you can see that you get an error message "Method does not exist or incorrect signature:void contains(String) from the type Object" for the following line of Code:

if(MyLead.get(NonEmptyFields.get(i)).contains('test')){

So can you please help me with getting rid of this error message.

Here below is my code:

trigger Homework5 on Lead (before insert, after insert) {

List<Task> taskToInsertList = new List<Task>();
            for (Lead myLead:Trigger.new){
                
                List<String> NameOfFields = New List<String>();
                NameOfFields.add('FirstName');
                NameOfFields.add('LastName');
                NameOfFields.add('Email');
                NameOfFields.add('Phone');
                NameOfFields.add('Website');
                NameOfFields.add('Title');
                
                List<String> NonEmptyFields = new List<String>();                                                                                  
                for(Integer i=0;i<NameOfFields.size();i++){
                    if(myLead.get(NameOfFields.get(i)) !=null){
                        NonEmptyFields.add(NameOfFields.get(i));                        
                    }
                } 
                                                
               if(NonEmptyFields.size()>=3){                
                for(Integer i=0;i<NonEmptyFields.size(); i++){
                if(MyLead.get(NonEmptyFields.get(i)).contains('test')){ 
                Task myTask = new Task();
                myTask.whoId = myLead.Id;
                myTask.Subject = 'WARNING';
                myTask.Status = 'Not Started';
                taskToInsertList.add(myTask);
            }
                      
                else{Task myTask = new Task();
                myTask.whoId = myLead.Id;
                myTask.Status = 'Not Started';
                taskToInsertList.add(myTask);}
                
             }    
           
              insert taskToInsertList;  
          }
                
       }
  }

Thank you.

Darko
Hi All,

I am just starting to learn to code and I have a small question regarding the code I wrote below. 
My goal is to first calculate the number of fields which are not null(there are 6 fields I am interested in as you can see in the list) and then show that number in the custom Key_Fields_Populated__c  field.
Once I have the Key_Fields_Populated__c filled out with correct number I would also like to create a new Task and link that Task to the Lead.

For some reason when I try to create Lead I get the following message: CreatingTask: execution of AfterInsert caused by: System.FinalException: Record is read-only Trigger.CreatingTask: line 21, column 1
I

Line 21 is this line in the code below
myLead.Key_Fields_Populated__c = NonEmptyFields.size();

Here is my code:

trigger Homework5 on Lead (after insert) {
    
    for (Lead myLead:Trigger.new){

        List<String> NameOfFields = New List<String>();
        NameOfFields.add('FirstName');
        NameOfFields.add('LastName');
        NameOfFields.add('Email');
        NameOfFields.add('Phone');
        NameOfFields.add('Website');
        NameOfFields.add('Title');
        
        List<String> NonEmptyFields = new List<String>();
               
        for(Integer i=0;i<NameOfFields.size();i++){
            if(myLead.get(NameOfFields.get(i)) !=null){
               NonEmptyFields.add(NameOfFields.get(i));
           
            }
        }
      myLead.Key_Fields_Populated__c = NonEmptyFields.size();
        
       Task myTask = new Task();
       myTask.whoId = myLead.Id;
       myTask.Status = 'Not Started';
       insert myTask;
         
    } 
           
}

Thanks in advance.

Darko