You need to sign in to do that
Don't have an account?
Darko Vukasovic
How to get rid of Error Message for Contain dot notation
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
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
Can you try the below code.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Can you try the below code.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Thank you very much for your response. This is exactly what I was looking for.
Can you please also explain why you used String.valueof() method in this case, I would like to understand this since i am just starting to learn to code.
Best Regards,
Darko
As we can use contains() only with string field so we are taking the string value of the field using String.valueof() .
Thanks,