• Pallavi Soni 32
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
trigger AccountTrigger on Account (before update) {
    for (Account acc : Trigger.new) {
        if (acc.Status__c == 'Deceased' && (acc.DOB__c == null || acc.DOD__c == null || acc.DOD__c <= acc.DOB__c)) {
            acc.addError('Please ensure that Date of Birth is populated, Date of Death is greater than Date of Birth, and Status is set to Deceased.');
        } else if (acc.Status__c == 'Deceased') {
            List<Case> relatedCases = [SELECT Id FROM Case WHERE AccountId = :acc.Id AND IsClosed = false];
            if (!relatedCases.isEmpty()) {
                acc.addError('Please close all related cases before marking the status as Deceased.');
            }
        }
    }
}

 
Develop a Lightning component that allows users to mass update the close date on opportunities. 
Integrate this component into the Opportunity List View page and allow for bulk updates. The opportunities should be selected from the standard list view and on clikc of a butoon iit should navigate to another page where the opportunity close date gets updated and display the result . The code is not working as expected. Opportunity close date is not egtting udpated
This is the controller:
public with sharing class OpportunityUpdateController {
 @AuraEnabled(cacheable=true)
    public static void updateOpportunities(List<Id> opportunityIds, String newCloseDate) {
        List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();

        for (Id oppId : opportunityIds) {
            Opportunity opp = new Opportunity(Id = oppId);
            opp.CloseDate = Date.valueOf(newCloseDate);
            opportunitiesToUpdate.add(opp);
            system.debug('opportunitiesToUpdate:' +opportunitiesToUpdate);
        }

        update opportunitiesToUpdate;
    }
}
This is the html code

<template>
    <lightning-card title="Mass Update Close Date">
        <div class="slds-p-around_medium">
            <lightning-input type="date" label="New Close Date" value={newCloseDate} onchange={handleDateChange}></lightning-input>
            <lightning-button label="Update Close Date" onclick={updateCloseDate} variant="brand"></lightning-button>
        </div>
        <lightning-datatable
            key-field="Id"
            data={opportunities}
            columns={columns}
            selected-rows={selectedOpportunities}
            onrowselection={handleRowSelection}
        >
        </lightning-datatable>
    </lightning-card>
</template>
this is the js code
import { LightningElement, api, track } from 'lwc';
import updateOpportunities from '@salesforce/apex/OpportunityUpdateController.updateOpportunities';
const columns = [
    { label: 'Opportunity Name', fieldName: 'Name' },
    { label: 'Close Date', fieldName: 'CloseDate', type: 'date' }
];
export default class massUpdateOpportunityCloseDate extends LightningElement {
    @api opportunities;
    @track newCloseDate;
    @track columns = columns;
    @track selectedOpportunities = [];
    @track updateMessage = '';
    handleDateChange(event) {
        this.newCloseDate = event.target.value;
        console.log('New Close Date:', this.newCloseDate);
    }
    handleRowSelection(event) {
        this.selectedOpportunities = event.detail.selectedRows;
        console.log('Selected Opportunities:', this.selectedOpportunities);
    }
    updateCloseDate() {
        if (!this.newCloseDate || this.selectedOpportunities.length === 0) {
            this.updateMessage = 'Please select opportunities and provide a valid new close date.';
            return;
        }
        const opportunityIds = this.selectedOpportunities.map(opp => opp.Id);
        console.log('Opportunity IDs:', opportunityIds);
        updateOpportunities({ opportunityIds: opportunityIds, newCloseDate: this.newCloseDate })
            .then(result => {
               
                this.updateMessage = 'Opportunities updated successfully.';
                console.log('Update Result:', result);
            })
            .catch(error => {
               
                this.updateMessage = 'Error updating opportunities: ' + JSON.stringify(error);
                console.error('Update Error:', error);
            });
    }
}
 
if(trigger.isAfter && trigger.isInsert){
        list<Contact>conlist=new list<Contact>();
        for(Account acc:trigger.new){
            if(acc.Create_contact_record__c!=null){
                for(integer i=0;i < acc.Create_contact_record__c; i++){
                Contact con=new Contact();
                con.AccountId=acc.Id;
                con.LastName=acc.Name+i;
                    conlist.add(con);
                }
            }
            insert conlist;
        }
        
    }
}
   /* if(trigger.isAfter && trigger.isUpdate){
         list<Contact>conlist=new list<Contact>();
        for(Account acc:trigger.new){
            if(trigger.oldMap.get(acc.Id).Create_contact_record__c!=acc.Create_contact_record__c){
                for(integer i=0;i < acc.Create_contact_record__c; i++){
                Contact con=new Contact();
                con.AccountId=acc.Id;
                con.LastName=acc.Name+i;
                    conlist.add(con);
                }
            }
            update conlist;
        }
    }
}*/
For example - If file extension is [pdf, docx, png] and size is certain it should allow to upload. When I write trigger on contentDocument it seems its not working correctly, can any one please guide