Skip to main content

#Apex Class0 discussing

Create lighting web component as an action in record detail page in salesforce to allow users to download all related files on opportunity with a single click and consider time out issues as i tried to create it today and it has this issue sometimes worked sometimes not and there zip file solutions try to depend on resources like salesforce stack overflow , salesforce ben and with your recommended solutions considering these things mentioned above

The apex code

public with sharing class OpportunityFilesController {

@AuraEnabled(cacheable=false)

public static List<FileWrapper> getOpportunityFiles(Id oppId) {

List<FileWrapper> results = new List<FileWrapper>();

// Get all files linked to Opportunity

List<ContentDocumentLink> links = [

SELECT ContentDocumentId, ContentDocument.Title,

ContentDocument.LatestPublishedVersionId

FROM ContentDocumentLink

WHERE LinkedEntityId = :oppId

];

// Fetch file versions

for (ContentDocumentLink l : links) {

ContentVersion v = [

SELECT Id, Title, FileExtension, VersionData, ContentSize

FROM ContentVersion

WHERE Id = :l.ContentDocument.LatestPublishedVersionId

LIMIT 1

];

// ⚠️ Add limit to avoid hitting heap size

if (v.ContentSize < 3000000) { // 3MB limit per file for safety

results.add(new FileWrapper(

v.Title + '.' + v.FileExtension,

EncodingUtil.base64Encode(v.VersionData)

));

} else {

// Instead of crashing, skip large file

results.add(new FileWrapper(

v.Title + '.' + v.FileExtension,

null,

true

));

}

}

return results;

}

public class FileWrapper {

@AuraEnabled public String fileName;

@AuraEnabled public String base64Data;

@AuraEnabled public Boolean skipped;

public FileWrapper(String f, String b) {

fileName = f;

base64Data = b;

skipped = false;

}

public FileWrapper(String f, String b, Boolean s) {

fileName = f;

base64Data = b;

skipped = s;

}

}

}

Html code

<template>

<lightning-card title="Download Files">

<lightning-button

variant="brand"

label="Download All Files"

onclick={handleDownload}

disabled={isLoading}>

</lightning-button>

<template if:true={isLoading}>

<lightning-spinner size="medium"></lightning-spinner>

</template>

</lightning-card>

</template>

Javascript code

import { LightningElement, api, track } from 'lwc';

import getOpportunityFiles from '@salesforce/apex/OpportunityFilesController.getOpportunityFiles';

import JSZip from '@salesforce/resourceUrl/jszip';

import { loadScript } from 'lightning/platformResourceLoader';

export default class OpportunityDownloadFiles extends LightningElement {

@api recordId;

isLoading = false;

jsZipInitialized = false;

renderedCallback() {

if (this.jsZipInitialized) return;

this.jsZipInitialized = true;

loadScript(this, JSZip + '/jszip.min.js');

}

async handleDownload() {

this.isLoading = true;

try {

const files = await getOpportunityFiles({ oppId: this.recordId });

const zip = new JSZip();

files.forEach(file => {

if (!file.skipped && file.base64Data) {

const content = atob(file.base64Data);

const arrayBuffer = new Uint8Array(content.length);

for (let i = 0; i < content.length; i++) {

arrayBuffer[i] = content.charCodeAt(i);

}

zip.file(file.fileName, arrayBuffer);

}

});

const blob = await zip.generateAsync({ type: 'blob' });

const link = document.createElement('a');

link.href = URL.createObjectURL(blob);

link.download = 'OpportunityFiles.zip';

link.click();

} catch (error) {

console.error(error);

} finally {

this.isLoading = false;

}

}

}

Please i want your input if they are correct

#Salesforce Developer #Apex Class #Lightning Web Components
0/9000

We're on Enterprise and have an Apex class that does HTTP callouts to a third party service. We've run this successfully for over two years. Suddenly we get the error "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"  We're told it's a developer issue and can't get support, but it's not even an Apex error; it's clearly a system error. Since when do we have to renew certificates to make HTTP callouts to a third party?

 

