Skip to main content

#Apex68 utenti parlano di questo argomento

I am currently encountering a similar challenge. I am building a custom Lightning Web Component (LWC) to replicate standard Salesforce List View functionality, which will allow users without administrative access to create and manage their own list views. I am utilizing Named Credentials to handle the creation and updating of these list views.

However, I am running into a few issues:

First, I am unable to retrieve only the fields that are eligible for List View creation. When I fetch the fields for the User object, the system returns every field on the object. I have realized that not all of these fields are actually available or supported for use inside a standard List View.

Second, when attempting to save the list view via the Metadata API, the standard SOQL field API names fail. When I fetch an existing list view to inspect it, the XML returns completely different internal API names, as shown in the snippet below: 

<ListView xmlns="

http://soap.sforce.com/2006/04/metadata

"> 

    <fullName>testing_list_view_2</fullName> 

    <columns>CORE.USERS.FAX</columns> 

    <columns>CORE.USERS.FIRST_NAME</columns> 

    <columns>FULL_NAME</columns> 

    <columns>DVC_Is_Manually_Cleared__c</columns> 

    <columns>CORE.USERS.LAST_LOGIN</columns> 

    <columns>CORE.USERS.LAST_NAME</columns> 

    <columns>CORE.USERS.MIDDLE_NAME</columns> 

    <columns>CORE.USERS.CELL</columns> 

    <columns>CORE.USERS.COMMUNITY_NICKNAME</columns> 

    <columns>OOO_End_Date__c</columns> 

    <columns>OOO_Start_Date_Time__c</columns> 

    <columns>CORE.USERS.PHONE</columns> 

    <columns>Planned_Activation_Date__c</columns> 

    <columns>CORE.USERS.STATE_CODE</columns> 

    <columns>CORE.USERS.SUFFIX</columns> 

    <filterScope>Everything</filterScope> 

    <label>testing list view 2</label> 

    <sharedTo> 

        <allInternalUsers></allInternalUsers> 

    </sharedTo> 

</ListView> 

 

Based on this, I have two questions:

  1. Is there a programmatic way to retrieve only the specific fields that are available for selection when creating a User List View in the standard Salesforce UI?
  2. Is there an official documentation page or mapping matrix I can refer to that translates standard SOQL field API names to these specific Metadata API names?

#Salesforce Developer  #TrailblazerCommunity  #Apex

2 risposte
  1. Oggi, alle 03:31

    Hi @Manav joshi

     

     

    I agree with suggestions provided by Danish. 

    Two other things worth considering before building and maintaining that mapping:

    • Check whether you need a custom LWC at all. Users without admin access can already create their own private list views if they have the ā€œCreate and Customize List Viewsā€ permission.
    • If you do need the LWC, look at the UI API list view resources instead of the Metadata API. They work with normal field API names, so the CORE.USERS.* mapping problem goes away. 
0/9000

I have a trigger and a apex class that should be showing a custom message when a user tries to upload a file on a record related list when the file name has too many characters. But when i test it, it shows the standard  Can't upload message. I'm not sure what I am doing wrong 

 

trigger tr_ContentVersionTrigger on ContentVersion (before insert) {

charContentVersionTriggerHandler.validateFileNameLength(Trigger.new);

}

public with sharing class charContentVersionTriggerHandler {

private static final Integer MAX_CHAR_LIMIT = 80;

public static void validateFileNameLength(List<ContentVersion> newFiles) {

for (ContentVersion file : newFiles) {

if (file.Title != null && file.Title.length() > MAX_CHAR_LIMIT) {

String errorMessage = 'The file name "' + file.Title +

'" exceeds the maximum system limit of ' + MAX_CHAR_LIMIT +

' characters. Please rename the file and try again.';

file.addError(errorMessage);

}

}

}

}

 

#Apex  #Triggers

1 risposta
  1. 23 ott, 20:12

    Your trigger is most likely firing fine. The catch is the Upload Files dialog on the related list doesn't show the text from addError on ContentVersion, it just replaces it with its own generic "Can't upload" message. You can confirm by turning on a debug log for your user and uploading a file with a long name, your message should show up in the log. 

    If blocking isn't a hard requirement, an easier route is to shorten the name in the same before insert instead of throwing an error, so the upload just goes through:

    if (file.Title != null && file.Title.length() > MAX_CHAR_LIMIT) { 

        file.Title = file.Title.left(MAX_CHAR_LIMIT); 

    } 

     

    Title doesn't include the extension (that's on PathOnClient / FileExtension), so the file still opens normally. If you do need to block it, it's probably worth adding a note near the related list so users know about the 80 character limit, since they won't see your custom text.

