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
venkateshvenkatesh 

Associating objects with Master-detail relationship

Hi,

 

      First, I will have to asscociate two objects and then I will have to update/insert master related child records to child object which are coming from Web Service call.  Here I will explain about my work related to master-detail relationship with the Salesforce screenshots and what I did upto this. Please have a look into the details:

1) I have created new Sales_Order__c(custom object).

2) This object contains Name field as the required filed(ofcourse this field is Auto Number).

3) I have created new custom object(called AccountOrderAssociation__c as the API name) to relate the Account and Sales Oreder objects. This object contains two master-detail relationship custom fields. Here I have ralated one custom field with Account(field API name is Accounts__c)and another with Sales Order(field API name is SalesOrder__c).

4) After above setup, I went to page layout setup of the Account object. Because my intention is to associate the Sales Order(child object) with Account(parent object) as like in link1 and link2.

5) I have selected Sales Order fields such as Name(Required field for Sales Order), Document Number(custom field for Sales Order) from the Related List Properties-Sales Order Association popup window.This popup is available when we click Properties icon in the Sales Order associated block in Account page layout.

When I go to view in-detail of Account records in Account object, these Sales Order field details are displaying in seperate block.

6) This will finish up my requirement of relating between two default and custom objects.

7) Now my requirement is to code level inserting/updating/associating the records to Account and Sales Order objects.

8) To achieve the above scenario at present, I made web service call to external database. I am calling this web service Apex class within trigger of my sheduler(This is one of the seperate custom object) from which I can schedule to update the Account records at the specified intervals.

9) Now I can successfully insert the records to Account object using Apex upsert call.

10) As same like Account object, I will be getting records for Sales Order custom object related to Account records also(through web service call) from my external database.

11)  I should have to insert/update(upsert API call) these Sales Order records to Sales Order object.

12) At present situation I don't have Apex class to call the sales order records from my databse through web service call.

13) So I tried for, when account records are  upserted to Account object through web service call, it should create new Sales Order record or upsert to the same record in my Sales_Order__c object by taking one of the field values from the Account record. As same as below statement written in bold text:

 

//Loop through Sales Order
for(Sales_Order__c s: sales){

//Using the trigger.newMap, get the related Sales Oredr record to the specific Account record
// You need to pass in the AccountID into the get call rather than the Sales_Order__c's ID
Account a = Trigger.newMap.get(s.Name);

//Set the Sales Order related to Account field here....
s.DESCRIPTION__c = a.For_Testing__c;
}

14) To achieve above scenario, when account trigger occures(from web service call), these update/insert or upsert to Sales Order whatever operation should happen.

 

Please help me to achieve the above scenario. I hope I am getting good suggestion from one who achieve same kind of sitaution.

 

Thanks in advance......