• Oiswarja Pyne
  • NEWBIE
  • 20 Points
  • Member since 2015
  • Accenture Services Pvt. Limited

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi All.

I need to unlock a custom object (Events__c) record when an Task is created.
Hence I propose to recall the approval process when the Task is created by using an After Insert Trigger.

Here is the below code...

Task Trigger 
trigger TaskTrigger on Task (after insert) {
    if(Trigger.IsInsert){
         TaskSequenceController.afterInsert(trigger.new);    
    }
    
}


Sequence Controller
public class TaskSequenceController{
     /**
    * Method Name : afterInsert
    * Parameter   : 
    * Return type : None
    * Description : This method is used to perform operation on after Insert event of TaskTrigger
    */
    public static void afterInsert(List<Task> taskList){           
        TaskTriggerOperation.taskOnInsert(taskList);           
    }
    
    
 }



Operation Controller

public class TaskTriggerOperation{
    /**
    * Method Name : taskOnInsert
    * Parameter   : 
    * Return type : None
    * Description : This method is used to perform operation on before Insert event of TaskTrigger
    */
    public static void taskOnInsert( List<Task> taskList){  
        Set<Id> eventIds = new Set<Id>();
      for (Task  tsk : taskList) {
       if(tsk.WhatId != null ) { 
        eventIds.add(tsk.whatId);
System.debug('All Event Ids:' +eventIds);
    } 
   
}
}
    /*
    * Method Name : recallApproval
    * Parameter   : 
    * Return type : None
    * Description : This method is used to perform recall Approval process on Event record
    */
     public static void recallApproval(Id eventIds)    
    {        
       
        List<ProcessInstanceWorkitem> piwi = [SELECT Id, ProcessInstanceId, ProcessInstance.TargetObjectId
        FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: eventIds];
        System.debug('Target Object ID:' +eventIds);
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setComments('Recalling and unlocking request.');
        req.setAction('Removed');        
        req.setWorkitemId(piwi.get(0).Id);
        req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
        Approval.process(req,false);
    } 
    }

I am kinda new to Apex.Aplogies for the amateurish coding.However the code is not working exactly the way I want.Email is sent to user , task is getting created but record is still locked as the approval process in not recalled.I checked the debug logs and found that the Event Id is getting populated correctly at the end of taskonInsert method but no ID is generated in the debug log for Recall Approval methos.I guess I am not passing the parameters correctly in the Recall Approval method.
Can anyone suggest me what to do and where I am missing out?
Thanks in advance!!

I have a two custom objectsin my org... Project and Events.I have written a trigger to update Project status field based on Event Status values.Project__c is a lookup field in Events__c object.

However I am getting the below error when i am saving it.
[Error] Error: Compile Error: Didn't understand relationship 'Events__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 54

//TriggerCode

trigger Cancel_Event on Events__c (after update) {
    // Get a list of Projects
    Set<Id> ProjectIDs = new Set<Id>();
    for (Events__c event : Trigger.New) {
        ProjectIDs.add(event.Project__c);
    }

    // Get the projects, and all related events that have been Cancelled
    List<Project__c> Projects = new List<Project__c>([ SELECT Id, Project_Status__c, (SELECT Project__c , Event_Status__c FROM Project__r.Events__c)
                                                       FROM Project__c
                                                       WHERE (Id in :ProjectIDs)
                                                       AND (Event_Status__c ='Cancelled')
                                                       FOR UPDATE]);

I know the query can be simplified using two select queries but I want to use nested queries.Kindly advise.

-M@X

Create a simple Lightning component with a styled headline. The headline must use an H1 tag with a CSS class that enforces a 24px font-size. Make the component available in the Navigation Menu of Salesforce1.The component must be named 'MyLightningComponent'.
The component must include an H1 tag with a CSS class named 'headline'. The 'headline' CSS class must set a font-size of 24px.
The Lightning Component tab that is added to Salesforce1 must be called 'MyLightning'

 

 

 

 

<aura:component implements="force:appHostable"> 
    <h1 class="headline">My Lightning Component</h1> 
</aura:component>

<aura:application >
    <h1>Hello Lightning App!</h1>
    <c:MyLightningComponent />
</aura:application>

 

.THIS .headline {
    font-size:24px;
}

 

Challenge not yet complete... here's what's wrong: 
The component is not using the correct CSS for the 'headline' class

 

Thankx 
Prashant

Hello,

Getting this:
Challenge not yet complete... here's what's wrong: 
The component does not implement the 'appHostable' interface. That interface is required to add the component to Salesforce1.


My component looks like this
 
<aura:component implements="force:appHostable">
	<h1 class="headline">Hello Trailhead</h1>
</aura:component>

 

I have a two custom objectsin my org... Project and Events.I have written a trigger to update Project status field based on Event Status values.Project__c is a lookup field in Events__c object.

However I am getting the below error when i am saving it.
[Error] Error: Compile Error: Didn't understand relationship 'Events__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 54

//TriggerCode

trigger Cancel_Event on Events__c (after update) {
    // Get a list of Projects
    Set<Id> ProjectIDs = new Set<Id>();
    for (Events__c event : Trigger.New) {
        ProjectIDs.add(event.Project__c);
    }

    // Get the projects, and all related events that have been Cancelled
    List<Project__c> Projects = new List<Project__c>([ SELECT Id, Project_Status__c, (SELECT Project__c , Event_Status__c FROM Project__r.Events__c)
                                                       FROM Project__c
                                                       WHERE (Id in :ProjectIDs)
                                                       AND (Event_Status__c ='Cancelled')
                                                       FOR UPDATE]);

I know the query can be simplified using two select queries but I want to use nested queries.Kindly advise.

-M@X