0/9000
Hassan Dasti ha fatto una domanda in #Trailhead Challenges

 Hi Trailblazers! I'm currently diving deeper into Apex development and building out modular code patterns on Trailhead. For those working with enterprise codebases in production, what is your preferred design pattern for organizing trigger logic (e.g., the Trigger Handler pattern, helper classes, or specialized frameworks)?  

I'd love to hear what has worked best for maintainability and test coverage!     

 

#Apex

 

#Developer

 

#TrailblazerCommunity

 

#Trailhead Challenges

 

#Salesforce Developer

 

 

#Apex Code  #Best Practices

1 risposta
  1. 20 ott, 05:40

    Structuring Apex Triggers using a decoupled Trigger Handler framework rather than placing logic directly inside the trigger body is the universal best practice for enterprise Salesforce development.

0/9000

#Salesforce Developer #Apex When would you use Future Methods, Queueable Apex, Batch Apex, and Scheduled Apex, and how would you choose the right approach for a real-world business requirement?

1 risposta
  1. Eric BurtƩ (DEVOTEAM) Forum Ambassador
    18 ott, 21:55
0/9000

#Salesforce Admin #Salesforce Developer #Apex

 

How would you decide between Record-Triggered Flows and Apex Triggers when automating complex business processes, handling related records, and preventing recursion or duplicate updates?

1 risposta
  1. 18 ott, 13:06

    Hi @M Anjil Reddy Good question! Record-Triggered Flows are best for simple to moderately complex automation without coding, while Apex Triggers are better for complex logic, advanced processing, and scenarios requiring more control.

    I would follow these points:

    1. Before-Save Flow: Update fields on the same record.
    2. After-Save Flow: Create or update related records.
    3. Apex Trigger: Handle complex logic and advanced bulk processing.
    4. Recursion: Use entry conditions, change detection, and proper trigger design.
    5. Duplicate Updates: Check whether field values have actually changed before performing DML.
    6. Best Practice: Avoid overlapping Flow and Apex automation on the same object.

    Start with Flow when it meets the requirements. Choose Apex when the logic becomes too complex or needs greater control.

    šŸ“˜ Salesforce Documentation:

     

    Record-Triggered Flows – Trailhead

    Hope this helps!

0/9000

#Salesforce Admin #Salesforce Developer #Apex How would you build a Lightning Web Component that retrieves and displays Account records using an Apex controller? Explain Apex methods, SOQL queries, the @wire decorator, error handling, and enforcement of record-level, object-level, and field-level security.

1 risposta
  1. 17 ott, 17:28

    Hi @Rakesh Goud  You can retrieve and display Account records in LWC using an Apex controller.

    Here are the key steps:

    1. Apex Class: Create an Apex method with @AuraEnabled(cacheable=true).
    2. SOQL: Query the required Account fields, such as Id, Name, and Industry.
    3. LWC JavaScript: Import the Apex method and use @wire to fetch records.
    4. LWC HTML: Display the Account records using for:each or lightning-datatable.
    5. Error Handling: Handle both data and error in the wire response.
    6. Security: Use with sharing for record-level access and WITH USER_MODE in SOQL for object-level and field-level permissions.

    A few important points:

    • Use @wire with cacheable Apex methods for read-only data.
    • Use imperative Apex when you need to control when the method runs.
    • For simple record retrieval, Lightning Data Service or UI API may be a better choice without Apex.

    Useful Salesforce Documentation:

    My suggestion is to start with a simple Account list using @wire, then add a datatable and proper error handling.

    Hope this helps!

0/9000

#Trailhead #TrailblazerCommunity #Apex

 

For a learner with strong Trailhead experience who wants to move into Salesforce development, what is the recommended learning sequence for SOQL, Apex, Lightning Web Components (LWC), and REST API integrations, and what hands-on projects can help build confidence in each area?

1 risposta
  1. 17 ott, 04:15

    Hi @Sai Pavani Yamsani Good question! Since you already have strong Trailhead knowledge, I suggest learning Salesforce Development in this order:

    1. SOQL → Apex → LWC → REST API Integration

    • SOQL: Learn SELECT, WHERE, ORDER BY, and relationship queries. Practice fetching Accounts and related Contacts.
    • Apex: Start with classes, methods, collections, DML, triggers, bulkification, and test classes. Build a simple Student Management System.
    • LWC: Learn HTML, JavaScript, data binding, events, and Apex integration. Build a searchable Account List component.
    • REST API: Learn GET, POST, JSON, authentication, Named Credentials, and Apex callouts. Integrate Salesforce with a public API.

    2. Official Learning Resources

    3. My Suggestion

    Build one complete project using all four skills, such as a Student Management Application with SOQL, Apex, LWC, and REST API integration.

    Don't focus only on completing Trailhead badges. Spend more time writing code, debugging errors, and building real-world projects.

    Consistent hands-on practice is the best way to become a confident Salesforce Developer.

    Hope this helps!

    Venkat Yadav | SFDCINDIA

