You need to sign in to do that
Don't have an account?
Brabas
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!
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
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.
Thanks
I have a question.
How to read the value of the key in te policy controller?
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');