+ Start a Discussion
Best Answer chosen by Shreya Singh 36
Arun Kumar 1141Arun Kumar 1141
Hello Shreya,

To handle this, you can follow below steps:
  • Add button in HTML file.
<button data-id="myClick" onclick={handleMyClick}>Click on Me</button>
  • Add LightingElement in your JS file to handle button click event
import { LightningElement } from 'lwc';

export default class MyClass extends LightningElement {
    handleMyClick(event) {
        // Write your logic here
    }
}

Mark it best answer, if it helps you.
Thanks
Best Answer chosen by Albert Raul
Arun Kumar 1141Arun Kumar 1141
Hello Albert,

Absolutely! LWC provides the flexibility to incorporate external JavaScript libraries or third-party frameworks to enhance the capabilities of your components. You can achieve this by importing the desired libraries as static resources within your LWC component.
By importing external libraries, you can leverage the rich functionality and features offered by these resources directly within your LWC code. Whether it's charting libraries, data manipulation utilities, or UI frameworks, you have the freedom to tap into a vast array of existing JavaScript solutions to supercharge your LWC components.

Furthermore, LWC also supports the integration of npm modules. Leveraging the power of npm, you can seamlessly include and utilize modules from the extensive JavaScript ecosystem in your LWC components. This opens up a world of possibilities and empowers you to leverage established libraries and frameworks effortlessly.

By embracing external JavaScript libraries and npm modules, you can extend the capabilities of your LWC components, reduce development effort, and tap into the wider JavaScript community to deliver exceptional user experiences and functionality in your Salesforce applications.

Please mark it as best, if it helps you.
Thank you
Paul H 5Paul H 5 
Can Somebody Explain ?? do we need to change the fields in Contact 
whenever we we change any field in account ?? I am not getting this scenario...
Best Answer chosen by Paul H 5
VinayVinay (Salesforce Developers) 
Hi Paul,

From above statement I understand you would need to update contact status field with account status field value and below is the sample code snippet for same.
trigger CopyAccountFieldOnContactCreation on Contact (after insert) {
    // Collect a set of Account IDs associated with the newly created contacts
    Set<Id> accountIds = new Set<Id>();
    for (Contact con : Trigger.new) {
        accountIds.add(con.AccountId);
    }

    // Retrieve the corresponding accounts and their field values
    List<Account> accountsToUpdate = [SELECT Id, Custom_Field__c FROM Account WHERE Id IN :accountIds];

    // Update the account field based on the contact field
    List<Account> accountsToUpdateList = new List<Account>();
    for (Contact con : Trigger.new) {
        Account acc = new Account(Id = con.AccountId);
        for (Account a : accountsToUpdate) {
            if (a.Id == con.AccountId) {
                acc.Custom_Field__c = con.Custom_Field__c;
                accountsToUpdateList.add(acc);
                break;
            }
        }
    }

    // Perform the account field update
    if (!accountsToUpdateList.isEmpty()) {
        update accountsToUpdateList;
    }
}

Please mark as Best Answer if above information was helpful.

Thanks,
Christopher YaskoskiChristopher Yaskoski 
I've at times seen profiles set up with a IP Range Whitelist restriction of 0.0.0.0 To 255.255.255.255 (the whole internet). Is there an advantage to doing this within Salesforce vs simply removing the restriction in the first place?
Best Answer chosen by Christopher Yaskoski
VinayVinay (Salesforce Developers) 
Hi Christopher,

Adding an IP range allows users to bypass the identity verification for user interface logins and any customer apps/integrations won't need a security token. If an IP address is not added a user can still log in after they provide the verification code or security token.

Reference:
https://help.salesforce.com/s/articleView?id=000386441&type=1
https://help.salesforce.com/s/articleView?id=sf.login_ip_ranges.htm&type=5

Please mark as Best Answer if above information was helpful.

Thanks,
Ashley FreiheitAshley Freiheit 
Hello, 

I'm creating a web to lead form. One of the fields is supposed to be numeric values only, but I cannot create it as a number field because there cannot be commas in the values. I made it a text field and am attempting to create a validation that only allows numeric values, and doesn't allow the form to be submitted and throws an error to the person filling out the web form. I've added the below code to my form, but I'm not getting an error and leads are being created. Can someone spot check my javascript, as I'm totally new to this. Note: I do have ValidateForm as my form action upon submit. 

