• Richard L Jones
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
Hi all,

I've got a custom button which uses onclick javascript to update the Stage of my opportunity object, so users can push the opportunities through the first few stages of the sales process. The javascript I cobbled together to do this is;
 
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var opp=new sforce.SObject("Opportunity");
var newRecords = [];
opp.id="{!Opportunity.Id}";
opp.StageName = 'Gate 1 - Pursuing';
newRecords.push(opp);
var result = sforce.connection.update(newRecords);
window.location.reload();

This particular JS is on the first button, moving it from Prospecting to Pursuing, and they all seem to work fine. Now, I know that Salesforce1 won't use OnClick Javascript because Salesforce basically like messing with me ;) 

However, I've attempted to move it into a VF page and create a global action, which sure enough creates a button on my SF1 action bar, but it's really clunky because all it does is open up an extra page with a button on it. Plus it doesn't work, so looks both awful and is pointless :p I'll put the code for it at the bottom, just in case anyone wants a laugh. 

Soooooo, is there any way to recreate the nice experience of just having a custom button on my opportunity object which just pushes the stage forward without needing to open up random pages or anything like that? 

thanks in advance
Richard 
 
<apex:page >
<apex:form >
 <script src="/soap/ajax/13.0/connection.js"></script >
    <script>
sforce.connection.sessionId = "{!$Api.Session_ID}";
function execute()
{
    var opp=new sforce.SObject("Opportunity");
    var newRecords = [];
    opp.StageName = 'Gate 1 - Pursuing';
    newRecords.push(opp);
    var result = sforce.connection.update(newRecords);
    window.location.reload();
    } 
    }
}
</script>
<input type="button" value="Next Stage" onclick="execute();"/>
</apex:form>
</apex:page>


Hi all,

I've been experimenting with ways to print part of a page layout by using an Onclick Javascript custom button. I've got it to print the div I want using the following code;
 

var prtContent = document.getElementById("ep");
var WinPrint = window.open('', '', 'left=0,top=0,width=1024,height=768,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();

It prints the right bit, but obviously it doesn't pick up the necessary CSS to make it half-way decent. I've tried to make it pick up the CSS by using various combinations of;


WinPrint.document.write('<link rel=stylesheet href=common.css>')
WinPrint.document.write('<link rel=stylesheet href=extended.css>')

Variations include just using one or other line, and other including the /sCC/40.0/. . . etc. etc. full links. 

The problem that I have when using these is that nothing appears on the printed document at all :) Anyone got any ideas? I'd like to make this work instead of going down the Visualforce rendertoPDF route, to be honest, in case people think of that :)

thanks
Richard

Hi all,

Well, I'm in well over my head here :) We have a custom object on our opportunity pages called Financial Projections. This takes data from the opportunity page and performs calculations to show annual revenue and annual gross margin, and then displays them in a related list object.

The problem I've got, apart from the developer having disappeared, is that the financial projection aren't being generated properly.

Basically, if a user completes all the required fields on the opportunity and saves it, the projections will generate correctly.

However, if they don't enter all the fields but move the opp forward a stage, and at that point enter all the required fields, the financial projections doesn't trigger at all.

Finally, and confusingly, if they populate the correct fields at the start, move forward a stage, and then alter the figures, the financial projections will correctly update. 

So, it's almost as if it's a one-chance deal to the trigger the class. Can anyone help? I'll post the trigger below - the class is 650 lines long so I'm not sure an inline paste will work here.

Thanks in advance
Richard

trigger CRMS_OpportunityTrigger on Opportunity (before insert, after insert, after update, before update) 
{
    public static boolean blnUpdate = false;
    //public static integer intCount = 0;
    if(trigger.isInsert && trigger.isBefore)
    {
        CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
        objClass.beforeInsert(trigger.new);
    }
    if(trigger.isInsert && trigger.isAfter)
    {
        CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
        objClass.afterInsert(trigger.newMap);
    }
    if(trigger.isAfter && trigger.isUpdate)
    {
        //if(intCount <2)
        if(!blnUpdate)
        {
          CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
          objClass.afterUpdate(trigger.newMap, trigger.OldMap);
          //intCount = intCount + 1;
          blnUpdate = true;
        }
    }
    if(trigger.isUpdate && trigger.isBefore)
    {
        CRMS_OpportunityTriggerHandler objClass = new CRMS_OpportunityTriggerHandler();
        objClass.beforeUpdate(trigger.newMap, trigger.OldMap);
    }
}