You need to sign in to do that
Don't have an account?
jsacpt24
create opportunity from button
I am trying to create a visualforce button that then inserts an opportunity and then sends an email to anyone if the running user is listed as the marketing_development_rep__c. Not sure if I am doing something wrong but it isn't creating the opportunity when I go and hit save.
VF:
Apex:
VF:
<apex:page controller="mdrHandOffOppInsert" sidebar="false" showHeader="false"> <apex:form id="frm"> <apex:pageBlock > <strong>Please provide any reference notes for this deal.</strong> <apex:pageBlockSection > <apex:inputField value="{!Opportunity.Hand_Off_Notes__c}" required="true"/> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:actionFunction name="quickSaveJavascript" action="{!quicksave}" oncomplete="window.top.close();"/> <apex:commandButton value="Submit" onclick="quickSaveJavascript();"/> <!--<apex:commandButton action="{!cancel}" value="Cancel"/>--> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Apex:
public class mdrHandOffOppInsert { public Account acc{get; set;} public opportunity oppstring{get; set;} public mdrHandOffOppInsert(){oppstring= new opportunity();} public void Saveto(){ opportunity opp= new opportunity(); opp.Accountid= oppstring.Accountid; opp.StageName= 'F- Awareness'; opp.CloseDate=date.today()+90; opp.Type='New Business'; opp.Name= oppstring.name + ' SaaS Deal'; opp.Marketing_Opp__c = true; opp.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('SaaS - Marketer').getRecordTypeId(); insert opp; } } public static sendEmailToAccDir { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List <User> sadList= SELECT Account_Director__r.email FROM team__c WHERE Marketing_Development_Rep__r.id = UserInfo.getUserId()]; mail.setTargetObjectId(Con[0].id); mail.setSenderDisplayName('Salesforce Support'); mail.setUseSignature(false); mail.setBccSender(false); mail.setSaveAsActivity(false); EmailTemplate et=[Select id from EmailTemplate where Name=:'MDR_Sales_Handoff_Initial_Alert']; mail.setTemplateId(et.id); Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }
Is this the updated code..?
In the SaveTo() method, you have written logic to create opportunity, but I don't see this function is being called from any button in the VF page.
Am I right..?
Thank You,
Rajesh Adiga P.
VF:
Apex:
Also, update the VF page line 6 with the below line
<apex:inputField value="{!Opp.Hand_Off_Notes__c}" required="true"/>
VF:
APEX: