You need to sign in to do that
Don't have an account?

Help with Custom Trigger on Lead Object to Create Task
Hi all,
We're running into a little bit of trouble with a custom APEX trigger on Lead Update or Creation. We're trying to pull 3 values from custom fields on the Lead Object and create a new task and then NULL out the custom fields on the Lead record.
So far, we're able to generate the new task, but we are running into referencing issues with the custom Lead fields and we receive a "Comparison arguments must be compatible types" on the if statement.
Also when we try to simply insert the values using the Lead.variable_name references into the Subject of the task as a test it inserts as a string with a value of "variable_name."
We're unable to do this using a Workflow Rule, because you can't insert values into custom fields on Tasks using WFRs.
Any suggestions on what we're doing wrong?
Thanks for your help.
Ryan
We're running into a little bit of trouble with a custom APEX trigger on Lead Update or Creation. We're trying to pull 3 values from custom fields on the Lead Object and create a new task and then NULL out the custom fields on the Lead record.
So far, we're able to generate the new task, but we are running into referencing issues with the custom Lead fields and we receive a "Comparison arguments must be compatible types" on the if statement.
Also when we try to simply insert the values using the Lead.variable_name references into the Subject of the task as a test it inserts as a string with a value of "variable_name."
We're unable to do this using a Workflow Rule, because you can't insert values into custom fields on Tasks using WFRs.
Any suggestions on what we're doing wrong?
Thanks for your help.
Ryan
trigger AfterInsertUpdateLead on Lead (after insert, after update) { list<Task> NewLitTask = new list<Task>(); for(integer i=0; i<trigger.new.size(); i++) { Lead lead = new Lead(); if (lead.Number_of_Gap_Catalogs__c > 0 || lead.Number_of_Group_Catalogs__c > 0 || lead.Number_of_HS_Catalogs__c > 0) { NewLitTask.add(new Task( Subject = 'Lit Request', WhoID = trigger.new[i].id )); } } insert NewLitTask; }
Also, what field type are those that are used in the if statement?
You're trying to compare a field definition to a numeric value (lead.number_of_gap_catalogs__c expands to schema.lead.number_of_gap_catalogs__c, which is a static variable of type sobjectfield).
The code you actually need is far simpler than what you've written: