• PugetSoundJim
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 8
    Replies
So I have created a LWC that has multiple lighting-inputs, lightning-comboboxes and a lightning-datatable, where the selected rows combined with the other fields are utilized to bulk create leads, events and tasks.  The LWC works fine.  Unfortunately the jest test is not so well.  To get to the point of actually mocking the Apex insert, I need to figure out how to get passed the code in the LWC where it is using the getSelectedRows() function.

Here is my test code so far.  I can't figure out how to select a row or if I should be mocking it.  This is my attempt at mocking.  
 
describe('Save/Close', () => {
        it('Should be able to save leads.', done => {
            getObjectInfo.emit(getLeadObjectInfo);
            getPicklistValues.emit(leadStatusPicklistValues);
            getPicklistValues.emit(leadSourcePicklistValues);
            getProducts.mockResolvedValue(testProductRecords);
            document.body.appendChild(element);

            flushPromises().then(() => {
                const dataTable = element.shadowRoot.querySelector('lightning-datatable');
                expect(dataTable.data).not.toBeNull();
                const tableRows = dataTable.data;
                expect(tableRows.length).toBe(2);
                console.log(JSON.stringify(tableRows));

                simulateUserSelect(element, 'salutation', 'Mr.');
                simulateUserInput(element, 'firstName', 'John');
                simulateUserInput(element, 'middleName', 'B');
                simulateUserInput(element, 'lastName', 'Doe');
                simulateUserInput(element, 'email', 'doe@example.com');
                simulateUserSelect(element, 'leadStatus', 'New');
                simulateUserSelect(element, 'leadSource', 'Referral');
                simulateUserInput(element, 'budget', '100');

                const rowSelectionHandler = jest.fn();
                element.addEventListener('rowSelect', rowSelectionHandler);
                dataTable.getSelectedRows = jest.fn().mockImplementation(() => [testProductRecords[0]]);
                dataTable.dispatchEvent(new CustomEvent('rowselection'));
                expect(rowSelectionHandler).toHaveBeenCalled();

                flushPromises().then(() => {
                    const saveButton = element.shadowRoot.querySelector('lightning-button[data-element-id="save"]');
                    saveButton.click();

                    flushPromises().then(() => {
                        const calculatedInputs = element.shadowRoot.querySelectorAll('lightning-input');
                        expect(calculatedInputs.length).toBe(0);
                        done();
                    });
                });
            });
        });
expect(rowSelectionHandler).toHaveBeenCalled();  fails.

I do know that the datatable with data is in the dom based on the earlier expects.  

Would appreciate any help.  Thanks.

 
I have a nightly Apex batch that is rather simple in my mind. For whatever reason, I am getting errors now several weeks after being implemented I would have thought been caught by now.  

The error I'm getting is "TRANSFER_REQUIRES_READ, The new owner must have read permission."  This error itself isn't a concern.  It makes complete sense.  

Basically the batch job is looking for records where the owners of ObjectA__c and ObjectB__c are different.  If they are, update ObjectA__c's Owner to ObjectB__c's.  The error being raised is a result of ObjectB__c's owner no longer being active within SFDC.

Looking at the records for the Users, ObjectA and ObjectB, I am finding no modifications in the past 24 hours that would have hit the criteria of the SOQL query.  Some of the records haven't been touched in several months.  This leads me to think that the formula field sometimes isn't being calculated during batch runs.  Has anyone seen this type of thing before?

SOQL

SELECT id, OwnerId, ObjectB__r.OwnerId FROM ObjectA__c WHERE
Ownership_Same__c = FALSE AND RecordType = Type1 AND ObjectB__c != NULL

Formula Field
Ownership_Same__c
If(OwnerId = ObjectB__r.OwnerId, TRUE, FALSE)
Transitioning a charity from its previous payment processor to PayPal.  Donor transactions work perfectly fine.  For clarity, the donation transactions do not touch Salesforce.  I'm utilizing PayPal’s Instant Payment Notification service to populate Salesforce.

I have created and set up an Apex class I’ve called IPNHandler to respond to incoming IPN calls to a configured site which allows for anonymous authentication, since IPN doesn’t have a way to configure authentication to your IPN listener (AKA Apex Class).  The class basically responds to the incoming call, validates it with PayPal and should create a custom object record with the IPN message to be processed later using flows.

In PayPal, I can see that the messages are being successfully sent to Salesforce and validated.  On the Salesforce side however, the custom object is not being populated.  (Yes, for the guest profile being used by the site, I have given read/create access to the custom object and enabled Apex Class access to the IPNHandler class.)

Furthermore, I have set up debug logging for the class both through the Developer Console and the Setup Menu, but no logs are being created even though I am simulating donations which get queued up and then sent through the IPN service.  So obviously PayPal's IPN service is reaching out to Salesforce and recieving the required response which could only have happen if the Apex call was successful.

Does anyone have any thoughts?
I have inline editing available for a lightning datatable.  I realized today that if you touch a cell but don't input any data, the update will fail with the message, "Value provided is invalid for action parameter 'target' of type 'LIST'".

Data being submitted.  The bold/italized is the cell that was touch but no data was entered.
{hct: "", Id: "blahblahblah"}

Thanks.
 
So due to business requirements, I'm using a wrapper to sum daily target data into a single "record" displayed in a lightning:datatable in an aura component.   Those summarized records are editable and when saved were divided by seven for the week.  

Now the start of the "week" is changeable.  In other words some weeks can be seven days long, others can be five depending on the start date.  I'm able to get things working fine, creation of new records, extra except for the division part when updating previous records.  

Essentially using the "Power of One," I'm summing up the number of days in the "weekly record" and displaying it in the consolidated view for users.  I would like to pass that number back to SFDC so the updated values are divided by that summed "Power of One" value.  

Hoping some one can help me figure out how to force the component to return the sum even though it hasn't changed, kind of like the ID value.   If that value is rreturned, I don't have to do a SOQL query to find the number of daily records for the various "weekly" records.

Thanks.
Use case - Field is updated on opportunity, select contactid and role associated to opportunity via opportunitycontactrole, then update related fields on the various contact records.

I am having issues getting the relationship between objects correct. 

I am looping through an opportunity list based on the ID.
In the loop I'm pulling all the contact IDs and roles from the OpportunityContactRole base related to said ID.

After that I'm trying to update the contact record based on the contact record id, but I cant get the relationship between the contact ID and opporuntitycontactrole object's contactID to associate.  Any ideas?

Appreciate the help.
Thanks!
So I am writing a class to pull out community login data from the user object to populate a custom object which will be used to create reports for customers, since community users are unable to access the user object.

Here's what I have so far.  Thinking this should work but I'm getting an error when populating the data into the custom object.
 
global class CommunityLoginHistory implements Schedulable {
    
    // This method queries the LoginHistory Object for Community User logins in the past 15 minutes and populates the CommunityLoginHistory custom object.
 
    global void execute(SchedulableContext ctx) {
        DateTime d = Datetime.now().addMinutes(-15);
        List<User> UserLoginHistory = [SELECT Id,
                                              name, 
                                              LastLoginDate, 
                                              profile.name, 
                                              userrole.name, 
                                              account.name 
                                            FROM User 
                                            WHERE profile.name LIKE '%Customer Community Plus%' 
                                            AND isactive = true 
                                            AND LastLoginDate > :d ];
                                            
        if ( !UserLoginHistory.isEmpty()) {
            List<CommunityLoginHistory__c> clh = new List<CommunityLoginHistory__c>();
            for (User ulh : UserLoginHistory) {
                clh.add (new CommunityLoginHistory__c ( UserID__c           =   Id,
                                                        UserName__c         =   name,
                                                        LastLoginDate__c    =   LastLoginDate,
                                                        UserProfile__c      =   profile.name,
                                                        UserRole__c         =   userrole.name,
                                                        UserAccount__c      =   account.name
                ));
            }
            insert clh;
        }
    }
}
In the for loop, when trying to populate the record with the data that was pulled from the SOQL query, the Developer Console is giving me the following errors.

Line 21 - Variable does not exist: Id - Illegal assignment from Schema.SObjectField to String
Line 22 - Variable does not exist: name - Illegal assignment from Schema.SObjectField to String
Line 23 - Variable does not exist: LastLoginDate - Illegal assignment from Schema.SObjectField to String

I'm at a loss for why that is the case when the console doesn't complain about the other variables.  Hoping someone can help.
So I have created a LWC that has multiple lighting-inputs, lightning-comboboxes and a lightning-datatable, where the selected rows combined with the other fields are utilized to bulk create leads, events and tasks.  The LWC works fine.  Unfortunately the jest test is not so well.  To get to the point of actually mocking the Apex insert, I need to figure out how to get passed the code in the LWC where it is using the getSelectedRows() function.

Here is my test code so far.  I can't figure out how to select a row or if I should be mocking it.  This is my attempt at mocking.  
 
describe('Save/Close', () => {
        it('Should be able to save leads.', done => {
            getObjectInfo.emit(getLeadObjectInfo);
            getPicklistValues.emit(leadStatusPicklistValues);
            getPicklistValues.emit(leadSourcePicklistValues);
            getProducts.mockResolvedValue(testProductRecords);
            document.body.appendChild(element);

            flushPromises().then(() => {
                const dataTable = element.shadowRoot.querySelector('lightning-datatable');
                expect(dataTable.data).not.toBeNull();
                const tableRows = dataTable.data;
                expect(tableRows.length).toBe(2);
                console.log(JSON.stringify(tableRows));

                simulateUserSelect(element, 'salutation', 'Mr.');
                simulateUserInput(element, 'firstName', 'John');
                simulateUserInput(element, 'middleName', 'B');
                simulateUserInput(element, 'lastName', 'Doe');
                simulateUserInput(element, 'email', 'doe@example.com');
                simulateUserSelect(element, 'leadStatus', 'New');
                simulateUserSelect(element, 'leadSource', 'Referral');
                simulateUserInput(element, 'budget', '100');

                const rowSelectionHandler = jest.fn();
                element.addEventListener('rowSelect', rowSelectionHandler);
                dataTable.getSelectedRows = jest.fn().mockImplementation(() => [testProductRecords[0]]);
                dataTable.dispatchEvent(new CustomEvent('rowselection'));
                expect(rowSelectionHandler).toHaveBeenCalled();

                flushPromises().then(() => {
                    const saveButton = element.shadowRoot.querySelector('lightning-button[data-element-id="save"]');
                    saveButton.click();

                    flushPromises().then(() => {
                        const calculatedInputs = element.shadowRoot.querySelectorAll('lightning-input');
                        expect(calculatedInputs.length).toBe(0);
                        done();
                    });
                });
            });
        });
expect(rowSelectionHandler).toHaveBeenCalled();  fails.

I do know that the datatable with data is in the dom based on the earlier expects.  

Would appreciate any help.  Thanks.

 
I have a nightly Apex batch that is rather simple in my mind. For whatever reason, I am getting errors now several weeks after being implemented I would have thought been caught by now.  

The error I'm getting is "TRANSFER_REQUIRES_READ, The new owner must have read permission."  This error itself isn't a concern.  It makes complete sense.  

Basically the batch job is looking for records where the owners of ObjectA__c and ObjectB__c are different.  If they are, update ObjectA__c's Owner to ObjectB__c's.  The error being raised is a result of ObjectB__c's owner no longer being active within SFDC.

Looking at the records for the Users, ObjectA and ObjectB, I am finding no modifications in the past 24 hours that would have hit the criteria of the SOQL query.  Some of the records haven't been touched in several months.  This leads me to think that the formula field sometimes isn't being calculated during batch runs.  Has anyone seen this type of thing before?

SOQL

SELECT id, OwnerId, ObjectB__r.OwnerId FROM ObjectA__c WHERE
Ownership_Same__c = FALSE AND RecordType = Type1 AND ObjectB__c != NULL

Formula Field
Ownership_Same__c
If(OwnerId = ObjectB__r.OwnerId, TRUE, FALSE)
Transitioning a charity from its previous payment processor to PayPal.  Donor transactions work perfectly fine.  For clarity, the donation transactions do not touch Salesforce.  I'm utilizing PayPal’s Instant Payment Notification service to populate Salesforce.

I have created and set up an Apex class I’ve called IPNHandler to respond to incoming IPN calls to a configured site which allows for anonymous authentication, since IPN doesn’t have a way to configure authentication to your IPN listener (AKA Apex Class).  The class basically responds to the incoming call, validates it with PayPal and should create a custom object record with the IPN message to be processed later using flows.

In PayPal, I can see that the messages are being successfully sent to Salesforce and validated.  On the Salesforce side however, the custom object is not being populated.  (Yes, for the guest profile being used by the site, I have given read/create access to the custom object and enabled Apex Class access to the IPNHandler class.)

Furthermore, I have set up debug logging for the class both through the Developer Console and the Setup Menu, but no logs are being created even though I am simulating donations which get queued up and then sent through the IPN service.  So obviously PayPal's IPN service is reaching out to Salesforce and recieving the required response which could only have happen if the Apex call was successful.

Does anyone have any thoughts?
I have inline editing available for a lightning datatable.  I realized today that if you touch a cell but don't input any data, the update will fail with the message, "Value provided is invalid for action parameter 'target' of type 'LIST'".

Data being submitted.  The bold/italized is the cell that was touch but no data was entered.
{hct: "", Id: "blahblahblah"}

Thanks.
 
So due to business requirements, I'm using a wrapper to sum daily target data into a single "record" displayed in a lightning:datatable in an aura component.   Those summarized records are editable and when saved were divided by seven for the week.  

Now the start of the "week" is changeable.  In other words some weeks can be seven days long, others can be five depending on the start date.  I'm able to get things working fine, creation of new records, extra except for the division part when updating previous records.  

Essentially using the "Power of One," I'm summing up the number of days in the "weekly record" and displaying it in the consolidated view for users.  I would like to pass that number back to SFDC so the updated values are divided by that summed "Power of One" value.  

Hoping some one can help me figure out how to force the component to return the sum even though it hasn't changed, kind of like the ID value.   If that value is rreturned, I don't have to do a SOQL query to find the number of daily records for the various "weekly" records.

Thanks.
Use case - Field is updated on opportunity, select contactid and role associated to opportunity via opportunitycontactrole, then update related fields on the various contact records.

I am having issues getting the relationship between objects correct. 

I am looping through an opportunity list based on the ID.
In the loop I'm pulling all the contact IDs and roles from the OpportunityContactRole base related to said ID.

After that I'm trying to update the contact record based on the contact record id, but I cant get the relationship between the contact ID and opporuntitycontactrole object's contactID to associate.  Any ideas?

Appreciate the help.
Thanks!