DAY Spent in hospital with Salesforce Community Groups

Today, when I woke up , got call from my friend. He said ,If you don't have any work , can you come to Hospital with Me ?..

I was about start my preparation as I do regularly,but couldn't deny his request. Left everything behind and went to hospital at 12PM.Doctors put him a saline for 3 hours and I had to wait for that longer outside the room.

Then ,How do i spend 3 hours? There comes our Salesforce Community groups.. someone was asking about trigger and scenario based question that every Aspiring Salesforce developer must know .

trigger :Requirement :Cascade delete through Apex Code with Condition Applied.

Whenever we delete Account ,related Contacts must be deleted and related Contact must be Primary contact (isPrimary checkbox =True)

No alt text provided for this image

Custom Field on Standard Object :

In conversation he said "IsPrimary " is custom checkbox on Contact, I have gone through his code,he didn't append suffix '__c' to Custom field .(1st correction )

Soql query :

  • He was using SOQL query to fetch Primary Contacts .[SELECT id,isPrimary FROM Contact where Id IN:setid];
  • "setid" is a Set-Collection to hold Account records and same is Used in Query .In Where clause ,instead of id he must use AccountID which is Comman between Account and Contact Object.
  • So Query shall be changed to [SELECT id,isPrimary ,AccountID,FROM Contact where AccountID IN:setid];(2nd Correction)

For Loop Inside For Loop:

  • His approach was, for each Account he is using one more for Loop to check the Primary Contacts . If Primary then delete the Contact .
  • It's good to use MAP collection if we are Performing relative Comparison ,We can avoid for Loop Inside For Loop. (3rd Suggestion).But actually for Requirement ,relative Comparison is not necessary here.

Again he posted other code of trigger.

No alt text provided for this image

KEY TAKE AWAY FROM TODAY

  • we can take help of Salesforce Community to learn and give back in way where others can learn also ..
  • This blog is writtinh n mobile only .
  • I have Started to write this blog from 3Pm , my friend got discharged at 5.30 and I have completed this blog now and posting .
  • Anything on cloud .

要查看或添加评论,请登录

Mahesh Yallur的更多文章

社区洞察

其他会员也浏览了