Salesforce coding lessons for the 99%
Finally, Apex tutorials for point-and-click admins! Written by a self-taught Google engineer.
  • Beginner Tutorials
    • Apex
    • Certifications
    • Career Info
    • Technical Architect
    • Visualforce
    • Videos
  • Apex Academy
  • Success Stories
  • About Me
  • Misc
    • Mailbag
    • Challenges
    • Links
    • Login to my Org
Follow @dvdkliuor SUBSCRIBE!

Coding Challenges!

September 17, 2014

Want to see how your learning is coming along? Give these challenges a shot!

# Challenge Difficulty Recommended Reading
1 Lazy Employee Beginner Chapter 1
2 Account Rivals Advanced Chapter 5
3 Opportunity Renewal Intermediate Chapter 6
4 Extravagant Record Creation Advanced Chapter 7
5 Custom Sales Territory Management Advanced Everything!

If you have any hesitation within you, I recommend a nice cold beer (or two). Always works for me!

Not having too much difficulty solving these challenges? Start applying for Salesforce developer jobs!
…and once you get the job, find me and tell me your story!

David

27 Comments
sharan
June 26, 2020 @ 6:05 am

challenege to be solved in apex

can anyone solve this problem

Create a master list of facility having the conference room with facilities available for different locations of an office.

Request for a meeting room by selecting meeting room, meeting time slot, date/time.

Compare the above mentioned values and status as “Room booked” or “Meeting Room Not Available for Booking/Slot rejected” on display.

Option should be available for Reservation against cancellation.

Reply
Vatsal
October 8, 2019 @ 6:06 pm

Hi David,

Can you post some more challenge questions or provide a source for the same?

Like some scenarios for apex coding practices as well as apex trigger practices.

Reply
    David Liu
    October 8, 2019 @ 7:52 pm

    Check out bit.ly/go-apex

    Reply
Sagar D
November 17, 2018 @ 4:39 pm

// Automatically create a Renewal Opp for closed won deals
trigger CreateRenewal on Opportunity (before update) {

// Create a Map to store all renewal opps for bulk inserting
List renewals = new List();
Opportunity renewal;
Opportunity oldOpp;

//Get Renewal Record Type ID
Id RenewalRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get(‘Renewal’).getRecordTypeId();

for (Opportunity opp : Trigger.new) {

//Check if the current opportunity was not ‘closed won’
oldOpp = Trigger.oldMap.get(opp.Id);
Boolean oldOppIsWon = oldOpp.StageName.equals(‘Closed Won’);

// Only create renewal opps for closed won deals and were previously not ‘closed won’
if (opp.StageName == ‘Closed Won’ && !oldOppIsWon) {
renewal = new Opportunity();
renewal.AccountId = opp.AccountId;
renewal.Name = opp.Name + ‘(Renewal)’;
renewal.CloseDate = opp.CloseDate + 365;//add a year
renewal.StageName = ‘Open’;
renewal.RecordTypeId = RenewalRecordTypeId;
renewal.OwnerId = opp.OwnerId;
//Add Opportunity to list
renewals.add(renewal);
}
}
// Bulk insert all renewals to avoid Governor Limits
insert renewals;
}

Reply
Manu Mangal
October 29, 2017 @ 9:32 am

trigger caseLimit on Case (before insert,before update,after undelete) {
map<Id,list> ownerIdtocases = new map<Id,list>();
set ownerIdSet = new set();
for(case c:trigger.new){
ownerIdSet.add(c.OwnerId);
if(ownerIdtocases.containsKey(c.OwnerId)){
ownerIdtocases.get(c.OwnerId).add(c);
}
else{
ownerIdtocases.put(c.OwnerId,new list{c});
}
}
for(case c:[SELECT ownerId,CreatedDate
FROM case
WHERE createdDate = THIS_MONTH
AND OwnerId IN:ownerIdSet]){
if(ownerIdtocases.containsKey(c.OwnerId)){
ownerIdtocases.get(c.OwnerId).add(c);
}
else{
ownerIdtocases.put(c.OwnerId,new list{c});
}
}
ownerIdSet.clear();
for(list c:ownerIdtocases.values()){
if(c.size()>99)
ownerIdSet.add(c.get(0).OwnerId);
}
for(case c:trigger.new){
if(ownerIdSet.contains(c.OwnerId)){
c.addError(‘Too many cases created this month for user’+ c.OwnerId);
}
}
}

Reply
    venkatesh
    January 29, 2018 @ 9:47 pm

    wonder

    Reply
Apex Learner
May 22, 2017 @ 1:08 pm

This is just a request that wouldn’t it be great if you keep coming with few (2 to 3 only) trigger questions/Challenges per week and just post the question here on sfdc99? It will help us to brush up our all skills that we have learned in 3 courses so far.
Thank you sir & I appreciate your time reading comments here, Thank You!