#Apex Class  #Apex  #Salesforce Developer

4 answers
  1. Aug 21, 2025, 7:17 PM

    This is also suddenly happening in my org, within an omniscript-->Integration Procedure. Does anyone have any clues or helpful tips from past experience? 

0/9000
2 comments
  1. Aug 20, 2025, 2:50 PM

    Hi @NESE CHARAN KUMAR I’m a member of the Trailhead Help team. If your issue has been resolved, please share the solution that worked for you and mark it as Best Answer. If the issue remains unresolved, kindly log a case here for further assistance. Thank you!

0/9000

I have configured Apex Class to run weekly for test, now I want to modify Apex Job Schedule, but I cannot find setting menu to modify already configured Apex Job Schedule.

 

How to modify?

 

#Apex #Apex Class 

6 answers
  1. Dec 29, 2023, 7:28 AM

    Hi @Yoshitaka Ono

     

    You cannot update the scheduled jobs. You need to delete the existing job and then schedule it again.

    To Delete existing job follow below step:

    Setup -> Scheduled Job -> Job Name -> Delete

    Now to schedule it again:

    Setup -> Apex Classes -> Click on Schedule Job -> Select your class name and give other values

     

    For more information check this link : https://salesforce.stackexchange.com/questions/104641/how-to-update-the-scheduled-jobs-in-apex#:~:text=You%20cannot%20update%20the%20scheduled,and%20then%20schedule%20it%20again.&text=You%20will%20see%20a%20%22Schedule,up%20the%20timing%20from%20there.

0/9000

Resources from the Salesforce Developers Ask Me Anything on Apex Updates + Innovations

 

I hope you joined us for the fantastic SFDevsAMA on Wednesday 29th November featuring @Mohith Shrivastava and @Daniel Ballinger. They loved answering your questions about Apex. 

 

If you missed it, don't worry - we recorded the series and our experts have provided some great resources that our experts for you to continue your learning! 

 

Still have questions? Post them in this thread for our experts!Resources from the Salesforce Developers Ask Me Anything on Apex Updates + Innovations I hope you joined us for the fantastic SFDevsAMA on Wednesday 29th November featuring and .

@DataWeave in Apex @Salesforce Apex Hours @Apex Transaction Finalizers @Generics in Apex @User-Mode Database Operations

 

#Ask An Expert #CommUpdates #Apex #Apex Class #ApexDevelopment #Apexhours

12 comments
  1. Jul 5, 2025, 3:03 PM

    Using libraries like ApexMocks is now super verbose because of the lack of generics. 

    With generics, this:

    private static final MyService myService = (MyService) apexMocks.mock(MyService.class);

    could be written as this:

    private static final MyService myService = apexMocks.mock(MyService.class);

     

    And mock verification would change from: 

     

    ((MyService) apexMocks.verify(myService)).doSomething();

    to

    apexMocks.verify(myService).doSomething();
0/9000

⚙️ Ever faced limitations with chaining Queueable Jobs in Salesforce Apex? 

 Static job chains can be restrictive, inefficient, and hard to manage as business processes grow more complex. 

That’s where Dynamic Queueable Chaining in Salesforce Apex becomes a game-changer. 🚀 

In this step-by-step guide, you’ll learn: 

 🔹 What is Dynamic Queueable Chaining 

 🔹 How it solves limitations of static job chaining 

 🔹 Practical implementation with code examples 

 🔹 Best practices to build scalable, flexible Apex processes 

👉 Master the art of scalable asynchronous processing with dynamic chaining. 

 Read the full guide here:

https://salesforcecodex.com/salesforce/how-to-implement-dynamic-queueable-chaining-in-salesforce-apex/

 

#Salesforce Developer #Salesforce #Apex #Apex Class #ApexDevelopment #Integration

0/9000

Unable to find Apex action class referenced as 'ContactController'. 

 

can someone help me i follow all the steps but im stuck with this error Thank you! 

 

#Trailhead Challenges  #Salesforce Developer  #Apex  #Apex Class  #Trailhead  #Trailhead Superbadges  #Trailhead Playground  #Trailhead Developer Org

