0

I'm developing Salesforce code that interacts with a specific campaign. Currently, I have the following snippet, but it is not environment-independent due to hardcoded IDs:

if (opp.RecordType.DeveloperName == 'ExampleDeveloperName') {
opportunityWillUpdate.CampaignId = '123xx'; 
opportunityWillUpdate.CampaignExtensionName = '123yy'; 

}

I understand that directly using Campaign IDs (like '123xx') and potentially the 'CampaignExtensionName' can cause conflicts if campaigns are replicated between environments (e.g., development, testing, production).

One way I found is:

List<Campaign> matchingCampaigns = [SELECT Id FROM Campaign WHERE Name = :campaignName];

But in case the campaign name is different in different environments, like development and production, this code would fail.

My question is: What is the best practise to reference a spesific campaign without using hardcoded ID's? I also don't want to use custom metadata type,custom setting or custom labels.

Thanks in advance

1
  • Welcome to SFSE. Please take a moment to read How to Ask and take the tour. You have no choice but to use one of those 3 structures. Custom Metadata Type is probably best. Feb 16 at 15:39

0

You must log in to answer this question.

Browse other questions tagged .