0

My requirement is as follows :- In my ORG i have vf pages for account,Lead and opportunity where as standard pages for Contact and event. I want to per-populate some common fields between object Like in account there is a field called State and the same state field is in opportunity so i have to populate this field every time when i create opportunity . There are ample of such fields in my objects.

I want button facility in each VF page for creating new opportunity, new event , new contact ... can you help me out how to achieve this functionality with a sample code.

2

If you have a custom page to create Opportunity then it's very easy all you have to do is to fetch State value from Account and to put that in you instance which you are using to create Opportunity like.

public class YourController {
public Opportunity opp {get;set;}
public YourController() {
  List<Account> acc = [Select Id,State__c from Account where Name = 'YOUR ACCOUNT TO FILTER' ];
  String state ;
  if(acc.size() > 0 && acc[0].State__c ! = null)
    state =  acc[0].State__c ;
  opp = new Opportunity(State__c = state) ;
}
}

And then use this instance on your VF page.

Or if you only need that value to show on detail page then you can use Formula field or Workflow to populate that.

2
  • What about VF page to standard page i have account page in VF and contact and Event pages are standard page . I have to populate some fields of account in contact as well as event.
    – Cloud Arch
    Aug 8 '15 at 6:11
  • If you only need to show those fields on detail page of event and contact then you can populate them with WF rule or formula fields Aug 11 '15 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.