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
sfmoosesfmoose 

S-Control to create new record in custom object upon saving Opportunity

Hello everyone. 
I am in need of some help creating a S-Control.  I am the Admin for my company but do not have much programming experience.  I am trying to create a process in the opportunity tab that will create a new record in in a related custom object when the user saves a new opportunity.  The new record on the custom (related) object will contain data from 3 fields in the opportunity.  I was told that an S-Control can achieve this.  If anyone can lead me in the right direction, it would be greatly appreciated. 

Thank you in advance,
sfmoose
jf317820jf317820
this will be a lot easier to do using triggers when apex code goes to general release, but in the meantime...

my approach would be to embed an scontrol in the opportunity detail page.  once the user saves the opportunity, he/she is directed to the opportunity's detail page, which would launch the scontrol.  the scontrol would be coded to set the custom object fields based on the opportunity merge fields.

if you need any additional information for the solution above, let me know.

i'm sure there are other solutions, but they escape me currently.  perhaps others could chime in?
sfmoosesfmoose
Thanks so much for the reply!
Do you have any sample code you could send?  I'm not sure how to embed the code on the page or how to pull in the opportunity fields to my custom object.  I found out from SF that I can't override the Save button which was my original plan. 


RickyGRickyG
One small point - Apex Code is GA with the Summer 07 release.

- Rick Greenwald
Developer Evangelist
jf317820jf317820


RickyG wrote:
One small point - Apex Code is GA with the Summer 07 release.

- Rick Greenwald
Developer Evangelist





for unlimited edition only, correct?
RickyGRickyG
Right you are.

- Rick Greenwald
Developer Evangelist
sfmoosesfmoose
Thanks!
Any ideas on how I can accomplish this as easily as possible in the meantime?  Even some 'starter' s-control code would be much appreciated!!

RickyGRickyG
Your best friend - the Apex Developer Network.  Try some of the documents linked to from this page.

Hope this helps.

- Rick Greenwald
Developer Evangelist
finkyfinky
BTW, what does "GA" stand for?  :)
RickyGRickyG
General Availability.
BradDBradD
I created this s-control which 99% of it was copied from the Apex Toolkit. It lies inline on the Opportunity Page Layout, and will create a related list item only once (it matches on the Name of the Opportunity to the custom object). It works, but if anyone has any enhancements/suggestions, let me know!

<html>

 

<head>

<link href="/sCSS/8.0/1171411121000/Theme2/default/common.css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" type="text/css" />

<script src="/soap/ajax/8.0/connection.js"></script>

 

<script>

 

function initPage() {

 

 

        function findAccount(name) {

            result = sforce.connection.query("Select Id from Custom_Object__c where Name like '" + name+ "' limit 1");

            return result.size != 0;

        }

function createAccount() {

  var account = new sforce.SObject("Custom_Object__c");

            account.Opportunity__c= "{!Opportunity.Id}"

account.Name="{!Opportunity.Name}"

            result = sforce.connection.create(new Array(account));

            status = result[0].success == "true" ? "Account created" : "Failed to create account.";

}

 

 

try {

              if (findAccount("{!Opportunity.Name}")) {

                   alert("Record already exist. Not creating new ones.");

                } else {

                    createAccount();

                }

                return false;

            } catch (fault) {

               

                sforce.debug.display(fault);

            }

    

 

}

 

</script>

</head>

 

<body bgcolor="#F3F3EC" onload="initPage();">

</body>

 

</html>


MenteeMentee
@BradD
I dont know your post helped 'sfmoose' or not. It Helped me. I have learnt new things from your post. Thanks!