• Sarah Kalmbach
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
Howdy!

I currently have a workflow setup to, on opportunity creation, set the opportunity name via Workflow to update field name to YYYY-MM-DDXX, where 'XX' is the number of opp that has been created on that date within the entire org.

For example:
- If I made an opp right now, and it was the first opp created today, it would be named 2017-08-2201
- If I created another opp right after, the opp name would be 2017-08-2202
- ...and so on
- But, when the clock strikes midnight, the last two numbers would reset, so the first opp created after midnight would be 2017-08-2301

The way I have this workflow setup is through an autonumber field, as such: {YYYY}-{MM}-{DD}{00}. The problem I've run into is that the {00} (in the XX in my first example) does not reset daily so, I have to manually change it to a text field, then back to an autonumber field every morning.

I have never written APEX but, I’ve been trying to give it a shot. Via dev forums, I was able to generate a correct class and class test. But, I have not been able to make a successful test trigger.
 
Below is the code I have thus far -- 
 
 

OppCount = the field I created for the above purpose.
_____

Class -------
public class incrementHandler
{
    public void onBeforeInsert( list<Opportunity> newList)
    {
        List<Opportunity> lstOpp = [SELECT Id, OppCount__c FROM Opportunity WHERE Createddate = TODAY Order BY OppCount__c DESC LIMIT 1];
        Integer intCounter = lstOpp.isEmpty() ? 0 : Integer.valueOf(lstOpp[0].OppCount__c);
        for(Opportunity objOpportunity: newList)
        {
            intCounter ++;
            objOpportunity.OppCount__c = intCounter;
        }
    }
}


Trigger -------
trigger OpportunityTrigger on Opportunity(before insert) 
{
    incrementHandler objHandler = new incrementHandler();
    if(Trigger.isBefore && Trigger.isInsert)
    {
        objHandler.onBeforeInsert(Trigger.New);
    }
}




Test Class -------
@isTest
private class incrementHandlerTest
{   
    static testMethod void testOnBeforeInsert()
    {
Opportunity one = new Opportunity();
Opportunity two = new Opportunity();
list<Opportunity> newList = new list<Opportunity>();
newList.add(one);
newList.add(two);
new incrementHandler().onBeforeInsert(newList);
Integer diff = Integer.valueOf(two.OppCount__c) - Integer.valueOf(one.OppCount__c);
System.assertEquals(diff, 1, 'expected Opportunity OppCount to differ by 1');

}



Any help is appreciated! :)
I currently have a workflow setup to, on opportunity creation, set the opportunity name via Workflow to update field name to YYYY-MM-DDXX, where 'XX' is the number of opp that has been created on that date within the entire org.

For example:
- If I made an opp right now, and it was the first opp created today, it would be named 2017-08-2201
- If I created another opp right after, the opp name would be 2017-08-2202
- ...and so on
- But, when the clock strikes midnight, the last two numbers would reset, so the first opp created after midnight would be 2017-08-2301

The way I have this workflow setup is through an autonumber field, as such: {YYYY}-{MM}-{DD}{00}. The problem I've run into is that the {00} (in the XX in my first example) does not reset daily so, I have to manually change it to a text field, then back to an autonumber field every morning.

I have never written APEX but, I’ve been trying to give it a shot. From what I understand, I have to have a ‘count field’ on the opportunity to keep track of the number made that day. Is this correct?

 
Either way, below is the code I have thus far --
 
 
OppCount = the field I created for the above purpose.
 
 
public class incrementHandler
{
    public void onInsert( list<Opportunity> newList){
 
    List<Opportunity> lstOpp = [SELECT Id,OppCount FROM Opportunity Order BY Createddate DESC LIMIT 1];
    Integer intCounter = lstOpp.size() != 0 ? lstOpp[0].OppCount : 0;
    for(Opportunity objOpportunity: newList)
    {
        intCounter ++;
        objOpportunity.OppCount = intCounter;
    }
 
    }
}
 
 
Any help is much appreciated!
 
Best!
 
I have a button that creates a Formstack survey, allows a client to fill out information, then writeback to salesforce and updates fields. This has all worked very smooth until a few weeks ago when I started receiving this error:

There was an error creating Opportunity 1. Salesforce error: Id in upsert is not valid

I'm assuming this is in relation to the Opportunity ID but I have no idea how to fix this! Help!

The code for the buttom is as follows: 

https://'company name'.formstack.com/forms/'formname'_scoping_v50 
?OppID={!Opportunity.Id} 
&AcctID={!Opportunity.AccountId} 
&ContactID={!Contact.Id} 
&First+Name={!Contact.FirstName} 
&Last+Name={!Contact.LastName} 
&Title={!Contact.Title} 
&Email={!Contact.Email} 
&Phone={!Contact.Phone} 
&Company={!Account.Name} 
&AcctNameOrig={!Opportunity.Account} 
&OwnerID={!User.Id} 
&Engagement+Focus={!Opportunity.Scoping_Sections__c} 
&Web+Application+name(s)={!Opportunity.SVC_WAPT_NAME__c} 
I have just been asked by management to explore options managing one master opportunity comprised by group of individual opportunities. Today we are managing this individually and currently have no way to tie them together to represent the one opportunity.

I am looking for a way to:
Create one master opportunity
Batch create child opportunity records (designated number)
Roll-up the $ amount of child opportunity records to the $ amount of the master opportunity
Forecast/Report on the master opportunity to reflect open vs. closed as each individual opportunity is closed