Reply
    David Liu
    May 22, 2017 @ 9:19 pm

    That is a FANTASTIC idea!

    Reply
      Apex Learner
      May 23, 2017 @ 7:22 am

      Thanks for replay..
      And Of course, the difficulty level can increase as we move further in challenges!
      I am looking forward then David!
      now it’s like…. can’t go to sleep if I don”t write some lines of code :) I am not kidding;)

      Reply
        David Liu
        May 23, 2017 @ 9:42 pm

        Great attitude!!

        Reply
          Apex Learner
          June 1, 2017 @ 7:25 am

          So David when do we expect to see you putting some extra challenges for us to work on and brush up our skills we learned so far? Thank you for your time, as always!

          Reply
            David Liu
            June 1, 2017 @ 9:33 pm

            LOL it’s on the backlog!! It’s a BIG backlog!

            Reply
Anonymous
July 27, 2015 @ 4:55 am

Hi David

I have referred your org and came to know about iframe to be used to display youtube video in VF page. When I tried to demonstrate this with other video link (apart from what you have coded) , I found its failing. In analysis I could understand its because of the parameter it is receiving in the link.
Now my question is that if someone wish to use youtube link mentioned like below in the code , how it should be done.
https://www.youtube.com/watch?v=Vov2OsA1JII

Thanks in advance for kind help.

Regards
Sandeep

Reply
    David Liu
    July 27, 2015 @ 9:16 pm

    Check this out:
    https://www.sfdc99.com/2015/02/20/example-how-to-write-a-basic-visualforce-page/

    Reply
    Sandeep
    July 27, 2015 @ 10:41 pm

    Hi David

    I got the answer , it was my mistake , we should use embed link rather than the direct link what we come across in youtube.

    I did the changes and worked fine.

    Thanks .. thought to share .. may be useful for someone who will come across such scenario in future. :-)

    Thanks
    Sandeep

    Reply
raj
March 20, 2015 @ 3:13 am

The visual page force should contain 6 fields of Custom Object.

We should be able to enter values in those fields and those values when clicked on the Save button should save in the custom objects.

pls send code.

thanks in advance

Reply
vasanthi
March 20, 2015 @ 3:12 am

The visual page force should contain some fields of Custom Object.

We should be able to enter values in those fields and those values when clicked on the Save button should save in the custom objects.

Reply
Anonymous
March 5, 2015 @ 8:56 am

Waiting on the next chapters:-) Champion gets slow:-)

Reply
    David Liu
    March 7, 2015 @ 12:54 am

    =)

    Reply
Satic007
February 28, 2015 @ 10:31 am

Hi David and experts,

I have a situation, I want to mass update a custom object’s custom fields. I’m using list, but somehow its only updating first and last record. Please let me know, if I’m doing something wrong. Here is the code

Account[] AcctFin = [select Id, (select Id,IsLatest__c from Account_Financials__r
order by date__c desc limit 1) from Account where Number_of_Financials__c > 0 limit 5];

list lstFin = new list();

for (Account A : AcctFin){
for(Financials__c fin: A.Account_Financials__r){
lstFin.add(fin);
}
}

for(Financials__c F : lstFin){
if(F.IsLatest__c != true){
F.IsLatest__c = true;
}
}
update lstFin;

Reply
    David Liu
    February 28, 2015 @ 4:25 pm

    Try posting this one on the forums!

    Reply
An Kumar
February 4, 2015 @ 10:06 am

Hi David

I have a requirement where user can enter account details thru which he/she will receive the payment(confidential information like account details), but no one in the org can able to see that field …and that field should in in encrypted formate.

Please advise

Reply
    David Liu
    February 4, 2015 @ 10:14 pm

    Try using an encrypted field and setting sharing to private (without granting access using hierarchies)

    Reply
Jaya Koti
December 4, 2014 @ 7:30 am

Hi David,

we have used Standard set Controller for getting list views & for pagination from this link: http://www.jitendrazaa.com/blog/salesforce/listview-filter-in-apex-with-paging-and-navigation/ .

Now we need to change the pagination to somwthign like this :http://demo.redpointsolutions.com/Dynamic_Visualforce_with_SOQL_Offset

Could you please suggest some possible chances to acieve this.

Thanks,
Koti

Reply
    David Liu
    December 4, 2014 @ 9:42 pm

    It’s very close!

    You just need to code the buttons to say the current page numbers instead of the arrows. This is one more thing to track in your controller.

    Also, you need to add a few more buttons but that shouldn’t be too difficult!

    Reply
Anonymous
October 16, 2014 @ 4:43 pm

David –

Big fan here.
Are you going to post the solutions to the other Trigger problem??

Reply
    David Liu
    October 16, 2014 @ 7:59 pm

    Almost forgot about that! Yes they will come! Next post will be on Chapter 8 first though!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


*

*

Theme: Simple Style by Fimply