• anketha
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 3
    Replies
Hi All,

I want to refresh a lightning component for every second, so I'm trying the below code which will call my apex class which is retrieved in the component for evry second. But somehow it doesn't work and i get an error.

window.setInterval(
   $A.getCallback(function() {                      helper.DisplayBusinessHoursForOpenCases(component,helper);
  }), 1000 ); 

I get an error that Uncaught Error in $A.getCallback() [Cannot read property 'DisplayBusinessHoursForOpenCases' of undefined].
I have tried using this.DisplayBusinessHoursForOpenCases, but that doesn't work either.

But the below links show the same example, but this doesn't work in my case.

http://www.infallibletechie.com/2018/04/agetcallback-usage-for-polling-in.html
https://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/

Can anyone please help.

Regards,
Anketha
Hi,

I have the following code:

public static string getBusinessHours(ID CaseId){
        string TimeDiff;
        BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
        Case c = [Select id,CreatedDate from case where id=:CaseId];
        
        Datetime CurrentDateTime = System.now();
        Datetime CreatedDateTime = c.CreatedDate ;
        //Datetime ClosedDateTime = ncs[i].ClosedDate ; 
        //Datetime ClosedDateTime =ncs[i].LastModifiedDate;
    
        Decimal diffHours = BusinessHours.diff(bh.ID,CreatedDateTime,CurrentDateTime);
Decimal days= (diffHours/86400000).round();  // converting milliseconds into days
Decimal hours = (diffHours/3600000).round();  // converting milliseconds into Hours
        Decimal minutes = (diffHours/60000).round();  // converting milliseconds into minutes
        Decimal seconds = (diffHours/1000).round();  // converting milliseconds into seconds
        
        TimeDiff = hours + ':' + minutes + ':' + seconds;
             
        return TimeDiff;
    }

This will return the days:hours:mins:seconds. But if the created date is 25/9/2018, the result is 80:1922:115331:6919867
But I want it to be displayed as 80 days and number of minutes after those many hours and seconds after those many minutes.
I don't want the total number of hours, minutes and seconds from the created date.

Can anyone please help on this?

Regards,
Anketha
Hi,

Even though I have set the trace logs for another user, I can't see any logs being generated.
I have created Transaction security policies for data export for Account object when Account data of more than 10 records are being extracted. An apex class is being written for this.

So, when I extract Account data, I see logs in my user, but I don't see any logs for the other user, whom I have set the trace logs. I have also disabled the checkbox - 'View my current logs only' in developer console.

Any help will be appreciated.

Regards,
Anketha
I'm trying to pass a parameter which is an account field to a soql query(which is just calculating the count on this custom object based on the account field). And I'm trying to retrieve this count value from the controller to the js file. And from the js file to the HTML Page.

But the challenge here is that all the documentation on this shows examples on a list of Sobjects. And even though this can be done on a single sObject through getSobjectValue, this method doesn't work by passing any parameter.
Below is my code and explanation of what I'm trying to do--

public class LWLeaseCountExtensionsController { @AuraEnabled(cacheable=true)
public static List<Account> getAccount(String AccId) {
return [SELECT Id,LeaseWaveID__c, LW_Customer_ID__c, LW_Fleet_ID__c, LW_Account_ID__c, LW_SubAccount_ID__c from Account where Id=:AccId Limit 1]; }

@AuraEnabled() public integer lc;

/*This was the original code that I tried first, but since it didn't work with a return type of Integer, I commented out the below method and created the next method which take a list of Integer as return type */ @AuraEnabled(cacheable=true)
public static Integer getLeaseCount(string LeaseWaveID) {
Integer lc = !string.isblank(LeaseWaveID) ? [SELECT COUNT() FROM DW_oData_vw_sf_Units__x WHERE Lease__c = TRUE AND LeasewaveId__c =:LeaseWaveID] : -1;

@AuraEnabled(cacheable=true)
public static List<Integer> getLeaseCount(string LeaseWaveID) { List<integer> lc;
Integer i;
if(LeaseWaveID!=null)
       i=[SELECT COUNT() FROM DW_oData_vw_sf_Units__x         WHERE Lease__c = TRUE AND LeasewaveId__c =:LeaseWaveID];
else
      i=-1;
lc.add(i);
system.debug('leaseWaveID1--'+lc);
return lc;
}
}

js file --
import { LightningElement,api,wire,track } from 'lwc';
//import { getSObjectValue } from '@salesforce/apex';
import getAccount from '@salesforce/apex/LWLeaseCountExtensionsController.getAccount'; import Account_LeaseWaveId from '@salesforce/schema/Account.LeaseWaveID__c';
import getLeaseCount from '@salesforce/apex/LWLeaseCountExtensionsController.getLeaseCount';

export default class TestLWLeaseCountwebComponent extends LightningElement {
@api recordId;
@track getLeaseCount;
@api totalLC;

@wire(getAccount,{AccId:'$recordId' })
accounts;

@wire(getLeaseCount, { LeaseWaveID: Account_LeaseWaveId}) odata;

totalLC = JSON.stringify(this.lc); }


Current HTML File which doesn't work --
<template>
    <lightning-card title="LWCount" icon-name="custom:custom63">
         <div class="boarder">
              <!-- <p class=”slds-m-bottom_small”>
                          <lightning-button label=”LoadContacts” onclick= {handleLoad}></lightning-button>
                </p> -->

