• StephenDickson
  • NEWBIE
  • 30 Points
  • Member since 2019


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 11
    Replies
Hi All,

I have been attempting to create a button in a LWC that when clicked would pass the current recordId to a method in an existing controller class.  This method fires other methods, all using the recordId as a parameter.  What am I doing wrong?

Apex method:
@AuraEnabled(cacheable=true)
    public static list<Task> generateRDLAndReturnTaskList(id recordId){
        String objectName = recordId.getSObjectType().getDescribe().getName();
        Required_Documents_List_Controller.generateRDL_AuraEnabled(objectName, (String)recordId);
        list<Task> myReturnList = new list<Task>();
        myReturnList = RDL_Lightning_Component_Controller.checkForRDL(recordId);
               
        return myReturnList;
    }

Javascript:
import { LightningElement, api, wire, track} from 'lwc';
import generateRDLAndReturnTaskList from '@salesforce/apex/RDL_Lightning_Component_Controller.generateRDLAndReturnTaskList';

export default class RequiredDocumentList_LWC extends LightningElement {
    @api recordId;
    @track error;
    @track myReturnList


    handleNewClick() {
        generateRDLAndReturnTaskList($recordId)
            .then(result => {
                this.myReturnList = result;
            })
            .catch(error => {
                this.error = error;
            });
    }
}

HTML:
<template>

    <div class="slds-m-around_medium">
        <h1 class="slds-text-heading_small">Required Documents List</h1>
    </div>

    <div class="c-container">
            <lightning-layout>
                <lightning-layout-item padding="around-small">
                        <lightning-layout-item padding="around-small">
                                    <lightning-button
                                        label="Generate RDL"
                                        onclick={handleNewClick}>
                                    </lightning-button>
                        </lightning-layout-item>
                </lightning-layout-item>
            </lightning-layout>
        </div>

</template>

