You need to sign in to do that
Don't have an account?
CSchaez
How to update a lead field based on associated activities
I'm fairly new to apex, so if this is really simple and I am just missing it, I apologize.
What I'm trying to do is take a boolean value field from the activity, use it to increment a field in the associated lead, and then toggle the boolean. Any help would be awesome.
You did not say, you are using trigger or visualforce or scontrol
Anyway
Task objTask = [select yourbooleanfield, WhoId from Task limit 1] //I am taking a task record
if(yourbooleanfield == true)
{
Lead objLead = new Lead(Id = objTask.WhoId);
objLead.yourIncremtField = objLead.yourIncremetnField++;
update objLead;
objTask.yourbooleanfield = false;
update objTask;
}
Hope this helps.
Ok so during my trial and error process, I've made a few changes...
The goal at this point is just to increment the increment field if bool__c is true.
for some reason, I keep on getting a "De-referencing a null object" error, even though there is a default value set.
trigger incrementStuff on Task(before insert)
{
private Task[] newTask = Trigger.new;
string subject = newTask[0].Subject;
subject.toLowerCase();
if (subject.contains ('stuff'))
newTask[0].bool__c = false;
else
{
newTask[0].bool__c=true;
string realId = newTask[0].WhoId;
realId = realId.substring(0,15);
Lead parent = new Lead(Id = realId);
parent.incrementField__c = parent.incrementField__c + 1;
update parent;
}
}