        <template if:true={accounts.data}>
             {LeaseWaveID} </template>
             {totalLC}

          <template if:true={odata.data}></template>
       </div>
    </lightning-card>
</template>

When I set the debug Logs to check if the method getLeaseCount is getting called when the Account page(which has this component) loads, this method is not getting called. Only the getAccount method gets called and the value is being retrieved.

The below HTML Works--
<template>
   <div class="boarder">
      <template if:true={accounts.data}>
          <ui>
              <template for:each={accounts.data} for:item="acc">
                 <li key={acc.Id}>{acc.LeaseWaveID__c}</li>
              </template>
            </ui>
          </template>
      </div>
</template>

Though the above HTML Works and displays an account field value, that doesn't serve my purpose as I want the count() of the custom object to be displayed through the html and I can't figure out a way to display the count.

Can anyone please help me with this. I'm referring to the section (Update code to pass record Id to Apex controller ) in the below documentation : 
https://rajvakati.com/2018/12/29/get-record-id-into-lightning-web-components

Regards,
Anketha
Hi,

When I run the below test class, I receive flow related error:

Method in the class:
static testMethod void rqiTest(){
        DW_oData_vw_sf_Units__x mockedRequest = new DW_oData_vw_sf_Units__x(fuel__c=true,VIN__c='ABC123');   
        ExternalQueryHandler.mockedObject.add(mockedRequest);
        Date d=date.today()+2;
        RecordType RemarketingRTid = [Select id from RecordType where SobjectType='Account' and Name='Remarketing Venue'];
        RecordType OppRTid = [Select id from RecordType where SobjectType='Opportunity' and name='FMS - Standard'];
        
        Account a= NEW Account(Name='Test', Phone='12345678',RecordTypeId=RemarketingRTid.id);
        insert a;
        Contact c = NEW Contact(FirstName='test',LastName='Last',AccountId=a.id);
        insert c;      
        
        Opportunity o= NEW Opportunity(Name='Test',AccountId=a.id,Type='Renewal',CloseDate=d,StageName='Proposal Presented',RecordTypeId=OppRTid.id);
        insert o;
       
        Remarketing_Quote__c rq = NEW Remarketing_Quote__c(Name='Test rq',Sales_Contact__c=c.id,Status__c='Opened',Account__c=a.id,Opportunity__c=o.id);
        insert rq;
        Remarketing_Quote_Item__c rqi = NEW Remarketing_Quote_Item__c(Remarketing_Quote__c=rq.id,fuel__c=false,VIN__c='ABC123',Status__c='Opened',Remarketing_Venue__c=a.id);
        insert rqi;
        
        LIST<Async_Request__c> newAR = NEW LIST<Async_Request__c>();        
        LIST<String> fields = NEW LIST<String>{'ID','VIN__c','OWNER__c','Lease__c','Fuel__c','Telematics__c','Maintenance__c'};
        String whereClause = 'WHERE VIN__c = \'ABC123\'';
        String ordering;
        integer lim;
            
        Test.startTest();
            LIST<DW_oData_vw_sf_Units__x> request = ExternalQueryHandler.runQuery(fields,'DW_oData_vw_sf_Units__x',whereClause,ordering,lim);
            newAR.add(NEW Async_Request__c(Request_Type__c='RQIUnitLookup',Params__c = rqi.id));
            insert newAR;
        test.stopTest();
    }

Error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Remarketing Quote” process failed. Give your Salesforce admin these details. <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow.  Please contact your system administrator for more information.: []

The error is in the line where the record of the object -  Remarketing_Quote_Item__c is being created. There is a process builder that gets initiated on this object's insert. And in step 4 of this process builder a flow gets initiated, where the remarketing Quote is mapped to opportunity object and an opportunity line item gets created.

When I searched the logs, I see that the flow error is due to the error -
This error occurred when the flow tried to create records: FIELD_INTEGRITY_EXCEPTION: field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id).

