function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeekDeek 

Establish M2M Relationship between Accounts and Campaigns

Hi Ya,

 

I need to create a Mant to Many relationship between Accounts and Campaigns. 

 

Please suggest the schema design for this approach.

 

Till now I understand, that we might need to create a junction object say AccountCampaign between Accounts and Campaigns and create master detail relation to Account and Campaign on this object respectively.

 

Is that the correct approach? Please suggest the best approach and solution.

 

Thanks

Dpat

Best Answer chosen by Admin (Salesforce Developers) 
DeekDeek

Hi Sonam,

 

My sincere apologies for replying so late. Yes you are right now I am able to pick the fields from ChildofCampaign>.

 

You rock.

 

Cheers!

 

Regards,

Dpat

 

 

All Answers

Sonam_SFDCSonam_SFDC

Hi Dpat,

 

The way to implement a  many to many relationship in Salesforce is indeed through Junction Object  hence your approach looks correct and the AccountCampaign OBject with its two masters Account and Campaign should do the trick.

 

 

sandeep@Salesforcesandeep@Salesforce

Yes You are with correct approach. you jst need to keep one thing in mind that In Junction object you need to create two master Detail relation ship with Accoutn and Campaign.

souvik9086souvik9086

Yes, create a custom object named AccountCampaign__c keeping the relation of both the objects as master-detail.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

sandeep@Salesforcesandeep@Salesforce

Please let us know if you need some more information

DeekDeek

Hi Sandip,

 

Thanks for all your advise.

 

How do I display this object in Account page? Can I display this object as a field in Accounts? 

 

I believe displaying this object as a related list in Accounts wont make sense. 

 

Please advise.

souvik9086souvik9086

The child object(junction object)must come in the related list in the Account detail page. It will not be available as fields in Account detail page.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

khillan bhardwajkhillan bhardwaj

yes u are right . m2m relationship is estalished by creating junction object say accCom  whixh have master-detail with Account and Compaign

sandeep@Salesforcesandeep@Salesforce

This new juncton object is child of these two object Account and Campaign.

 

Account               Campaign 

       \                       /

        \                    /

      Junction Object

 

 

You can show this object on Account's page for this you need to click on Edit layout on Account page and then in related list you need to drag and drop related list of this object on page layout and save thsi layout chage.

 

now automatically this object 's record will come- up in list format. 

 

You can do the same thing on campaign page layout also. 

DeekDeek
Hi Sandeep, Souvik and all,



Thanks you all for the prompt response.



As advised I did the same thing. In the accounts page layout I dragged and dropped the AccCamp object from the related list section.



In the UI, when I create a new record for an account on the related list:



1.The Accountid field which is a required field by default (Datatype-Master-Detail(Account) is prepopulated with the Account Name.



2. The Campaignid field which is another required field by default (Datatype-Master-Detail(Campaign) is blank. I need to associate a previously created campaign to this field in order to save the record. Is this expected?



Queries?

A- Will there will be only 2 fields displayed in the related list.i.e. Accountid and the Campaignid. Just understanding from useability perspective.

B - If I need to display few other fields from campaigns object in the related list. Is that possible? Means, when I pick up the Campaignid field, as stated in point 2 above, it should populate the exposed campaigns fields in the related list. Does this makes sense.? If so, how do I achieve this.



Sorry for putting so many questions. I am in learning stage and trying to achieve this without any major design issues.



Regards,

Dpat




















Notice



This email and any attachments are strictly confidential and subject to copyright. They may
contain privileged information. If you are not the intended recipient please delete the message
and notify the sender. You should not read, copy, use, change, alter or disclose this email or
its attachments without authorisation. The company and any related or associated companies do
not accept any liability in connection with this email and any attachments including in connection
with computer viruses, data corruption, delay, interruption, unauthorised access or unauthorised
amendment. Any views expressed in this email and any attachments do not necessarily reflect the
views of the company or the views of any of our related or associated companies.
souvik9086souvik9086

For points 1) and 2)

 

If you create a new junction object record from Account layout then account will be prepopulated and campaign will be blank.

If you create a new junction object record from Campaign layout then campaign will be prepopulated and account will be blank.

 

