This question runs in a pre-configured Salesforce environment - no personal connection required.
Transfer all Contacts from a source Account to a target Account by updating the AccountId field. Return the number of Contacts that were successfully transferred.
Return 0 if the source Account has no Contacts. Return null if either the sourceAccountId or targetAccountId is null.
Examples:
Input: sourceAccountId = '001XXXXXXXXXX', targetAccountId = '001YYYYYYYYYY'
Output: 5
Explanation: The source Account had 5 Contacts, all were transferred to the target Account
Input: sourceAccountId = '001XXXXXXXXXX', targetAccountId = '001YYYYYYYYYY'
Output: 0
Explanation: The source Account has no Contacts, so 0 Contacts were transferred
Input: sourceAccountId = null, targetAccountId = '001YYYYYYYYYY'
Output: null
Explanation: Source Account ID is null, return null
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.