• Ashwini Zine 5
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi all,
I need to capture an approval comments to populate a lead custom field when the lead status = unqualified and the step status = rejected. I have an error compilation like "Error: Compile Error: Variable does not exist: Lead at line 14 column 109"
Here is my code. Any help?
trigger Unqualified on Lead (before update) {
//Get all approval process records from an approval process definition. ProcessDefinitionId = The ID of this approval process instance.TargetObjectId = ID of the object affected by this approval process instance.//
List<ProcessInstance> instances = [SELECT Id,TargetObjectId,(SELECT Id, StepStatus, Comments FROM Steps) FROM ProcessInstance Where ProcessDefinitionId  = '[ TargetObjectId]'];

//guarda la información de los leads. Declara e inicializa. List (nombre del objeto)//
List<Lead> Leads = New List <Lead>(); 

//Create a set of object Ids which has process instance//
    for(ProcessInstance pi:instances){
        LeadIds.add(pi.TargetobjectId);
    }
 
//Query for related records//
Map<Id,Lead> LeadMap = new Map<Id,Lead>([Select ReasonRejectedByCommercialPlanning__c from Lead Where Id in:Lead]);

//populate object's reason rejected field from approval comments
if (l.status == 'Unqualified')
    if (l.recordtypeId == '0121A000000QeSxQAK')
    for(ProcessInstance pi:instances){
       for (ProcessInstanceStep step : pi.Steps) {
         if(step.Status == 'Rejected') {
            LeadMap.get(pi.TargetObjectId).ReasonRejectedByCommercialPlanning__c = step.Comments;
         }
       }
    }

//Update your object//
update LeadMap.values();
  • January 31, 2017
  • Like
  • 0