• Manish Deshmukh
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 4
    Replies

I want to add a year view to a fullcalendar. I can add day, month and week. 

Below is my code.

<template>
  <div class="slds-grid slds-gutters">
    <div class="slds-col">
      <span>
        <lightning-card  title="Other">
          <p class="slds-p-horizontal_small">
          <lightning-input type="date" name="input1" label="Start date" ></lightning-input>
          <lightning-input type="date" name="input1" label="End date" ></lightning-input>
        </p> 
      </lightning-card>
      </span>
      <lightning-button variant="brand" label="Apply" title="Primary action" onclick={handleClick} class="slds-m-left_x-small"></lightning-button>
    </div>
  </div>

    <div class="slds-box outerPart">
      
      <p class="slds-m-bottom_small">Opportunity Visualizer</p>
      <!--lightning-button variant="brand" name="verifyMail" label="Sync Salesforce Tasks" onclick​={initialiseFullCalendarJs}></lightning-button-->
      <div style="background:#ffffff;" class="slds-grid slds-m-top_medium">
        <div id="calendar" class="fullcalendarjs"></div>
      </div>
      <div if:true={casesSpinner} class="slds-spinner_inline spinner-padding">
        <lightning-spinner variant="brand" 
                           alternative-text="Loading Cases"     
                           size="medium">
        </lightning-spinner>
    </div>
    </div>
  </template>
import { LightningElement, track } from 'lwc';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import FullCalendarJS from '@salesforce/resourceUrl/FullCalendarResource';
import getOppo from '@salesforce/apex/oppoCloseDate.getOppo';
//import heySfLogo from '@salesforce/resourceUrl/heySfLogo';
/**
 * @description Full Calendar JS - Lightning Web Components
 */
export default class opportunityVisualizer extends LightningElement {
//  @track eventData ;
  @track returnedOppo = [] ;
  @track finalOppo = [] ;
  @track casesSpinner = true;
  //SfLogo = heySfLogo ;

  renderedCallback() {
    Promise.all([
      loadScript(this, FullCalendarJS + '/FullCalendarJS/jquery.min.js'),
      loadScript(this, FullCalendarJS + '/FullCalendarJS/moment.min.js'),
      loadScript(this, FullCalendarJS + '/FullCalendarJS/fullcalendar.min.js'),
      loadStyle(this, FullCalendarJS + '/FullCalendarJS/fullcalendar.min.css'),
      // loadStyle(this, FullCalendarJS + '/fullcalendar.print.min.css')
    ])
    .then(() => {
      // Initialise the calendar configuration
      this.getTasks();
    })
    .catch(error => {
      // eslint-disable-next-line no-console
      console.error({
        message: 'Not Loading FullCalendarJS',
        error
      });
    })
  }
  initialiseFullCalendarJs() {
    var str = window.location.href;
    var pos = str.indexOf(".com/");
    var last = pos + 4;
    var tDomain = str.slice(0,last);
    for(var i = 0 ; i < this.returnedOppo.length ; i++)
    {
      this.finalOppo.push({
        start : this.returnedOppo[i].CloseDate,
        title : this.returnedOppo[i].Name,
        url : tDomain+'/lightning/r/Opportunity/'+this.returnedOppo[i].Id+'/view'
    });
    }
    const ele = this.template.querySelector('div.fullcalendarjs');
    // eslint-disable-next-line no-undef
    $(ele).fullCalendar({
      header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,basicWeek,basicDay'
      },
     // defaultDate: '2020-03-12',
      defaultDate: new Date(), // default day is today
      navLinks: true, // can click day/week names to navigate views
      editable: true,
      eventLimit: true, // allow "more" link when too many events
      events : this.finalOppo
    });
  }
  getTasks(){
    getOppo()
        .then(result =>{   
           this.returnedOppo = JSON.parse(result);
           this.casesSpinner = false;
            this.initialiseFullCalendarJs();
            this.error = undefined;
        })
        .catch(error => {
            this.error = error;
            this.outputResult = undefined;
        });
  }
}


Output : 

User-added image