For Queries

 

A) No of fields present in that junction object you can display, going in the Edit Layout

B) This is not possible in standard layout. Possible only if you store the campaign field values in junction object. If you want  to have full access you can create a custom vf page and override with the view page of account or campaign(as per req) and then create the related list as custom and give the values from campaign field there.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

Sonam_SFDCSonam_SFDC

Hi Dpat,

 

A- Will there will be only 2 fields displayed in the related list.i.e. Accountid and the Campaignid. Just understanding from useability perspective.

<Sonam_SFDC>

 

You can add more fields to be displayed on the related list by going to the Account Page layout > scroll down to the Junction Object related list > clkick on the wrench icon to open settings and you can then choose which fields you wish to show on this related list.

 

In case, you have only two fields - Account ID and campaign ID on this junction Objects and wish to show more fields from the Account/Campaign Object - you can create formula fields on this junction Object and pull in the fields values from the master Objects.

B - If I need to display few other fields from campaigns object in the related list. Is that possible? Means, when I pick up the Campaignid field, as stated in point 2 above, it should populate the exposed campaigns fields in the related list. Does this makes sense.? If so, how do I achieve this.

<Sonam_SFDC>

The above explaination covers the answer to this question.

Yes , it is possible via formula fields to show field values from master objects.

 

Hope this helps!

sandeep@Salesforcesandeep@Salesforce


A- Will there will be only 2 fields displayed in the related list.i.e. Accountid and the Campaignid. Just understanding from useability perspective.

No you can add more you need ti again click on Edit Layout and then go to selected relatd list there  you will find Setting icon click on that so you will find a window form where you can manage these all.


B - If I need to display few other fields from campaigns object in the related list. Is that possible? Means, when I pick up the Campaignid field, as stated in point 2 above, it should populate the exposed campaigns fields in the related list. Does this makes sense.? If so, how do I achieve this.

 

Directly it is not possible but yes you can do it by created formula field on junction object and then you can show it on related list also..

 

Please let us know in case of knowing more clarifitcation or can close this discussion thread by selectig answere you liked provding kudos

DeekDeek
Hi Sandeep,



Thanks for your reply. I am trying the way as you advised. Any hiccups I
will reply you.



Cheers!

Dpat




Notice



This email and any attachments are strictly confidential and subject to copyright. They may
contain privileged information. If you are not the intended recipient please delete the message
and notify the sender. You should not read, copy, use, change, alter or disclose this email or
its attachments without authorisation. The company and any related or associated companies do
not accept any liability in connection with this email and any attachments including in connection
with computer viruses, data corruption, delay, interruption, unauthorised access or unauthorised
amendment. Any views expressed in this email and any attachments do not necessarily reflect the
views of the company or the views of any of our related or associated companies.
DeekDeek

Hi Sandeep,Sonam,

 

Thank you both for the advise.

 

I am stuck up in creating formula fields in Account Campaign Junction object as advised.

 

Just to start off, I am trying to populate a custom formula field called "Year" in the junction object from the corresponding custom formula field "Year__c" in Campaign object.

 

What will be the syntax for the formula field?

 

Please help.

 

 

Sonam_SFDCSonam_SFDC

Hi,

 

I assume there is a master detail relationship between junction object and Campaign:

The formula field for this field should be something like:

Junction_Object_Campaign Year = Campaign__r.Year__c

 

Read more on Cross object formulas:

https://help.salesforce.com/HTViewHelpDoc?id=fields_creating_cross_object_advanced.htm&language=en_US

 

 

sandeep@Salesforcesandeep@Salesforce

Step1. Create a new custom field on junction object ( field type should be formula)  

Step2. Here you need to mention return type so keep it TEXT and now for syntax you can do it  by providing wizard pick Campaign and then select it's field "year". it will automatically create formula or you can directly use something like as suggested by Sonam.

 

DeekDeek

Hi Sandeep/Sonam,

 

I followed Step 1  - created a new custom field of type formula and return type as text.

 

In Step 2  - In the wizard it doesn’t display “Campaign” object. It just pop up the junction object name “Account Campaign” along with other definitions as shown in screen shot.

 

