Task for Apex Developer Job Interview: SObject records field values swap

Illia Leshchuk
1 min readMar 17, 2023

A small task for Apex Developer Job Interviews which requires Apex-specific knowledge, shouldn’t take much time and can give you an impression about applicant skills.

Assuming we have two Opportunity records and we need to swap their “Close Date” field values. The task is to do it w/o introducing any additional variables:

Opportunity opportunityA = new Opportunity(CloseDate = System.today());
Opportunity opportunityB = new Opportunity(CloseDate = System.today().addDays(10));

//magic goes here

System.debug(opportunityA.CloseDate);//today + 10 days
System.debug(opportunityB.CloseDate);//today

What we’re trying to get in response is for applicant to leverage SObject.put method’s return value, so that result will look like this:

Opportunity opportunityA = new Opportunity(CloseDate = System.today());
Opportunity opportunityB = new Opportunity(CloseDate = System.today().addDays(10));

opportunityA.put(Opportunity.CloseDate, opportunityB.put(Opportunity.CloseDate, opportunityA.CloseDate));

System.debug(opportunityA.CloseDate);//today + 10 days
System.debug(opportunityB.CloseDate);//today

Initial requirements narrowed down to an Opportunity SObject and “Close Date” field on purpose — so that not to give applicant a hint to look into generic SObject methods right away and test their ability to see a bigger picture and think outside the box themselves.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Illia Leshchuk
Illia Leshchuk

Written by Illia Leshchuk

A salesforce developer/architect

No responses yet

Write a response