You need to sign in to do that
Don't have an account?
Darko Vukasovic
Need help with Contains dot notation
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
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
Please see the below code and Implement it in your logic.
You have to typecast with String because get() method returns the object.
Mark as the best answer if it is helpful for you.
Thanks,
Vinayak Karande