1 comment
  1. May 8, 2025, 7:36 AM

    Hi, 

    The error you are facing "Unable to find Apex action class referenced as 'ContactController'" indicates Salesforce cannot locate the ContactController Apex class referenced by a Lightning Web Component (LWC) or Aura Component. To resolve this, verify the class exists in Setup > Apex Classes or Developer Console; if missing, create it with a method annotated with @AuraEnabled(cacheable=true) (e.g., public static List<Contact> getContacts()) to ensure LWC or Aura can call it. 

    If the class exists, check whether the method is annotated with @AuraEnabled , If not then do it. 

    Check the LWC’s JavaScript for the correct import (e.g., import getContacts from '@salesforce/apex/ContactController.getContacts') or the Aura component’s controller="ContactController" attribute, ensuring no typos or case mismatches. Confirm your user/profile has access to the Apex class via Setup > Profiles > Apex Class Access. 

     

    If this resolves your query mark the answer as helpful! 

    Thanks.

0/9000

Hi all,  

 

I'm having trouble getting my test class above 69% coverage and I've hit a wall, can anyone assist? 

 

 

#Developer Forums  #Apex Class

1 comment
0/9000

I would like to request a feature enhancement in Apex to support optional parameters with default values in functions. Currently, when we need to add or modify parameters in a function, we must update every call to that function across our codebase, which can be time-consuming and prone to errors. 

 

By allowing optional parameters with default values, Apex would become more flexible and maintainable, reducing the need for extensive code refactoring. This feature is already available in many modern programming languages and would greatly improve developer productivity within the Salesforce ecosystem. 

 

#Salesforce Developer #Apex #Apex Class #Salesforce_developer #ApexDevelopment #Technical Support #Salesforce #Trailhead

0/9000

// JS code:

import {LightningElement, wire} from 'lwc';import Opplist from '@salesforce/apex/OpportunityHandler.getOpportunities';import {getObjectInfo, getPicklistValues} from 'lightning/uiObjectInfoApi';import StageName from '@salesforce/schema/Opportunity.StageName';export default class OppWebComponent extends LightningElement {    opportunityData;    CloseDate = null;    StageName;    error;    options = [];    @wire(Opplist, {        CloseDate: '$CloseDate',        StageName: '$StageName'    }) wiredData({data, error}) {        if (data) {            this.opportunityData = data;            this.error = undefined;        }        else if (error) {            this.opportunityData = undefined;            this.error = error;        }    }    handleChange(event) {        let {name, value} = event.target;        if (name == 'stage') {            this.StageName = value;        }        else {            this.CloseDate = value;        }    }    @wire(getObjectInfo, {        objectApiName: 'Account'    }) wiredData;    @wire(getPicklistValues, {        recordTypeId: '$wiredData.data.defaultRecordTypeId',        fieldApiName: StageName    }) wiredPicklist({data, error}) {        if (data) {            this.options = data.values;            console.log(data);        }        else if (error) {            console.log(error);        }    }}

// HTML File

<template>    <lightning-card title="opportunity Filter">       <lightning-combobox            name="stage"            label="Status"            value={StageName}            placeholder="Select Stage"            options={options}            onchange={handleChange} ></lightning-combobox>        <lightning-input value={CloseDate} type="Date" name="date" onchange={handleChange} ></lightning-input>    </lightning-card>    <lightning-card title="Opportunity List">        <template lwc:if={opportunityData}>            <lightning-layout multiple-rows="true">                <template for:each={opportunityData} for:item="opp" for:index="i">                    <lightning-layout-item size="4" key={opp.i}>                        <c-opp-tile opportunity={opp}></c-opp-tile>                    </lightning-layout-item>                </template>            </lightning-layout>        </template>    </lightning-card></template>

// Apex Class

