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
IWyattIWyatt 

Is it possible to create an Opportunity from a URL link?

Hi all - hoping there are some really  smart people out there that can help me vet an idea. :smileywink:

 

I'd like to have a clickable URL link in generated Tasks that allow a sales rep to click the link which will create an Opportunity with the Primary Campaign Source field pre-filled with a specified value.

 

I was thinking that the new REST API might be able to do this, but I wanted to see if the community has done this before?

 

The problem we are attempting to solve is taking the burden off Sales reps for attaching certain opportunities to specific campaigns.

For reasons I won't get in to, using the contact's previous campaign (default behavior) isn't sufficient.

 

Thanks all!

 

Best,

IW

 

 

Best Answer chosen by Admin (Salesforce Developers) 
joshbirkjoshbirk

A Visualforce page with the appropriate controller logic should be able to do that.  You can pass the ID's of the task/campaign/etc in the URL, the controller can pick it up, create the opportunity and the forward the user to where they need to go.

All Answers

joshbirkjoshbirk

A Visualforce page with the appropriate controller logic should be able to do that.  You can pass the ID's of the task/campaign/etc in the URL, the controller can pick it up, create the opportunity and the forward the user to where they need to go.

This was selected as the best answer
IWyattIWyatt

I like this idea - I'm new to visualforce pages, but not to coding.

After 20 minutes of reviewing the development guide, I think I could have a proof of concept built in little time.

 

Thanks for the great idea!

 

Best,

IW

IWyattIWyatt

So I've been tinkering with this in my spare time, attempting to build a proof of concept, and I'm not having much luck.

If you or another member of the community could offer some help, I would appreciate it.

 

The inline visual force page that I want to show up on the task is displaying "Content cannot be displayed: DML currently not allowed".

The expected display is a link, that when clicked, will create an opportunity with the name "Acme".

 

This is my visualforce page code:

 

<apex:page standardController="Task" extensions="OppClass">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Q1 2011 Upsell</h1>
Create new opportunity with this campaign:
<!-- My Stufff -->
    <apex:form >
    <apex:commandLink action="!Ops" value="Create New Opp" id="comlink1"/>
    </apex:form>
<!-- END MY STUFF-->
  <!-- End Default Content REMOVE THIS -->
</apex:page>

 

 

My apex code is this (intended to execute when one clicks on the above link):

 

public without sharing class OppClass
{

    public OppClass(ApexPages.StandardController controller) {
    NewOpp();
    }

    public void NewOpp(){
        Opportunity o = new Opportunity(name = 'Acme');
        Database.SaveResult[] lsr = Database.insert(new Opportunity[]{o, new Opportunity(name = 'Acme')},false);
    }
}

 

This is intended to be a simplified proof of concept, but I can't see where I am failing. Does anyone have any suggestions?

 

Thanks,

IW

 

joshbirkjoshbirk

It's using DML in the page constructor that is throwing the error.  Refer to the function in need in the action attribute of the page tag instead.

 

 

IWyattIWyatt

Thank you, Josh - 

 

I also found out my syntax was off as well:

http://boards.developerforce.com/t5/Visualforce-Development/Help-Requested-Create-new-Opp-from-visualforce-page-hyperlink/td-p/238289

 

Thanks again for your help.

 

Best,

Iw