How To Resolve Merge Conflicts In Salesforce?

Article Written By:
Varalatchumi V
Created On:

February 7, 2025

How to resolve merge conflicts in Salesforce with Git

Salesforce merge conflicts happen when two developers change the same metadata and Git cannot combine the versions on its own. You resolve them by opening the conflicted file, reading the conflict markers Git adds, choosing or combining the correct lines, removing the markers, then committing and re-validating the deployment. Prevented well and resolved calmly, they are a routine part of team development, not a crisis.

Conflicts are more common on Salesforce than on a standard codebase because the platform is metadata-driven. When several people edit the same profile, flow, or Apex class at once, their changes can collide during a merge. This guide explains what causes Salesforce merge conflicts, walks through how to resolve them step by step, and shows how to prevent most of them from happening at all.

Here is the quick view before the detail.

Question Short Answer
What is a merge conflict? Two changes to the same lines that Git cannot merge automatically
Why do they happen on Salesforce? Metadata-driven work means many people touch the same files
How do you resolve one? Read the conflict markers, keep the correct code, remove the markers, retest
How do you prevent most of them? Small branches, frequent merges, and clear task ownership

What Causes Salesforce Merge Conflicts?

Understanding the causes is the first step to fewer conflicts. Most Salesforce merge conflicts trace back to a handful of patterns that show up in any collaborative, version-controlled project.

Metadata Overlaps

Salesforce stores its settings and customizations as metadata. When two people edit the same metadata file at the same time, their changes overlap and Git flags a conflict. Workflows, Apex classes, and page layouts are all prone to these metadata conflicts.

Declarative Versus Programmatic Changes

Salesforce supports both point-and-click configuration and code. Conflicts arise when an admin and a developer solve the same problem in different ways, one declaratively and one programmatically. Those two approaches often collide during a merge or deployment.

Sandbox Drift

Teams use multiple sandboxes for parallel work, but sandboxes drift apart over time as hotfixes land in one place and not another. When the environments are out of sync, source control conflicts during integration are almost guaranteed.

Team Collaboration Gaps

Weak coordination is one of the biggest causes of Salesforce Git merge conflicts. Without a clear process, two people unknowingly work on the same component, and thin documentation makes it worse. The table below shows the metadata types that conflict most and how to handle each.

Metadata Type Why It Conflicts How To Handle It
Profiles Large XML files many people touch Move access to permission sets; split the work
Apex classes Two developers edit the same methods Keep classes modular; merge early and often
Lightning pages and components Layout and component XML overlap Assign one owner per component
Flows and workflows Shared automation edited in parallel Coordinate changes; one flow, one editor at a time

How To Resolve Merge Conflicts In Salesforce Step By Step

When a conflict does appear, the fix is methodical, not mysterious. Git merge conflict resolution follows the same core steps everywhere, and Salesforce Git integration adds only one twist: some of the files are metadata XML rather than code. Here is how to resolve Git conflicts in Salesforce cleanly, whether the file is XML metadata or an Apex class. These steps apply to merge conflicts in Salesforce development of any size, from a two-person team to a large release train.

Step 1: Find The Conflict

When you pull or merge a branch, Git tells you which files conflict. Run a status check to list them, and note whether each is metadata such as XML, an Apex class, or a Lightning component. Knowing the file type shapes how you resolve it, so start by getting the full list before touching anything.

Step 2: Open The File And Read The Conflict Markers

Open a conflicted file and you will see the markers Git inserts. The block between the markers shows both versions: your changes sit under one marker, the incoming changes under another, and a divider separates them. Your job is to decide what the final, correct version should look like. In a Salesforce XML file, this often means one person added a field permission and another changed a page setting in the same block.

Step 3: Choose Or Combine The Correct Changes

Decide which side to keep, or blend the two if both changes belong. This is the heart of Salesforce merge conflict resolution.

  • For XML merge conflicts, keep both entries when they cover different fields or permissions, since losing one silently removes access.
  • For Apex merge conflicts, read both method versions and combine the logic rather than blindly picking one.
  • For Lightning merge conflicts, confirm the component markup still renders after you settle the overlap.

When two people simply changed the same setting to different values, talk to the other developer rather than guessing. A quick conversation prevents a wrong choice that reaches production.

Step 4: Remove The Markers And Save

Once the block reads exactly as it should, delete all three conflict markers so only clean code remains. Leaving even one marker behind breaks the file, and for XML metadata it can make the whole deployment fail. Save the file when the markers are gone and the content is correct.

How to resolve merge conflicts in Salesforce using Git conflict markers

Step 5: Test And Re-Validate

A resolved file still has to work. Deploy the change to a sandbox and run a validation deployment with the relevant Apex tests before it goes anywhere near production. This confirms your metadata merge did not drop a permission or break a test, which is where rushed resolutions usually go wrong.

Step 6: Commit And Redeploy

With the tests green, mark the conflict resolved, commit the merge, and let your pipeline promote it. Committing frequently keeps the history clean and makes the next merge smaller. If your Salesforce CI/CD pipeline runs a validation on each merge, you get an extra safety check for free, and a clean metadata deployment at this stage confirms the merge is truly done. This whole loop is smoother when it sits inside a wider Salesforce release management process that already tracks every change.