0/9000

#LWC #LWC Development #Apex What practical projects can help learners understand LWC lifecycle hooks, component communication, Lightning Data Service, wire adapters, and event handling, and how should they connect LWC components with Apex methods?

2 risposte
  1. 17 ott, 04:23

    Hi @Sai Kumar Good question! The best way to learn LWC and Apex integration is to build small projects and gradually move to real-world scenarios.

    1. Recommended Practical Projects

    1. Account Search: Fetch Account records using Apex and @wire.
    2. Contact Management: Create, update, and delete Contacts using Lightning Data Service.
    3. Student Management: Practice parent-child communication using @api and custom events.
    4. Opportunity Dashboard: Display Opportunity data using Apex and refresh it after updates.

    2. Important Concepts to Practice

    • Lifecycle Hooks: connectedCallback() and renderedCallback().
    • Component Communication: @api and custom events.
    • Wire Adapters: Fetch Salesforce data using @wire.
    • Apex Integration: Use @AuraEnabled methods for server-side operations.
    • Error Handling: Handle exceptions and display meaningful messages.

    3. Official Salesforce Resources

    Start with an Account Search component, then build a complete Student Management application using LWC and Apex.

    Key Point: Don't just copy code from Trailhead. Practice writing code, debugging errors, and understanding how LWC communicates with Apex.

    Hope this helps!

    Venkat Yadav | SFDCINDIA

0/9000

#Salesforce Developer #API #Apex What should a beginner learn to integrate Salesforce with external applications using REST APIs, Named Credentials, authentication methods, and Apex callouts, and how can these integrations be tested in a Developer Org?

2 risposte
  1. 17 ott, 04:24

    Hi @Sai Kumar Good question! Salesforce REST API integration is an important skill for developers. I suggest starting with the basics and practicing in a Developer Org.

    1. Essential Steps to Learn

    1. REST API Basics: Understand GET, POST, PUT, PATCH, DELETE, JSON, and HTTP status codes.
    2. Authentication: Learn OAuth 2.0, access tokens, and secure API access.
    3. Named Credentials: Configure External Credentials and Named Credentials to manage endpoints and authentication securely.
    4. Apex Callouts: Use HttpRequest, Http, and HttpResponse to communicate with external APIs.
    5. JSON Handling: Practice JSON.serialize() and JSON.deserialize().
    6. Error Handling: Handle API failures, timeouts, and unexpected responses.
    7. Testing: Use HttpCalloutMock to write Apex test classes without making real API calls.

    2. Practical Project

    Build a simple Currency Converter or Weather Application.

    • Call a public REST API from Apex.
    • Display the API response in an LWC.
    • Handle errors and test different responses.

    3. Official Salesforce Resources

    Start with a simple GET API, then practice POST requests, OAuth authentication, and error handling.

    Key Point: Focus on understanding the complete integration process, not just writing Apex callout code.

    Hope this helps!

    Venkat Yadav | SFDCINDIA

0/9000

#Salesforce #Apex How can developers design bulkified Apex triggers and classes to handle large volumes of records efficiently while staying within Salesforce governor limits, and what common mistakes should beginners avoid?

2 risposte
  1. 17 ott, 04:25

    Hi @Sai KumarGood question! Bulkification is one of the most important Apex development practices, especially when handling large volumes of Salesforce records. 

     

    1. Best Practices for Bulkified Apex

    1. Avoid SOQL inside loops: Query all required records at once.
    2. Avoid DML inside loops: Use Lists to perform bulk insert, update, or delete operations.
    3. Use Collections: Use List, Set, and Map to process records efficiently.
    4. Handle Multiple Records: Always design triggers to process 200 records, not just one.
    5. Use Trigger Handlers: Keep business logic in separate Apex classes.
    6. Avoid Recursion: Prevent unnecessary repeated trigger execution.
    7. Write Test Classes: Test single records, bulk records, and error scenarios.

    2. Important Governor Limits

    • SOQL Queries: 100 per synchronous transaction.
    • DML Statements: 150 per transaction.
    • SOQL Rows: 50,000 per transaction.
    • CPU Time: 10 seconds for synchronous Apex transactions.

    3. Common Mistakes to Avoid

    • Writing SOQL or DML inside loops.
    • Assuming a trigger processes only one record.
    • Running unnecessary queries and updates.
    • Not testing with 200 records.

    4. Official Salesforce Resources

    Build an Account and Contact automation. When multiple Contacts are inserted, update their related Accounts using one SOQL query and one bulk DML operation.

    Key Point:

    Always write Apex code that works for 1 record and 200 records, not just a single record. 

     

    Hope this helps! Venkat Yadav | SFDCINDIA

0/9000