How do I add the year view?

  1. trigger updateContact on Opportunity (after insert,after update) {
  2.     
  3.     if(Trigger.isInsert || Trigger.isUpdate ){
  4.      
  5.         Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>(); 
  6.         List<Id> contactIdList = new List<Id>();
  7.         Map<Id, Contact> mapcontact = new Map<Id, Contact>();
  8.         Map<Id, List<Contact>> opptyContactMap = new Map<Id, List<Contact>>();
  9.         for(Opportunity opp : Trigger.new){
  10.             oppMap.put(opp.Id, opp);
  11.         }
  12.         //Contact[] contactList = [ SELECT Id, Nurture_Path__c FROM Contact WHERE Id IN ( SELECT ContactId FROM OpportunityContactRole WHERE OpportunityId IN: oppMap.keySet()) ];
  13.         
  14.         OpportunityContactRole[] opptyConRole = [SELECT ContactId, OpportunityId FROM OpportunityContactRole
  15.                                              WHERE OpportunityId IN: oppMap.keySet()];
  16.         
  17.         Map<Id, List<ID>> opptyContIdMap = new Map<Id, List<ID>>();
  18.         
  19.         for(OpportunityContactRole ocr : opptyConRole){
  20.             
  21.             if(opptyContIdMap.containsKey(ocr.OpportunityId))
  22.                 contactIdList = opptyContIdMap.get(ocr.OpportunityId);
  23.             else
  24.                 contactIdList = new List<Id>();
  25.             
  26.             contactIdList.add(ocr.ContactId);
  27.             opptyContIdMap.put(ocr.OpportunityId, contactIdList);
  28.         }
  29.         
  30.         for(Opportunity oppty : oppMap.values() ) {
  31.             system.debug('opptyContIdMap==>'+opptyContIdMap);
  32.             if(opptyContIdMap != NULL && !opptyContIdMap.isEmpty() ){
  33.                 if(oppty.stageName.contains('Prospecting')){
  34.                     for(Id idr : opptyContIdMap.get(oppty.Id)){
  35.                         Contact con = new contact(id = idr);
  36.                         if(!mapcontact.containsKey(con.id)){
  37.                             con.Nurture_Path__c = 'PreQual Op Nurture';
  38.                             mapcontact.put(con.id, con);
  39.                         }
  40.                     }
  41.                 }
  42.             else{
  43.                 for(Id idr : opptyContIdMap.get(oppty.Id)){
  44.                     Contact con = new contact(id = idr);
  45.                     if(!mapcontact.containsKey(con.id)){
  46.                         con.Nurture_Path__c = '';
  47.                         mapcontact.put(con.id, con);
  48.                     }
  49.                 }
  50.                     
  51.             }
  52.             }
  53.         }
  54.         List<Contact> conToUpdate = mapcontact.values();
  55.         if(conToUpdate!= NULL && !conToUpdate.isEmpty())
  56.         update conToUpdate;
  57.     }  
  58. }
How to write Trigger for this automation Logic-:
IF contact is associated to an opportunity and opportunity stage = "PreQual" THEN update Contact Picklist field to "PreQual Op Nurture"

IF contact associated to an opportunity and opportunity state = "Qualified", "Discovery", "Solution Overview", "Scoping", "Proposal", "Pending Approval","Won", "Closed Lost", or "Cancelled" THEN clear out Contact Picklist field to <None>

Please help, thanks!
  1. trigger updateContact on Opportunity (after insert,after update) {
  2.     
  3.     if(Trigger.isInsert || Trigger.isUpdate ){
  4.      
  5.         Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>(); 
  6.         List<Id> contactIdList = new List<Id>();
  7.         Map<Id, Contact> mapcontact = new Map<Id, Contact>();
  8.         Map<Id, List<Contact>> opptyContactMap = new Map<Id, List<Contact>>();
  9.         for(Opportunity opp : Trigger.new){
  10.             oppMap.put(opp.Id, opp);
  11.         }
  12.         //Contact[] contactList = [ SELECT Id, Nurture_Path__c FROM Contact WHERE Id IN ( SELECT ContactId FROM OpportunityContactRole WHERE OpportunityId IN: oppMap.keySet()) ];
  13.         
  14.         OpportunityContactRole[] opptyConRole = [SELECT ContactId, OpportunityId FROM OpportunityContactRole
  15.                                              WHERE OpportunityId IN: oppMap.keySet()];
  16.         
  17.         Map<Id, List<ID>> opptyContIdMap = new Map<Id, List<ID>>();
  18.         
  19.         for(OpportunityContactRole ocr : opptyConRole){
  20.             
  21.             if(opptyContIdMap.containsKey(ocr.OpportunityId))
  22.                 contactIdList = opptyContIdMap.get(ocr.OpportunityId);
  23.             else
  24.                 contactIdList = new List<Id>();
  25.             
  26.             contactIdList.add(ocr.ContactId);
  27.             opptyContIdMap.put(ocr.OpportunityId, contactIdList);
  28.         }
  29.         
  30.         for(Opportunity oppty : oppMap.values() ) {
  31.             system.debug('opptyContIdMap==>'+opptyContIdMap);
  32.             if(opptyContIdMap != NULL && !opptyContIdMap.isEmpty() ){
  33.                 if(oppty.stageName.contains('Prospecting')){
  34.                     for(Id idr : opptyContIdMap.get(oppty.Id)){
  35.                         Contact con = new contact(id = idr);
  36.                         if(!mapcontact.containsKey(con.id)){
  37.                             con.Nurture_Path__c = 'PreQual Op Nurture';
  38.                             mapcontact.put(con.id, con);
  39.                         }
  40.                     }
  41.                 }
  42.             else{
  43.                 for(Id idr : opptyContIdMap.get(oppty.Id)){
  44.                     Contact con = new contact(id = idr);
  45.                     if(!mapcontact.containsKey(con.id)){
  46.                         con.Nurture_Path__c = '';
  47.                         mapcontact.put(con.id, con);
  48.                     }
  49.                 }
  50.                     
  51.             }
  52.             }
  53.         }
  54.         List<Contact> conToUpdate = mapcontact.values();
  55.         if(conToUpdate!= NULL && !conToUpdate.isEmpty())
  56.         update conToUpdate;
  57.     }  
  58. }
How to write Trigger for this automation Logic-:
IF contact is associated to an opportunity and opportunity stage = "PreQual" THEN update Contact Picklist field to "PreQual Op Nurture"

IF contact associated to an opportunity and opportunity state = "Qualified", "Discovery", "Solution Overview", "Scoping", "Proposal", "Pending Approval","Won", "Closed Lost", or "Cancelled" THEN clear out Contact Picklist field to <None>

Please help, thanks!