If A Merge Goes Wrong, Start Over Cleanly

Not every conflict has to be pushed through in one sitting. If a merge gets tangled and you are unsure of the right result, it is safer to abort the merge and return the branch to its last good state than to force a resolution you do not trust. Nothing is lost when you do this, since your committed work stays intact, and you can retry the merge once you have talked to the other developer or pulled the latest changes. Treating a bad merge as something you can safely undo takes the pressure off, and it stops a rushed guess from reaching your code repository. This is another reason short-lived branches help: a small merge is quick to redo, while a giant one is not.

How To Prevent Merge Conflicts In Salesforce

Resolving conflicts is a skill, but preventing them is cheaper. A few habits keep source control conflicts rare in a healthy Salesforce development workflow. Many of these are core Salesforce DevOps best practices, and they build on the version-control discipline covered in our guide to the five key principles of Salesforce DevOps.

  • Adopt a clear branching strategy. Feature branching or Gitflow gives each piece of work its own space, and branch protection rules keep risky merges out of the main branch.
  • Merge early and often. Short-lived branches accumulate fewer changes, so conflicts stay small and easy to resolve while the work is still fresh.
  • Keep pull requests small and focused. One feature per pull request makes changes clear and review quick, which lowers the chance of overlap.
  • Minimize overlapping work. Assign developers to distinct parts of the org so two people rarely edit the same file, especially large ones like Profiles.
  • Keep environments consistent. Back-promote production hotfixes to lower environments and refresh sandboxes on a schedule so the code repository reflects reality.
  • Break large files into smaller units. Modular Apex classes and permission sets in place of giant profiles reduce the surface where changes collide.

The table below connects each habit to the conflict it heads off.

Prevention Habit Conflict It Prevents
Short-lived branches, merge often Big, tangled conflicts from long-open branches
One feature per pull request Overlap from unrelated changes bundled together
Distinct ownership of components Two people editing the same metadata file
Environment consistency Deployment conflicts caused by sandbox drift
Modular files and permission sets Profile and large-file configuration conflicts

Automated Conflict Detection Tools

Modern DevOps platforms can spot and often resolve conflicts for you. Tools such as Gearset and Copado offer semantic conflict detection, which understands Salesforce metadata rather than treating it as plain text, so they can merge many changes without manual work. For teams new to source-driven development, that safety net is worth the investment.

These tools sit inside a wider deployment process, so the cleanest results come from pairing them with a solid pipeline. Our guide to Salesforce CI/CD best practices covers how automated validation fits alongside conflict detection. Community comparisons on Forcetalks and Git branching guides on SFDCPanther are useful when you are choosing an approach, and learning paths on SaaSguru and tutorials on Salesforce Codex cover the Git fundamentals behind them.

Frequently Asked Questions

1. What is a merge conflict in Salesforce?

A merge conflict happens when two developers change the same lines in the same metadata file and Git cannot decide which version to keep. Because Salesforce work is metadata-driven, these conflicts are common when several people build in the same org at once.

2. How do I resolve a merge conflict in Salesforce?

Open the conflicted file, read the conflict markers Git added, and decide which changes to keep or how to combine them. Remove all the markers, save the file, then deploy to a sandbox and run a validation with tests before committing and redeploying.

3. How do I resolve XML and Apex merge conflicts?

For XML metadata, keep both entries when they cover different fields or permissions so you do not silently drop access. For Apex, read both versions of the method and combine the logic. Always retest after resolving, since a valid-looking file can still break behavior.

Can Salesforce merge conflicts be resolved automatically?

Often, yes. Tools like Gearset and Copado offer semantic conflict detection that understands metadata and can merge many changes without manual effort. They reduce the load, though a person should still review conflicts that touch shared logic or access.

How do I prevent merge conflicts in Salesforce?

Use a clear branching strategy, keep branches short-lived, merge early and often, and give each component a single owner. Keeping environments in sync and breaking large files into smaller units removes most of the overlap that causes conflicts in the first place.

Keep Your Salesforce Team Development Conflict-Free

Merge conflicts are a normal part of collaborative development, and they are manageable with the right approach. Understand what causes them, resolve them methodically by reading the conflict markers and retesting, and prevent most of them with small branches, frequent merges, and clear ownership. Do that, and conflicts stop slowing your releases down.

If you would like help building the source control best practices and pipelines that keep conflicts rare, Minuscule Technologies offers Salesforce DevOps services and expert Salesforce consulting built around how your team works. Contact us today to get started.

Contact Us for Free Consultation
Thank you! We will get back in touch with you within 48 hours.
Oops! Something went wrong while submitting the form.

Recent Blogs

Ready to Architect Your Salesforce Success?

You've seen what's possible. Now, let's make it happen for your business. Whether you need an end-to-end Salesforce solution, a complex integration, or ongoing managed services, our team is ready to deliver.

Schedule a Free Strategic Call