​​​​​​​
Considering the inherent problems with OOP (https://medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53), and since Salesforce is always on the cutting edge, is there a universe in which Salesforce would move away from OOP and toward Functional Programing?  

I'm a certified Salesforce professional but still relatively new to writing code. I've been working on learning Apex in order to be able to hold my own as a Salesforce Developer......I'd love to be reassured that I'm not wasting my time learning Object-Oriented Programming.  

Admittedly, my grasp of the two different engineering approaches is very limited so I'm speaking as a newbie :)
Now that Force.com IDE is out, can anyone help me figure out how to delete classes and triggers from production using VSCode SFDX?  

I tried the SFDX command, "Delete this from Project and Org," but the error stated testLevel of NoTestRun cannot be used and I can't see where to change the test level.

Thanks in advance!
I created a trigger to update a custom field (Mailing County) before insert of a Contact.  The trigger takes the MailingPostalCode entered by the user and finds the County in which that zip code is found.  This is done via a custom object (Zip_Code__c) in which the Postal Codes are stored along with their respective Counties.

I would love any feedback on how to make this trigger better, but specifically I am confused because one of my test methods is not working (TestContactWithValidZip).  This particular test gets caught by my addError clause of my trigger.

Trigger:
trigger CountyLookupByZip on Contact (before insert) {
    for (Contact c : Trigger.New) {
        if(c.MailingPostalCode != null) {
        	List<Zip_Code__c> contactCounty = new List<Zip_Code__c>();
            contactCounty = [SELECT Id,
                                County__c,
                                Postal_Code__c
         				 FROM   Zip_Code__c 
        			     WHERE  Postal_Code__c = :c.MailingPostalCode];
            if(contactCounty.size() != 0){
            	c.Mailing_County__c = contactCounty[0].County__c;
            } else {
                c.MailingPostalCode.addError('Postal Code not found. Please ensure the postal code is a valid Virginia zip code.');
            }
        }
	}
}
Test Clas:
@isTest
public class TestCountyLookupByZip {

    @isTest
    public static void TestContactWithNullZip() {
        // Test data setup
        // Create a contact without a Mailing Postal Code
        // and check to ensure County is also null
        Contact contactNullZip = new Contact(LastName = 'Test');
        insert contactNullZip;
        
        // Perform Test
        System.assertEquals(contactNullZip.Mailing_County__c, null);
    }

    @isTest
    public static void TestContactWithValidZip() {

        // Test data setup
        // Create a contact with a valid VA Mailing Postal Code
        // and check to ensure County is updated correctly
        
    	Contact contactValidZip = new Contact(LastName = 'Test', MailingPostalCode = '20101');
        insert contactValidZip;
        
        // Perform Test
        System.assertEquals(contactValidZip.Mailing_County__c, 'Loudoun');
    }   
    
    @isTest
    public static void TestContactWithInvalidZip() {
        // Test data setup
        // Create a contact with an invalid Mailing Postal Code
        // and throw an error
        Test.startTest();
        try {
       		Contact contactInvalidZip = new Contact(LastName = 'Test', MailingPostalCode = '17602');
        	insert contactInvalidZip;
        // Perform Test
        } catch(Exception e) {
			System.Assert(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'));
            System.Assert(e.getMessage().contains('Postal Code not found. Please ensure the postal code is a valid Virginia zip code.'));
        }
        Test.stopTest();
    }
}


 
I have been trying to deploy apex classes to a Trailhead Playgound as well as a developer org, but I receive the error "SFDX: Deploy Source to Org failed to run" in VS Code. 

Did I miss something when I set-up VS Code?
  • Salesforce CLI is up to date
  • All extensions are up to date
  • The orgs in question have been authorized successfully
  • The CLI appears to be installed correctly (when I run "sfdx" in the Terminal, I receive the Salesforce CLI menu)

This is the Salesforce CLI output:
Starting SFDX: Deploy Source to Org
11:35:46.868 sfdx force:source:deploy --sourcepath c:\Salesforce\VSCodeQuickStart\force-app --json --loglevel fatal
11:35:48.630 sfdx force:source:deploy --sourcepath c:\Salesforce\VSCodeQuickStart\force-app --json --loglevel fatal ended with exit code 1

Any help would be much appreciated!
Now that Force.com IDE is out, can anyone help me figure out how to delete classes and triggers from production using VSCode SFDX?  

I tried the SFDX command, "Delete this from Project and Org," but the error stated testLevel of NoTestRun cannot be used and I can't see where to change the test level.

Thanks in advance!
I created a trigger to update a custom field (Mailing County) before insert of a Contact.  The trigger takes the MailingPostalCode entered by the user and finds the County in which that zip code is found.  This is done via a custom object (Zip_Code__c) in which the Postal Codes are stored along with their respective Counties.

I would love any feedback on how to make this trigger better, but specifically I am confused because one of my test methods is not working (TestContactWithValidZip).  This particular test gets caught by my addError clause of my trigger.

Trigger:
trigger CountyLookupByZip on Contact (before insert) {
    for (Contact c : Trigger.New) {
        if(c.MailingPostalCode != null) {
        	List<Zip_Code__c> contactCounty = new List<Zip_Code__c>();
            contactCounty = [SELECT Id,
                                County__c,
                                Postal_Code__c
         				 FROM   Zip_Code__c 
        			     WHERE  Postal_Code__c = :c.MailingPostalCode];
            if(contactCounty.size() != 0){
            	c.Mailing_County__c = contactCounty[0].County__c;
            } else {
                c.MailingPostalCode.addError('Postal Code not found. Please ensure the postal code is a valid Virginia zip code.');
            }
        }
	}
}
Test Clas:
@isTest
public class TestCountyLookupByZip {

    @isTest
    public static void TestContactWithNullZip() {
        // Test data setup
        // Create a contact without a Mailing Postal Code
        // and check to ensure County is also null
        Contact contactNullZip = new Contact(LastName = 'Test');
        insert contactNullZip;
        
        // Perform Test
        System.assertEquals(contactNullZip.Mailing_County__c, null);
    }

    @isTest
    public static void TestContactWithValidZip() {

        // Test data setup
        // Create a contact with a valid VA Mailing Postal Code
        // and check to ensure County is updated correctly
        
    	Contact contactValidZip = new Contact(LastName = 'Test', MailingPostalCode = '20101');
        insert contactValidZip;
        
        // Perform Test
        System.assertEquals(contactValidZip.Mailing_County__c, 'Loudoun');
    }   
    
    @isTest
    public static void TestContactWithInvalidZip() {
        // Test data setup
        // Create a contact with an invalid Mailing Postal Code
        // and throw an error
        Test.startTest();
        try {
       		Contact contactInvalidZip = new Contact(LastName = 'Test', MailingPostalCode = '17602');
        	insert contactInvalidZip;
        // Perform Test
        } catch(Exception e) {
			System.Assert(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'));
            System.Assert(e.getMessage().contains('Postal Code not found. Please ensure the postal code is a valid Virginia zip code.'));
        }
        Test.stopTest();
    }
}


 
I need help in writing a trigger, I have two objects

1) Opportunity
2) Opportunity_ Program__c

both are having lookup relationship, Opportunity is Parent and Opportunity Program is child.

Opportunity program has Status field.

I need to write a trigger on Opportunity Program object, for a given Opportunity if any of the child records contains status as "MATR" then Opportunity.StageName = 'Closed Won', if any of the child record for a given opportunity does not contain "MATR" then Opportunity.StageName = 'Closed Lost'

Can anyone helps me out in this issue please.
I have been trying to deploy apex classes to a Trailhead Playgound as well as a developer org, but I receive the error "SFDX: Deploy Source to Org failed to run" in VS Code. 

Did I miss something when I set-up VS Code?
  • Salesforce CLI is up to date
  • All extensions are up to date
  • The orgs in question have been authorized successfully
  • The CLI appears to be installed correctly (when I run "sfdx" in the Terminal, I receive the Salesforce CLI menu)

This is the Salesforce CLI output:
Starting SFDX: Deploy Source to Org
11:35:46.868 sfdx force:source:deploy --sourcepath c:\Salesforce\VSCodeQuickStart\force-app --json --loglevel fatal
11:35:48.630 sfdx force:source:deploy --sourcepath c:\Salesforce\VSCodeQuickStart\force-app --json --loglevel fatal ended with exit code 1

Any help would be much appreciated!
Hello, 

When I try to deploy a class to my Production organization using sfdx the error produced does not show enough details.
I am executing the command:
sfdx force:source:deploy -m ApexClass:ClassNameRepository -l RunLocalTests -u myOrgProd --json --loglevel error
Response error:
{
    "status": 1,
    "result": [
        {
            "error": "Unknown"
        }
    ],
    "name": "DeployFailed",
    "message": "Deploy failed.",
    "exitCode": 1,
    "commandName": "SourceDeployCommand",
    "data": [
        {
            "error": "Unknown"
        }
    ],
    "stack": "DeployFailed: Deploy failed.\n    at MetadataRegistry.initializeMetadataTypeInfos.then.then.catch.e (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\salesforce-alm\\dist\\lib\\source\\sourceApiCommand.js:64:31)\n    at tryCatcher (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\util.js:16:23)\n    at Promise._settlePromiseFromHandler (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\promise.js:517:31)\n    at Promise._settlePromise (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\promise.js:574:18)\n    at Promise._settlePromise0 (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\promise.js:619:10)\n    at Promise._settlePromises (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\promise.js:695:18)\n    at _drainQueueStep (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\async.js:138:12)\n    at _drainQueue (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\async.js:131:9)\n    at Async._drainQueues (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\async.js:147:5)\n    at Immediate.Async.drainQueues [as _onImmediate] (C:\\Users\\whernandez\\AppData\\Local\\sfdx\\node_modules\\bluebird\\js\\release\\async.js:17:14)\n    at runCallback (timers.js:705:18)\n    at tryOnImmediate (timers.js:676:5)\n    at processImmediate (timers.js:658:5)",
    "warnings": []
}
I upgrade to the following versions sfdx-cli / 7.30.13-9e204762d5 win32-x64 node-v10.15.3
and salesforcedx installed v47.3.7