• KarenC
  • NEWBIE
  • 0 Points
  • Member since 2011

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



I don't know java, however, I received some help and wrote a button to clone a quote...see revise button below..

Here is the code behind the button:  

 

 

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}result = sforce.connection.query("select id,opportunityid from Quote where id = '{!Quote.Id}'")window.top.location.href =    "{!URLFOR( $Action.Quote.NewQuote ,null,[clone=1,id=Quote.Id,retURL="/"&Quote.Id],true)}&oppid=" +result.records.OpportunityId +"&00N60000001rya1=1&00N60000001rtxU={!Quote.Version__c+1}"

 

When the insert on the cloned quote is done a before insert trigger is fired.  The purpose of the trigger is to find the max revision number within a quote within an opportunity and then increment the revision number by one.

 

The trigger works fine as long as I have all the fields displayed on the screen below.  The weird part is once I remove some of these fields from the page layout the trigger no longer works.  I don't want to leave the fields (such as revision_chkbox__c) as these fields are behind the scene fields as switches.  

 

Sorry for long post -

 

Please advise,,,,I am banging my head against the wall....

 

 
trigger quoteversioning on Quote (before insert) {
    Quote q;
    for (quote insertedquote : Trigger.new) {
        if (insertedquote.revision_chkbox__c == true) {
            q = [select version__c from quote
                where quote_number_test__c = :insertedquote.quote_number_test__c and
                      opportunityid = :insertedquote.opportunityid
                order by version__c desc
                limit 1];
            insertedquote.version__c = q.version__c + 1;
        }
    }
}
  • October 09, 2011
  • Like
  • 0

I don't know java, however, I received some help and wrote a button to clone a quote...see revise button below..

Here is the code behind the button:  

 

 

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}result = sforce.connection.query("select id,opportunityid from Quote where id = '{!Quote.Id}'")window.top.location.href =    "{!URLFOR( $Action.Quote.NewQuote ,null,[clone=1,id=Quote.Id,retURL="/"&Quote.Id],true)}&oppid=" +result.records.OpportunityId +"&00N60000001rya1=1&00N60000001rtxU={!Quote.Version__c+1}"

 

When the insert on the cloned quote is done a before insert trigger is fired.  The purpose of the trigger is to find the max revision number within a quote within an opportunity and then increment the revision number by one.

 

The trigger works fine as long as I have all the fields displayed on the screen below.  The weird part is once I remove some of these fields from the page layout the trigger no longer works.  I don't want to leave the fields (such as revision_chkbox__c) as these fields are behind the scene fields as switches.  

 

Sorry for long post -

 

Please advise,,,,I am banging my head against the wall....

 

 
trigger quoteversioning on Quote (before insert) {
    Quote q;
    for (quote insertedquote : Trigger.new) {
        if (insertedquote.revision_chkbox__c == true) {
            q = [select version__c from quote
                where quote_number_test__c = :insertedquote.quote_number_test__c and
                      opportunityid = :insertedquote.opportunityid
                order by version__c desc
                limit 1];
            insertedquote.version__c = q.version__c + 1;
        }
    }
}
  • October 09, 2011
  • Like
  • 0

Hi -

 

I am using an aggregate function for the first time and need help!

I need to find the max(version__C) from the quotes table then increment it by 1.

 

I understand that the results of an aggregate returns an array of AggregateResult objects. AggregateResultis a read-only sObject and is only used for query results.

 

How can I increment it.  I tried converting it to an integer and then adding 1 - but I am getting a run time error of:

 

System.NullPointerException: Attempt to de-reference a null object: Trigger.quoteversioning: line 16, column 34

 

It points to the "i" variable in the statement : insertedquote.version__C = i + 1;

 

Thanks for your help!!!

 

trigger quoteversioning on Quote (before insert) {

integer i;

for (quote insertedquote : system.Trigger.new)
    {
    if (insertedquote.revision_chkbox__c == true)
      {
      AggregateResult[] groupedresults = [select max(version__c) maxversion from quote
                        where quotenumber = :insertedquote.quotenumber
                        and opportunityid = :insertedquote.opportunityid];
      object maxrev = groupedresults[0].get('maxversion');
      
      i=integer.valueof(maxrev);
         
      insertedquote.version__C = i + 1;
      }
    }
}
  • October 07, 2011
  • Like
  • 0

Hi - 

 

I am writing a basic apex trigger to update a quote revision number.  I need to select the max version number within a quote, within an opportunity.

 

I get an unexpected token on the red line below.  The revision? field is a custom checkbox field in the quote table.

 

Thanks for your help!!!

 

 

 

trigger quoteversioning on Quote (before insert) {
for (quote insertedquote : system.Trigger.new)   

  {   

 

   if (insertedquote.revision?)

      {      quote QT = [select max(version__c) from quote

                        where quotenumber = :insertedquote.quotenumber                       

                        and opportunity = :insertedquote.opportunity];

 

               insertedquote.version__C = QT.version__c + 1;     

     }   

  }

}


  • October 06, 2011
  • Like
  • 0

Was wondering if someone has successfully accomplished cloning a quote and the related quote line items?  I need it to create a new quote revision without creating a whole new quote with new quote number...just a new revision number.

 

I am struggling and thought that this task has probaly been done by someone "out there"...

 

I appreciate your help!!

  • September 14, 2011
  • Like
  • 0

Hi -

 

I am using an aggregate function for the first time and need help!

I need to find the max(version__C) from the quotes table then increment it by 1.

 

I understand that the results of an aggregate returns an array of AggregateResult objects. AggregateResultis a read-only sObject and is only used for query results.

 

How can I increment it.  I tried converting it to an integer and then adding 1 - but I am getting a run time error of:

 

System.NullPointerException: Attempt to de-reference a null object: Trigger.quoteversioning: line 16, column 34

 

It points to the "i" variable in the statement : insertedquote.version__C = i + 1;

 

Thanks for your help!!!

 

trigger quoteversioning on Quote (before insert) {

integer i;

for (quote insertedquote : system.Trigger.new)
    {
    if (insertedquote.revision_chkbox__c == true)
      {
      AggregateResult[] groupedresults = [select max(version__c) maxversion from quote
                        where quotenumber = :insertedquote.quotenumber
                        and opportunityid = :insertedquote.opportunityid];
      object maxrev = groupedresults[0].get('maxversion');
      
      i=integer.valueof(maxrev);
         
      insertedquote.version__C = i + 1;
      }
    }
}
  • October 07, 2011
  • Like
  • 0

Hi - 

 

I am writing a basic apex trigger to update a quote revision number.  I need to select the max version number within a quote, within an opportunity.

 

I get an unexpected token on the red line below.  The revision? field is a custom checkbox field in the quote table.

 

Thanks for your help!!!

 

 

 

trigger quoteversioning on Quote (before insert) {
for (quote insertedquote : system.Trigger.new)   

  {   

 

   if (insertedquote.revision?)

      {      quote QT = [select max(version__c) from quote

                        where quotenumber = :insertedquote.quotenumber                       

                        and opportunity = :insertedquote.opportunity];

 

               insertedquote.version__C = QT.version__c + 1;     

     }   

  }

}


  • October 06, 2011
  • Like
  • 0

Was wondering if someone has successfully accomplished cloning a quote and the related quote line items?  I need it to create a new quote revision without creating a whole new quote with new quote number...just a new revision number.

 

I am struggling and thought that this task has probaly been done by someone "out there"...

 

I appreciate your help!!

  • September 14, 2011
  • Like
  • 0