So, according to this error, pricebookEntry records have been created in the flow, but I still receive this error. And If I add the pricebookEntry records in the class, I receive a different error. Please help to figure out the exact issue.

Thanks,
Anketha
When I'm trying to follow the trailhead to create Lightning web component, I'm stuck at step 2.

In the 1st course, we have to install Salesforce CLI and VS Studio tools which is done.

In the 2nd course, where a new project has to be added is also done. But after that, when I try to Authorize an org or setup a default org, it gives me the below error:

Starting SFDX: Authorize an Org
16:19:16.79 sfdx force:auth:web:login --setalias MyDevOrg --instanceurl https://test.salesforce.com --setdefaultusername
ERROR running force:auth:web:login: Cannot start the OAuth redirect server on port PortInUseAction.
Try this:
Kill the process running on port 7717 or use a custom connected app and update OauthLocalPort in the sfdx-project.json file.
16:21:02.884 sfdx force:auth:web:login --setalias MyDevOrg --instanceurl https://test.salesforce.com --setdefaultusername ended with exit code 1

I have tried to  search the process with the port number - 7717 and tried to kill that process, but that doesn't work either.

Any help on this will be appreciated.

Thanks!

There are some jobs scheduled for this weekend and there is downtime on 7th at 7 pm(PST). Can I know what is the impact of downtime on these apex jobs? Will these apex jobs be restarted on their own after downtime or should i restart?

Hi,

  I have included some input fields which includes name input field and a command button in a visualforce page...when i click on this command button ,it wil navigate to another page..I want the name entered in the input field in the first page to be displayed in the second page after clicking on the command button.how can this be done through a param tag.?

How can I add a stylesheet using visualforce in a apex page? I tried adding stylesheet through $Resource...But I'm not able to add the stylesheet to the apex page.Please help.

Hi All,

I want to refresh a lightning component for every second, so I'm trying the below code which will call my apex class which is retrieved in the component for evry second. But somehow it doesn't work and i get an error.

window.setInterval(
   $A.getCallback(function() {                      helper.DisplayBusinessHoursForOpenCases(component,helper);
  }), 1000 ); 

I get an error that Uncaught Error in $A.getCallback() [Cannot read property 'DisplayBusinessHoursForOpenCases' of undefined].
I have tried using this.DisplayBusinessHoursForOpenCases, but that doesn't work either.

But the below links show the same example, but this doesn't work in my case.

http://www.infallibletechie.com/2018/04/agetcallback-usage-for-polling-in.html
https://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/

Can anyone please help.

Regards,
Anketha
Hi,

I have the following code:

public static string getBusinessHours(ID CaseId){
        string TimeDiff;
        BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
        Case c = [Select id,CreatedDate from case where id=:CaseId];
        
        Datetime CurrentDateTime = System.now();
        Datetime CreatedDateTime = c.CreatedDate ;
        //Datetime ClosedDateTime = ncs[i].ClosedDate ; 
        //Datetime ClosedDateTime =ncs[i].LastModifiedDate;
    
        Decimal diffHours = BusinessHours.diff(bh.ID,CreatedDateTime,CurrentDateTime);
Decimal days= (diffHours/86400000).round();  // converting milliseconds into days
Decimal hours = (diffHours/3600000).round();  // converting milliseconds into Hours
        Decimal minutes = (diffHours/60000).round();  // converting milliseconds into minutes
        Decimal seconds = (diffHours/1000).round();  // converting milliseconds into seconds
        
        TimeDiff = hours + ':' + minutes + ':' + seconds;
             
        return TimeDiff;
    }

This will return the days:hours:mins:seconds. But if the created date is 25/9/2018, the result is 80:1922:115331:6919867
But I want it to be displayed as 80 days and number of minutes after those many hours and seconds after those many minutes.
I don't want the total number of hours, minutes and seconds from the created date.

Can anyone please help on this?

Regards,
Anketha

How can I add a stylesheet using visualforce in a apex page? I tried adding stylesheet through $Resource...But I'm not able to add the stylesheet to the apex page.Please help.