<script type='text/javascript'>
    function ValidateForm() {
        if  (isNaN(document.getElementById('MemberAccountNumber').value {
            alert("Member Account Number must only contain numeric values");
            return false;
        }
        return true;
    }
</script>
<script type='text/javascript'>
    function ValidateForm() {
        if  (isNaN(document.getElementById('MemberAccountNumber').value {
            alert("Member Account Number must only contain numeric values");
            return false;
        }
        return true;
    }
</script>



Thank you
 
Best Answer chosen by Ashley Freiheit
SubratSubrat (Salesforce Developers) 
Hello Ashley,

You are missing a closing parenthesis after document.getElementById('MemberAccountNumber').value.
<script type='text/javascript'>
    function ValidateForm() {
        if (isNaN(document.getElementById('MemberAccountNumber').value)) {
            alert("Member Account Number must only contain numeric values");
            return false;
        }
        return true;
    }
</script>

Make sure to include this JavaScript code within the <script> tags in your HTML web-to-lead form. Additionally, ensure that the form's submit button is calling the ValidateForm() function within the onsubmit attribute, like this:
<form action="your-action-url" method="POST" onsubmit="return ValidateForm()">
    <!-- Your form fields -->
    <input type="text" id="MemberAccountNumber" name="MemberAccountNumber" />
    <!-- Other fields and submit button -->
</form>

If this helps , please mark this as Best Answer.
Thank you.
Lam Ha TuanLam Ha Tuan 
I want to add custom field: StartDate to Task (Salesforce Standard object) but the salesforce does not allow that. Is there any solutions for this problem? 
Best Answer chosen by Lam Ha Tuan
SwethaSwetha (Salesforce Developers) 
HI Lam Ha Tuan,

In Salesforce, you cannot directly add custom fields to standard objects like the Task object.

As mentioned in https://help.salesforce.com/s/articleView?id=000387017&type=1 Since Events and Tasks are both part of the Activities object, you will need to create your custom fields at the Activities level.  To differentiate between Task and Event custom fields, select the appropriate page layouts on step 4 of 4 during the field creation process. The field can be added to both Tasks and Events, or just one of the objects.


If this information helps, please mark the answer as best. Thank you
Yadhagu LYadhagu L 
i have a custom button in campaign object related list of campaignmember object and I need to call vf page that will bring the campaign record id using the custom button.
Best Answer chosen by Yadhagu L
Arun Kumar 1141Arun Kumar 1141

Hi Yadhagu,

To create a custom button on the Campaign Member related list in the Campaign object that calls a Visualforce page and passes the Campaign record ID, you can follow these steps:

1. Create a Visualforce page:
  1. Go to Setup in Salesforce.
  2. Search for "Visualforce Pages" and select it.
  3. Click on "New" to create a new Visualforce page.
  4. Write the Visualforce page code that includes the logic you need. In this case, you want to access the Campaign record ID.

Here's an example of a basic Visualforce page that retrieves the Campaign ID:
<apex:page controller="CampaignMemberButtonController">
         <apex:form>
             <apex:commandButton action="{!redirectToPage}" value="Go to Campaign" />
         </apex:form>
</apex:page>
     
2. Create an Apex controller:

Create an Apex controller that retrieves the Campaign record ID and redirects to the desired page. Here's an example of an Apex controller:
public class CampaignMemberButtonController {
       public String campaignId { get; set; }
   
       public CampaignMemberButtonController() {
           campaignId = ApexPages.currentPage().getParameters().get('id');
       }
   
       public PageReference redirectToPage() {
           // Add logic or redirect to the desired page with the campaignId
           // Example: PageReference pageRef = new PageReference('/apex/YourPage?id=' + campaignId);
           // return pageRef;
           return null;
       }
   }

3. Customize the Campaign page layout:
  1. Go to the Campaign object's page layout that you want to modify.
  2. Edit the related list section for Campaign Members.
  3. Add a custom button and specify the Visualforce page you created as the content source.
  4. Save the page layout changes.

Now, when you navigate to the Campaign object and view the Campaign Member related list, you will see the custom button. Clicking on the button will invoke the Visualforce page, retrieve the Campaign record ID, and redirect to the desired page or perform any other desired logic. Make sure to customize the redirectToPage() method in the Apex controller to implement your specific logic or redirect to the appropriate page using the campaignId parameter.

Note: Ensure that the Visualforce page and Apex controller have the necessary access and visibility settings based on your organization's security requirements.

Hope this will be helpful.
Thanks!
Gokul BalijaGokul Balija 
Iam trying to export an object that has address field, but facing the below issue 
2023-05-31 21:00:23,833 ERROR [ModalContext] client.PartnerClient runOperation (PartnerClient.java:366) - Error while calling web service operation: query, error was: Failed to load class: com.sforce.soap.partner.Address
com.sforce.ws.ConnectionException: Failed to load class: com.sforce.soap.partner.Address

When checked, I couldnt find the class in dataloader 58.0.0.jar. is there a way i can download previous version of dataloader?

thanks
-gokul
Best Answer chosen by Gokul Balija
SwethaSwetha (Salesforce Developers) 
HI Gokul,
You can try the older versions of Data Loader from repositories as mentioned in
https://help.salesforce.com/s/articleView?id=000384726&type=1


Alternately, It is also possible to use older API versions using alternative tools such as Workbench by selecting 'Default API Version' in Settings.

If this information helps, please mark the answer as best. Thank you
Mahmoud Ibrahim MahmoudMahmoud Ibrahim Mahmoud 
After pausing a flow, it gets added to a list of paused interview flows. When I click resume, it opens the flow interview in a modal dialog (pop-up window), but I want it to display the flow interview in a full screen.
Best Answer chosen by Mahmoud Ibrahim Mahmoud
SubratSubrat (Salesforce Developers) 
Hi Mahmoud ,

Apoligies but your requirement is still under Idea Exchange and with no Workaround on this .

I would request you to upvote this idea so that you can get update on the same .

Idea Exchange -> https://ideas.salesforce.com/s/idea/a0B8W00000GdowKUAR/allow-customizing-width-of-quick-action-popup-window-in-lightning

Please mark this as Best Answer for closing this loop and keeping our dev forum community clean .

Thank you.
UserSFDXUserSFDX 
I want a trigger to do some dml of Lead Title should be mapped to Opportunity Name on conversion of lead.
Best Answer chosen by UserSFDX
SubratSubrat (Salesforce Developers) 
Hello ,

Can you try with the below trigger and let me know further :
trigger LeadConversionTrigger on Lead (after update) {
    // Check if the lead has been converted
    List<Lead> convertedLeads = new List<Lead>();
    for (Lead lead : Trigger.new) {
        if (lead.IsConverted && !Trigger.oldMap.get(lead.Id).IsConverted) {
            convertedLeads.add(lead);
        }
    }

    if (!convertedLeads.isEmpty()) {
        List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();

        // Retrieve the converted opportunities
        Map<Id, Opportunity> convertedOpportunities = new Map<Id, Opportunity>();
        for (Opportunity opportunity : [SELECT Id, LeadId, Name FROM Opportunity WHERE LeadId IN :convertedLeads]) {
            convertedOpportunities.put(opportunity.LeadId, opportunity);
        }

        // Update the opportunity names based on the lead titles
        for (Lead lead : convertedLeads) {
            Opportunity convertedOpportunity = convertedOpportunities.get(lead.Id);
            if (convertedOpportunity != null && lead.Title != null) {
                convertedOpportunity.Name = lead.Title;
                opportunitiesToUpdate.add(convertedOpportunity);
            }
        }

        // Perform the updates
        if (!opportunitiesToUpdate.isEmpty()) {
            update opportunitiesToUpdate;
        }
    }
}
In this trigger, we first check if the lead has been converted by verifying the IsConverted field. We iterate over the updated leads in the trigger context and identify the leads that have been converted for the first time.

Next, we query for the opportunities associated with the converted leads using the LeadId field. We store the converted opportunities in a map using the lead IDs as the keys.

Then, we iterate over the converted leads and retrieve the corresponding opportunity from the map. If the opportunity exists and the lead has a non-null title, we update the opportunity's name with the lead's title and add it to the opportunitiesToUpdate list.

Finally, if there are opportunities to update, we perform the update using the update DML statement.

If this helps , please mark this as Best Answer.
Thank you.