Please help me out.

 

How do I display Campaign object in the wizard?

 

Sonam_SFDCSonam_SFDC

Hi dpat,

 

Could you please upload the screenshot to a public site and share the link here, the screen shot didn't get uploaded on the comment.

 

I think you should be able to see the campaign object there if you are wokring on the junction object and you have a Master detail relationship with Campaign as master. 

Peter_sfdcPeter_sfdc

Dpat, I'm going to steer you in a different direction altogether. 

 

Campaigns are connected to Leads and Contacts through the Campaign Member object. Since Contact is required to have an Account, there is already an indirect link between Campaign in Account like this: 

 

Campaign---<CampaignMember>---Contact>--Account

 

You're a little unclear as the the driving force behind connecting Account and Campaign, but I would strongly advise against adding another relationship to Account, unless there is a really good reason to do so. But just knowing which accounts have something to do with this campaign, if you have contacts, you can use cross-object formulas to display account information on the Campaign member. 

 

For instance, let's say you want to have visibility to the Industry. You could use a formula to go get industry from Account if the campaign member is a Contact, or use it to get it from Lead if it is a Lead. Campaign member has both a ContactId and LeadId field. But if ContactId is populated, the Lead is ignored, as the system assumes the Lead has been converted at that point, and converted Leads are typically shunted aside in the standard UI. 

 

To try the formula I'm thinking of: 

1. Go to Setup > Customize > Campaigns > Campaign Members > Fields

2. At the bottom of the page look for the section titled "Campaign Member Custom Fields & Relationships" and click New

3. Select the Formula radio button and click Next

4. Enter a field label and name (for instance Company Industry)

5. Select Text in the Formula Return Type radio buttons and click Next

6. In the formula editor, enter this formula:

IF (ISBLANK(ContactId), Lead.Industry, Contact.Account.Industry)

7. Click Next

8. Click Next

9. Click Save

10. Next go to your Campaign page layout Customize > Campaigns > Page Layouts

11. Next to your page layout, click Edit (if you have more than one, pick whichever one you want to test with)

12. Find the Campaign Members related list at the bottom, and click on the wrench icon. 

13. Move your field to the list of fields in use. 

14. Click Ok and Save

 

You asked about approach, and in my opinion, this would be the best practice: use the existing relationship. The advantage of this approach is that it will leverage all of the features of the existing campaign functionality and Lead conversion functionality. If you have a campaign member that is a Lead, but you have a separate relationship to Account, you create a potential disconnect between that information when you convert those Leads. But the cool thing is that when you convert a Lead, it will perform an Account dedupe and attempt to connect it with existing Accounts. 

 

On the other hand, maybe "Account" is meant to represent some other data, like partners or organizations that will be used as channels for your Campaign. If this is the case, then the M2M junction object that was suggested by others is the way to go, and you can tell me to shove off. :-)

 

Good luck!

DeekDeek

Hi Sonam,

 

I have shared the link for viewing.

 

https://www.dropbox.com/s/o5l2brzncuzfmr2/Att.docx

Sonam_SFDCSonam_SFDC

Hi Dpat,

 

In the second column choose "ChildofCampaign>" - I think this is the lookup field name you have given to Campaign object which is the reason its not showing Campaign but the custom name you've given.

 

When you select ChildofCampaign> you will see the campaign fields and you can then choose year from there.

 

DeekDeek

Hi Sonam,

 

My sincere apologies for replying so late. Yes you are right now I am able to pick the fields from ChildofCampaign>.

 

You rock.

 

Cheers!

 

Regards,

Dpat

 

 

This was selected as the best answer
DeekDeek

Hi Peter,

 

Apologies for late reply.

 

I know I have a very limited knowledge in Salesforce as I have just ventured in this domain recenlty.

 

Your explanation was really very useful and a real eye opener. Now I came to know about the schema relations from Campaign to Accounts.

 

I have another related question in regards to Campaigns. Why the Campaign object is not available in Dataloader for insert/update/upsert/delete operations.

 

Its available in Dataloader(while I connect to Sandbox).

 

Please let me know the reasons and any other alternative way to run upsert opeartions for Campaigns?

 

Cheers!