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
sgkmillssgkmills 

Custom object with 'New' Action not working

Hi,

I have written an s-control for some standard and custom objects to override the "Add" buttons.  The "Add" buttons on the standard object Opportunity Product works fine with the code below (The object name in red is replaced with the Opportunity Product of course).  The problem happens when I try to use a custom object called "Sales_Credit__c".  When the function below runs, it seems to call the s-control twice because I get the alert message (highlighted in blue) twice, where the 2nd time around Opportunity.Id, and Opportunity.Name are blank.  Then I get a blank page in the web browser with a URL stating: https://na3.salesforce.com/servlet/servlet.Integration?lid=*deleted for post*&ic=1#Error!

function successInit(queryResult)
 {
    var records = queryResult.getArray('records');
    qrysize= queryResult.size;
    var it = new sforce.QueryResultIterator(queryResult);

    while(it.hasNext() )
    {
        var record = it.next();
        gProfileId=record.Profile_Identifier__c;
        if (gProfileId == 'Admin' )
        {
            alert("ProfileId=" + gProfileId + ", Opp.: " + '{!Opportunity.Id}' + ", " + '{!Opportunity.Name}');
            window.parent.location.href="{!URLFOR($Action.Sales_Credit__c.New,  Opportunity.Id,  [retURL=URLFOR($Action.Opportunity.View, Opportunity.Id)], true)}";
           
        }
        else
        {
                searchstring0="select Id, Opportunity_Number__c, Submit_to_ERP__c from Opportunity WHERE Id = '{!Opportunity.Id}' LIMIT 1 ";
                 queryResult= sforce.connection.query(searchstring0, ERPcallback);
        }
    }
}

Then I have also done it with the href set with variables, and then I get the New sales credit screen, but don't have the variables assigned.

window.parent.location.href="{!URLFOR($Action.Sales_Credit__c.New,  null,  [retURL=URLFOR($Action.Opportunity.View, Opportunity.Id),Opportunity=Opportunity.Name], true)}";

Also, the "Sales_Credit__c" object has a master-detail realtionship to Opportunity!

Any information to point me in the right direction will be greatly appreciated.

Thanks in advance
sgkmillssgkmills
Well, I have answered my own question!

The format that worked for me was the one below, where I had to substitue the **uniquefieldnames** generated by SalesForce so I could prepopulate the fields on a newly created Sales Credit (Custom object)

window.parent.location.href="{!URLFOR($Action.Sales_Credit__c.New,   null,  [**uniquefieldname**=Opportunity.Name,**uniquefieldname**=Opportunity.Id,retURL=URLFOR($Action.Opportunity.View ,  Opportunity.Id ) ], true)}";

As a sidenote, I cannot say I find these forums much of any use.  Most of the posts I read are incomplete and when you do see a post from some of the SalesForce guys they suggest read the documentation.  Well, I have read the documentation and it isn't too good at all!  For example, the "Custom Formula Fields" documentation.  Plus, a lot of the documentation doesn't touch on what most people are trying to do! 

I do see good posts from other contributors and after searching the net and reading many other incomplete posts with similar issues, I attempted the above and it worked.  Not my choice of problem-solving, but it is what I had to default to.

The Apex language and the s-controls is a powerful tool, but I wish I could have more examples and better documentation so I could do so much more. 

Anyway, like I said above, my problem is solved and hopefully someone might be able to solve their similar issues.


JakeHJakeH

sgkmills,

I feel your pain! Way too many posts never receive a reply. Granted, some are poorly worded, but most are fair questions where it's clear the poster has tried many things and is now stumped.

I have yet to locate a doc that contains a complete list of commands I can use in an s-control, and I get stumped on possibly easy problems because of that. Could you list some of the other resources you find useful in creating s-controls?

Thanks,

-Jake

Thrantor2Thrantor2

sgkmills, Where did you find out what the "uniquefieldnames" were for your object. I'm trying to work with the standard opportunity object but with custom fields and I can't find the names for the stupid things.

 

Is there documentation somewhere that talks about this?