Hi Salesforce Bolt, Could you please help me. A question was asked in my interview today, the question is How do we fetch all accounts that have at least one or more contacts and we have to show fields like account name, last modified contact name related to account and in the org we have millions of accounts and contacts. And data have to show in datatable in LWC.
@raghavendrasharma2466, It was a good Question!! You can't do this in apex class unless you are using Batch Apex. Salesforce don't allow to compare LastModifiedDate > CreateDate, but there is a workaround , Create a Formula field in Contact Object ie, IsLastModifiedRecord__c and add the comparision 'LastModifiedDate > CreatedDate' and then soql use as follows List accWithLastModifiedContacts = new List(); List accounts = [ SELECT Id,Name,(select Id from Contacts where IsLastModifiedRecord__c = true) FROM Account]; for(Account a : accounts){ List contacts = a.Contacts; if(contacts.size() > 0){ System.debug(contacts.size()); accWithLastModifiedContacts.add(a); } } since you are query million records it must be happen in the BatchApex class only. Since you should use on LWC pagination should be implemented.
Hi Salesforce Bolt,
Could you please help me. A question was asked in my interview today, the question is
How do we fetch all accounts that have at least one or more contacts and we have to show fields like account name, last modified contact name related to account and in the org we have millions of accounts and contacts. And data have to show in datatable in LWC.
@raghavendrasharma2466, It was a good Question!! You can't do this in apex class unless you are using Batch Apex. Salesforce don't allow to compare LastModifiedDate > CreateDate, but there is a workaround , Create a Formula field in Contact Object ie, IsLastModifiedRecord__c and add the comparision 'LastModifiedDate > CreatedDate' and then soql use as follows
List accWithLastModifiedContacts = new List();
List accounts = [ SELECT Id,Name,(select Id from Contacts where IsLastModifiedRecord__c = true) FROM Account];
for(Account a : accounts){
List contacts = a.Contacts;
if(contacts.size() > 0){
System.debug(contacts.size());
accWithLastModifiedContacts.add(a);
}
}
since you are query million records it must be happen in the BatchApex class only. Since you should use on LWC pagination should be implemented.
Hi, Is it possible to redirect to a record from the toast?
Yes in hyperlink you can give url of the record.
Sir, can we show only taost message instead of loading the component, just like a validation rule.
Unfortunately no, it has to be inside a component.