public with sharing class OpportunityHandler {    @AuraEnabled(cacheable = true)    public static List<Opportunity> getOpportunities(String StageName,Date CloseDate){        String Query = 'select Id,Name,CloseDate,StageName from Opportunity';        system.debug(StageName+' ayush'+CloseDate);        if(StageName!='' || CloseDate!=null){            Query+=' where ';        }        if(StageName!='') {            Query+=' StageName = :StageName ';        }        if(StageName!='' && CloseDate!=null){            Query+=' And ';        }        if(CloseDate!=null){            //String formattedTime = CloseDate.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');            Query +='CloseDate>= '+CloseDate;        }        system.debug(Query);        return Database.query(Query);    }}

 

#Apex Class

4 answers
  1. Dec 9, 2024, 1:56 PM

    Hi @Ayush Singhal

     

    This is the updated Apex Code and Js and Html.

     

    if this answer resolve your query please mark as helpful.

     

    Thanks.

     

    public with sharing class OpportunityHandler {

    @AuraEnabled(cacheable = true)

    public static List<Opportunity> getOpportunities(String StageName, Date CloseDate) {

    String query = 'SELECT Id, Name, CloseDate, StageName FROM Opportunity';

    Boolean whereClauseAdded = false;

    // Add filter for StageName if provided

    if (String.isNotBlank(StageName)) {

    query += ' WHERE StageName = :StageName';

    whereClauseAdded = true;

    }

    // Add filter for CloseDate if provided

    if (CloseDate != null) {

    if (whereClauseAdded) {

    query += ' AND CloseDate >= :CloseDate';

    } else {

    query += ' WHERE CloseDate >= :CloseDate';

    whereClauseAdded = true;

    }

    }

    // Execute query

    return Database.query(query);

    }

    }

    updated Js

    import { LightningElement, wire } from 'lwc';

    import Opplist from '@salesforce/apex/OpportunityHandler.getOpportunities';

    import { getObjectInfo, getPicklistValues } from 'lightning/uiObjectInfoApi';

    import StageName from '@salesforce/schema/Opportunity.StageName';

    export default class OppWebComponent extends LightningElement {

    opportunityData;

    CloseDate = null;

    StageName = '';

    error;

    options = [];

    // Wire to fetch opportunity data from Apex method

    @wire(Opplist, {

    StageName: '$StageName',

    CloseDate: '$CloseDate'

    })

    wiredOpportunities({ data, error }) {

    if (data) {

    this.opportunityData = data;

    this.error = undefined;

    } else if (error) {

    this.opportunityData = undefined;

    this.error = error;

    }

    }

    // Handle changes for CloseDate and StageName

    handleChange(event) {

    const { name, value } = event.target;

    if (name === 'stage') {

    this.StageName = value;

    } else if (name === 'date') {

    this.CloseDate = value;

    }

    }

    // Wire to fetch Object Info (Opportunity object info)

    @wire(getObjectInfo, { objectApiName: 'Opportunity' }) // Change 'Account' to 'Opportunity' for StageName field

    objectInfo;

    // Wire to fetch picklist values for StageName field

    @wire(getPicklistValues, {

    recordTypeId: '$objectInfo.data.defaultRecordTypeId',

    fieldApiName: StageName

    })

    wiredPicklist({ data, error }) {

    if (data) {

    this.options = data.values;

    } else if (error) {

    console.error('Error fetching picklist values: ', error);

    }

    }

    }

    Update Html

    <template>

    <lightning-card title="Opportunity Filter">

    <lightning-combobox

    name="stage"

    label="Status"

    value={StageName}

    placeholder="Select Stage"

    options={options}

    onchange={handleChange}

    ></lightning-combobox>

    <lightning-input

    value={CloseDate}

    type="Date"

    name="date"

    onchange={handleChange}

    ></lightning-input>

    </lightning-card>

    <lightning-card title="Opportunity List">

    <template if:true={opportunityData}>

    <lightning-layout multiple-rows="true">

    <template for:each={opportunityData} for:item="opp">

    <lightning-layout-item size="4" key={opp.Id}>

    <c-opp-tile opportunity={opp}></c-opp-tile>

    </lightning-layout-item>

    </template>

    </lightning-layout>

    </template>

    </lightning-card>

    </template>

0/9000