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
BrabasBrabas 

relate two custom objects

Hi, 

 

 

I have two custom objects, Customer and Policy, with the following relationship:
Master-Detail (Customer), both with their forms, inserting or save the Customer,

the application redirects to the form Policy . I want each insert has a Policy that

Customer identifier. How I can do this?

 

 

public class Record{

Public String Person{get; set;}
Public String lastName{get; set;}
Public String firstName{get; set;}
Public String RFC{get; set;}
Public String Direcction{get; set;}
Public String City{get; set;}
Public String CP{get; set;}
Public String Email{get; set;}
Public String Cell{get; set;}
Public String Phone{get; set;}
Public Date bDay{get; set;}
/*********************************/
Public PageReference save(){ 

Customer__c c =new Customer__c (
Person__c= Person,
firstName__c= firstName,
lastName__c= lastName, 
RFC__c= RFC,
Direcction__c=Direcction,
City__c=City,
CP__c=CP,
Email__c=Email,
Cell__c=Cell,
Phone__c=Phone,
bDay__c=bDay 

);

/***************************/

insert c;
PageReference newPage;
newPage = Page.catchPolicy( );
return newPage.setRedirect(true);

} 

/******************************/
}



/*******************************/

public class RecordPolicy{


Public String npolicy{get; set;}
Public String Certificate{get; set;}
Public String Company{get; set;}
Public String descPolicy{get; set;}
Public Date dSPolicy{get; set;}
Public Date dEPolicy{get; set;}
Public String fPayment{get; set;}

/**********************/
Public PageReference save(){


Policy__c p =new Policy__c (
npolicy__c= npolicy,
Certificate__c= Certificate,
Company__c= Company,
descPolicy__c= descPolicy,
dSPolicy__c=dSPolicy,
dEPolicy__c=dEPolicy,
fPayment__c=fPayment
);

/***********************/

insert p;



PageReference newPage;
newPage = Page.capturaPolizas;
return newPage.setRedirect(false);

}
/******************************/
}

 Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

In the first page soon after you save the customer and when redirecting to policy page pass the CustomerId as a parameter in the URL

something like...

 

 String pageURL  ='/apex/catchpolicy?custId='+c.Id;
       PageReference p = new PageReference(pageURL);

       return p;

 

When On the policy creation page... In its respctive controller read the key value pair i.e., customer record Id and when saving the policy record associate it with the customer Id.

All Answers

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

In the first page soon after you save the customer and when redirecting to policy page pass the CustomerId as a parameter in the URL

something like...

 

 String pageURL  ='/apex/catchpolicy?custId='+c.Id;
       PageReference p = new PageReference(pageURL);

       return p;

 

When On the policy creation page... In its respctive controller read the key value pair i.e., customer record Id and when saving the policy record associate it with the customer Id.

This was selected as the best answer
BrabasBrabas

Thanks
 

I have a question.

 

How to read the value of the key in te policy controller?

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

say if your policy page url looks something like.. https://c.naX.visual.force.com/apex/catchpolicy?custId=a09000000ac0anb

 

//this will give you a09000000ac0anb

String CustomerId = ApexPages.currentPage().getParameters().get('custId');