+ Start a Discussion
Agnibha Chakrabarti 10Agnibha Chakrabarti 10 

how to create new relationship between two objects after final approval?

this is the requirement: On approval, a relationship between the Student and the batch(two custom object) will be created in the system.
Nubes Elite Technologies Pvt. LtdNubes Elite Technologies Pvt. Ltd
Hi Agnibha,

You need to create the lookup, then populate each one so that each child record has a parent record. This is because a master detail relationship does not allow for 'orphaned' child records. Once you have a lookup with each child having a parent, than you can go back and convert the lookup field to a master detail. 

follow this url : https://success.salesforce.com/answers?id=90630000000h0TaAAI

Thank You,
www.nubeselite.com
Development | Training | Consulting

Please mark this as solution if your problem is solved.
Agnibha Chakrabarti 10Agnibha Chakrabarti 10
how can I automate the process?
 
Team NubesEliteTeam NubesElite
Hi Agnibha,
If you want to automate this process
1. You need to create a lookup relationship
2. Create a proces builder to automate this please find the link for help
https://help.salesforce.com/articleView?id=000337963&language=en_US&type=1&mode=1 (https://help.salesforce.com/articleView?id=000337963&language=en_US&type=1&mode=1)
3. Or you can create a trigger for this it will work like charm.


Thank You
www.nubeselite.com

Developement | Training | Consulting

Please Mark this as solution if your problem resolved. 
 
Agnibha Chakrabarti 10Agnibha Chakrabarti 10
can you provide any sample code for trigger where within trigger we are creating a lookup field in child object after approval process. That will be really helpful
Team NubesEliteTeam NubesElite
Hi Agnibha,
This is a sample code you can refer this code and make changes according to your requirement.
trigger OpportunitySubmitForApproval on Opportunity (after update) {
List<Approval.ProcessSubmitRequest> approvalReqList=new List<Approval.ProcessSubmitRequest>();
for (Oppertunity opp: Trigger.New)
{       
  if (opp.Incentive_Offer__c=='Yes')
 {           
     // create the new approval request to submit    
   Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();   
   req.setComments('Submitted for approval. Please approve.');
   req.setObjectId(opp.Id);
   approvalReqList.add(req);        
   }   
  }
// submit the approval request for processing        
List<Approval.ProcessResult> resultList = Approval.process(approvalReqList);        
// display if the reqeust was successfull
for(Approval.ProcessResult result: resultList )
{        
System.debug('Submitted for approval successfully: '+result.isSuccess());      
}
}



Thank You
www.nubeselite.com

Developement | Training | Consulting

Please Mark this as solution if your problem resolved.