Use case:

There is one big project for Acme Telecom that's worth $1M. This is captured in SF.com as 1 opportunity for $1M. This customer has asked that we break out the project in 10 phases and provide 1 quote for each phase. Since we could only have 1 primary quote per opportunity, we would have to create 10 separate opportunities worth $100K per quote.

However, our sales management would like to report/forecast the 1 opportunity. As each quote is booked, the respective opportunity would be closed in SF.com and reflected in the forecasts and reporting. Ultimately, we would end up with $1M of closed opportunities over the course of the FY.

This is scenario starting to occur more frequently and it is becoming a nightmare to manage.

Any ideas?
Hello! 

I would like to implement the velocity of sales equation (as follows) into my salesforce account:

( [number of sales opps you work] x [average deal value] x [win rate] ) / Lengeth of sales cycle

The problem I have run into, to begin, is calculating the length of the sales cycle. To document this we use a multi-picklist that we change from 2-5-10-25-50-75-90-100%. We have had history trcking on this custom field since we made it. But, sometimes an opportunity will fluctuate from 50-90%, back anf forth, a few times. With this, when I use the Opp. History Report and look at the stages it will only tell me how many days since it's been chnaged from the previous stage (whatever that may be) to the current stage. 

My goal, to begin, is to track the number days between 10% and 100% (the FINAL time it is moved to 100%) to get the denominator in the equation.

Then, fromt here I need to be able to calcualte and multiply everything in the numerator. 

Basically, I thnk I need a formula and I have no idea where to start! Help please! 
Howdy!

I currently have a workflow setup to, on opportunity creation, set the opportunity name via Workflow to update field name to YYYY-MM-DDXX, where 'XX' is the number of opp that has been created on that date within the entire org.

For example:
- If I made an opp right now, and it was the first opp created today, it would be named 2017-08-2201
- If I created another opp right after, the opp name would be 2017-08-2202
- ...and so on
- But, when the clock strikes midnight, the last two numbers would reset, so the first opp created after midnight would be 2017-08-2301

The way I have this workflow setup is through an autonumber field, as such: {YYYY}-{MM}-{DD}{00}. The problem I've run into is that the {00} (in the XX in my first example) does not reset daily so, I have to manually change it to a text field, then back to an autonumber field every morning.

I have never written APEX but, I’ve been trying to give it a shot. Via dev forums, I was able to generate a correct class and class test. But, I have not been able to make a successful test trigger.
 
Below is the code I have thus far -- 
 
 

OppCount = the field I created for the above purpose.
_____

Class -------
public class incrementHandler
{
    public void onBeforeInsert( list<Opportunity> newList)
    {
        List<Opportunity> lstOpp = [SELECT Id, OppCount__c FROM Opportunity WHERE Createddate = TODAY Order BY OppCount__c DESC LIMIT 1];
        Integer intCounter = lstOpp.isEmpty() ? 0 : Integer.valueOf(lstOpp[0].OppCount__c);
        for(Opportunity objOpportunity: newList)
        {
            intCounter ++;
            objOpportunity.OppCount__c = intCounter;
        }
    }
}


Trigger -------
trigger OpportunityTrigger on Opportunity(before insert) 
{
    incrementHandler objHandler = new incrementHandler();
    if(Trigger.isBefore && Trigger.isInsert)
    {
        objHandler.onBeforeInsert(Trigger.New);
    }
}




Test Class -------
@isTest
private class incrementHandlerTest
{   
    static testMethod void testOnBeforeInsert()
    {
Opportunity one = new Opportunity();
Opportunity two = new Opportunity();
list<Opportunity> newList = new list<Opportunity>();
newList.add(one);
newList.add(two);
new incrementHandler().onBeforeInsert(newList);
Integer diff = Integer.valueOf(two.OppCount__c) - Integer.valueOf(one.OppCount__c);
System.assertEquals(diff, 1, 'expected Opportunity OppCount to differ by 1');

}



Any help is appreciated! :)
I currently have a workflow setup to, on opportunity creation, set the opportunity name via Workflow to update field name to YYYY-MM-DDXX, where 'XX' is the number of opp that has been created on that date within the entire org.

For example:
- If I made an opp right now, and it was the first opp created today, it would be named 2017-08-2201
- If I created another opp right after, the opp name would be 2017-08-2202
- ...and so on
- But, when the clock strikes midnight, the last two numbers would reset, so the first opp created after midnight would be 2017-08-2301

The way I have this workflow setup is through an autonumber field, as such: {YYYY}-{MM}-{DD}{00}. The problem I've run into is that the {00} (in the XX in my first example) does not reset daily so, I have to manually change it to a text field, then back to an autonumber field every morning.

I have never written APEX but, I’ve been trying to give it a shot. From what I understand, I have to have a ‘count field’ on the opportunity to keep track of the number made that day. Is this correct?

 
Either way, below is the code I have thus far --
 
 
OppCount = the field I created for the above purpose.
 
 
public class incrementHandler
{
    public void onInsert( list<Opportunity> newList){
 
    List<Opportunity> lstOpp = [SELECT Id,OppCount FROM Opportunity Order BY Createddate DESC LIMIT 1];
    Integer intCounter = lstOpp.size() != 0 ? lstOpp[0].OppCount : 0;
    for(Opportunity objOpportunity: newList)
    {
        intCounter ++;
        objOpportunity.OppCount = intCounter;
    }
 
    }
}
 
 
Any help is much appreciated!
 
Best!