You need to sign in to do that
Don't have an account?
hybin joseph 2
Need help with making 2 fields required in a VF page and also map them to Opportunity Fields
I need help with making 2 custom fields created to be required if the Do not create Opp checkbox is not checked. If it is checked then the 2 fields shud be required. I also need to map the value of these fields to 2 custom fields in Opportunity. Code from Class below :
public with sharing class ConvertLeadExtn { Final Lead curLead; public boolean IsSendEmailChecked{get;set;} public String SelectedAccType{get;set;} public Contact ContactAcctToRefer{get;set;} public boolean IsOppChecked{get;set;} public String SelectedConvrtdStatus{get;set;} //Returns the list of account types public list<selectOption> lstAccountType { get { List<selectOption> lstAcctType = new List<selectOption>(); lstAcctType.add(new selectOption('','--None--')); lstAcctType.add(new selectOption('Create New Account','Create New Account')); lstAcctType.add(new selectOption('Attach to Existing','Attach to Existing')); return lstAcctType; } set; } // Returns the converted Status list public List<selectOption> lstConvertedStatusList { get { List<selectOption> lstConvertedStatus = new List<selectOption>(); LeadStatus leadStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1]; lstConvertedStatus.add(new selectOption(leadStatus.MasterLabel,leadStatus.MasterLabel)); return lstConvertedStatus; } set; } //Controller public ConvertLeadExtn(ApexPages.StandardController controller) { this.curLead = (Lead)controller.getRecord(); if(curLead.Id!=null) { ContactAcctToRefer = new Contact(); } } //Converts the Lead public PageReference ConvertLead() { Id accountId; PageReference accPage; try { Database.LeadConvert leadCnvrt = new database.LeadConvert(); if(SelectedAccType == null || SelectedAccType =='') { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Account Type!')); return null; } //Sets all the fields that are required leadCnvrt.setLeadId(curLead.Id); leadCnvrt.setOwnerId(curLead.OwnerId); leadCnvrt.setSendNotificationEmail(IsSendEmailChecked); leadCnvrt.setDoNotCreateOpportunity(IsOppChecked); leadCnvrt.setConvertedStatus(SelectedConvrtdStatus); if(SelectedAccType == 'Attach to Existing') { if(ContactAcctToRefer.accountId !=null) { leadCnvrt.setAccountId(ContactAcctToRefer.accountId); } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Existing account to attach!')); return null; } } if(!leadCnvrt.isDoNotCreateOpportunity()) { leadCnvrt.setOpportunityName(curLead.Company); } Database.LeadConvertResult leadCnvrtResult = Database.convertLead(leadCnvrt); accountId=leadCnvrtResult.getAccountId(); System.assert(leadCnvrtResult.isSuccess()); } catch(exception excptn) { String excptnMsg = excptn.getMessage(); if(excptnMsg.contains('CANNOT_UPDATE_CONVERTED_LEAD') || excptnMsg.contains('INVALID_CROSS_REFERENCE_KEY')) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Lead Conversion Failed! Lead is already converted!')); } else if(excptnMsg.contains('TRANSFER_REQUIRES_READ')) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Opportunity can not be created, User do not have Read Permission!')); } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,excptn.getMessage())); } } if(accountId!=null) { accPage = new pageReference('/'+accountId); } return accPage; } }
You can use javascript in VF page to make the fields required.