****FREE LWC COURSE VOUCHER***** Are you someone or do you know someone who recently appeared for a Salesforce Developer interview at Google/Amazon/Uber/Salesforce or any major product company? Then reach out to me at *sfdcfacts@**gmail.com* to share your interview experience and get access to LWC udemy course for FREE!!!!!
Crazy thing is this can all be accomplished in a much more efficient manner with a few additions to the data model and a simple workflow (or few lines of trigger code if you must). I understand this is a coding interview, but I find far too often Salesforce developers(and developers in general) immediately start with over-engineered coding implementations as opposed spending some time thinking about the problem, and implementing a more simplistic elegant solution. I think an important follow up question may be "would you be able to implement this without code, and what are the pros and cons of each?" which will definitely give you some insight into how the developer approaches problems.
This problem has a very simple mathematical solution. Instead of retrieving all patients for an area just keep adding the number of cases to a custom field on the area. Than calculate the weighted average each time just with the trigger context - without doing any additional SOQL queries.
Are the interview questions related to salesforce object model like shown in the video or could the coding interview questions be related to something from HackerRank or Leetcode google interview questions?
You can create formula field to get days between created date and cure date and then you can use aggregate query :) No need to iterate on trigger new much time you are consuming unnecessary space Awesome video (y)
Just to reply everyone on this thread, this was a coding interview and follows similar pattern of how product companies take interviews. The objective of these interview is to check your coding abilities and your knowledge of data structures and algorithms, hence you are not allowed to make config level changes. But that’s not all, we have discussed this approach as well in the end of part 2 video of this interview. Happy learning!!
Thanks for sharing this type of conversation in an interview (mock interview). There are lots of video for salesforce related topics. But hardly we get few like this to get idea about interview process for experienced . Thank you so much.
I think group by rollup would do the purpose in trigger after update context, writing so much logic is fine but I think using queries capabilities will simplify. above solution works only when it was built in the starting but later if already had so much data/patients in the area...considering the volume...above solution will not work. we have to use either queries capability or async queries/batch- this is also an example of non-real time processing, need not to be real time.
Just a quick thought instead of using the Map mapAreaToCuredAverage = new Map(); and Map mapAreaToCount = new Map(); Why not create a single map Map mapAreaToCuredAverage = new Map(); and doing so will help to add the diffStateChange value along with no. of patients associated with a particular area. In the end we can get the avg time to cure by simply adding the (values in the list of Integers / size of that list) It would save using another map and the other Iterations done!. Let me know if I missed anything here.
I think this can be solved very easily. A trigger on the Patient object to update the cured Days or fatal Days whenever the state change happens. Then on the Area object, we would require four Roll-up summary fields, one for total CuredDays, one for total fatalDays, one for the number of cured patients, and one for the number of fatal patients. Then we can create two formula fields to calculate the average fatality rate and average days to recover. Again for this to work we need a master-detail field for this. Like if this solution works.
Formula fields that include date values are forbidden for the roll up summary fields. The optimal solution would be to create formula fields to calculate no of days to cure and no of days to fatality and use aggregate soql query like Manish said: may be something like this Fields on patient__c object: NoDaysToCure__c, NoOfDaysToFatality__c List agr = [select Area__c, avg(NoOfDaysToFatality__c), avg(NoDaysToCure__c) from patient__c group by Area__c ];
Nice video Manish.. Keep it up. One request from my side, if you can make a kind of tutorial video on how to measure complexity of code, it would be really great.
Nice approach .First thought after avg problem ,I was thinking of using sub query but time complexity O(n2) . optimum solutions at end are very nice keep good work going 👌
Nice work.. just a thought as you mentioned about custom field. Instead of lookup will create master detail relationship and roll up the formula field. Secondly, if area having more patients like 20000 it may lead to lookup skew issue I guess.
****FREE LWC COURSE VOUCHER*****
Are you someone or do you know someone who recently appeared for a Salesforce Developer interview at Google/Amazon/Uber/Salesforce or any major product company?
Then reach out to me at *sfdcfacts@**gmail.com* to share your interview experience and get access to LWC udemy course for FREE!!!!!
Crazy thing is this can all be accomplished in a much more efficient manner with a few additions to the data model and a simple workflow (or few lines of trigger code if you must). I understand this is a coding interview, but I find far too often Salesforce developers(and developers in general) immediately start with over-engineered coding implementations as opposed spending some time thinking about the problem, and implementing a more simplistic elegant solution. I think an important follow up question may be "would you be able to implement this without code, and what are the pros and cons of each?" which will definitely give you some insight into how the developer approaches problems.
Is there any video explaining the DSA roung at google for salesforce developers ? how hard the questions are?
This problem has a very simple mathematical solution. Instead of retrieving all patients for an area just keep adding the number of cases to a custom field on the area. Than calculate the weighted average each time just with the trigger context - without doing any additional SOQL queries.
Why exactly can't we use Batchable and Future and we stuck to using Queueable?
Can someone explain?
Are the interview questions related to salesforce object model like shown in the video or could the coding interview questions be related to something from HackerRank or Leetcode google interview questions?
Hey Manish, Can you please suggest what are the limitations in aggregate query that you were discussing?
You can create formula field to get days between created date and cure date and then you can use aggregate query :) No need to iterate on trigger new much time you are consuming unnecessary space Awesome video (y)
This way is much better than what they are doing.
Exactly, I was also thinking the same way. Not sure why Ranjan did not go that way.
Just to reply everyone on this thread, this was a coding interview and follows similar pattern of how product companies take interviews. The objective of these interview is to check your coding abilities and your knowledge of data structures and algorithms, hence you are not allowed to make config level changes.
But that’s not all, we have discussed this approach as well in the end of part 2 video of this interview.
Happy learning!!
34:00 are we allowed to use formula fields on aggregate queries?
Thanks for sharing this type of conversation in an interview (mock interview). There are lots of video for salesforce related topics. But hardly we get few like this to get idea about interview process for experienced . Thank you so much.
Glad it was helpful!
I think group by rollup would do the purpose in trigger after update context, writing so much logic is fine but I think using queries capabilities will simplify. above solution works only when it was built in the starting but later if already had so much data/patients in the area...considering the volume...above solution will not work. we have to use either queries capability or async queries/batch- this is also an example of non-real time processing, need not to be real time.
No configuration is allowed, specially the rollup summary, that's the whole point of a coding interview (to test your coding abilities)
Ranjan directly subtract date..it won't work..we have to use daysbetween() method to calculate days...apart from that 👍
Good Work @SFDCFacts, Please keep posting these kind of videos.
Can it be done without trigger?
By flows we can do
Just a quick thought instead of using the Map mapAreaToCuredAverage = new Map(); and Map mapAreaToCount = new Map();
Why not create a single map
Map mapAreaToCuredAverage = new Map();
and doing so will help to add the diffStateChange value along with no. of patients associated with a particular area.
In the end we can get the avg time to cure by simply adding the (values in the list of Integers / size of that list)
It would save using another map and the other Iterations done!.
Let me know if I missed anything here.
and what will be the time complexity?
I think this can be solved very easily. A trigger on the Patient object to update the cured Days or fatal Days whenever the state change happens. Then on the Area object, we would require four Roll-up summary fields, one for total CuredDays, one for total fatalDays, one for the number of cured patients, and one for the number of fatal patients. Then we can create two formula fields to calculate the average fatality rate and average days to recover. Again for this to work we need a master-detail field for this.
Like if this solution works.
He said lookup so that he wants to avoid Summary fields as solution but that should be a question to the interview that why not master detail field.
Amazing Video format watched many SFDC videos but this is very interactive and thorough.
formula field on child and roll-up summary on parent would be the best approach.
Formula fields that include date values are forbidden for the roll up summary fields. The optimal solution would be to create formula fields to calculate no of days to cure and no of days to fatality and use aggregate soql query like Manish said: may be something like this
Fields on patient__c object:
NoDaysToCure__c, NoOfDaysToFatality__c
List agr = [select Area__c, avg(NoOfDaysToFatality__c), avg(NoDaysToCure__c) from patient__c group by Area__c ];
Awesome Explanation Bro....
Good work Manish! 👍🏻👍🏻
Calling multiple times would end up with query limit.feature we can't pass other than primary parameters.
Nice video Manish.. Keep it up.
One request from my side, if you can make a kind of tutorial video on how to measure complexity of code, it would be really great.
nice explanation but why this can not be managed by Batch.
We have discussed this at the end of part 2 of this interview.
@@SFDCFacts - it can be done using the aggregate result for average.
Nice approach .First thought after avg problem ,I was thinking of using sub query but time complexity O(n2) . optimum solutions at end are very nice keep good work going 👌
Nice glasses Manish 👍
Nice work.. just a thought as you mentioned about custom field. Instead of lookup will create master detail relationship and roll up the formula field. Secondly, if area having more patients like 20000 it may lead to lookup skew issue I guess.
Amazing content. Kindly make a video explaining how to measure complexity of the code.