• sreelekha
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi,

I have written a trigger.But i want to write a testclass for it can you please help.

trigger triglast on QuoteLineItem (after insert,after update) {
public static double total=0;
Set<Id> qtids=new Set<Id>();
List<opportunity> oppl=new List<opportunity>();
List<Quotelineitem> qlil=new List<Quotelineitem>();
for (QuoteLineItem qli : Trigger.new){
   qtids.add(qli.quoteid);
   qlil.add(qli);
   }
  
   Map<ID, Quote> entries = new Map<ID, Quote>( [select id,totalprice,opportunityid,status__c from Quote where id in :qtids]);
   //system.debug(entries);
   //List<Id> qutids=new List<Id>();
   //qutids.add(entries); 

   List<Quote> quotevalues=new List<Quote>();
   quotevalues=entries.values();
   
  
    Opportunity opp=[select id,amount from opportunity where id =:quotevalues[0].opportunityid];
    for(integer i=0;i<qlil.size();i++)
     {
        total=qlil[i].totalprice+total;
     
     }
        if(quotevalues[0].status__c){
        
         opp.amount=quotevalues[0].totalprice+total;
         
        
        }
        
        oppl.add(opp);
        update oppl;

i have written a trigger for updating the amount field value with quote total price when we selet the quote as primary.but it will work only when we adding single quotelinitem to the quote.When i am trying bulky quotelineitems at a time it will throw an exception " Apex trigger qlitem123 caused an unexpected exception, contact your administrator: qlitem123: execution of AfterInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.qlitem123: line 3, column 28  "

 

my code is here:please help me to solve this problem

 

 

trigger qlitem123 on QuoteLineItem (after insert, after update) {
         public static double total=0;
         quotelineitem qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
         List<QuoteLineItem> qlil=new List<Quotelineitem>();
          qlil.add(qli);
         quote q=[select id,opportunityid,totalprice,stage__c from quote where id=:qli.quoteid];
         
         opportunity opp=[select id,amount from opportunity where id=:q.opportunityid];
         List<opportunity> oppl=new List<opportunity>();
         
         for(integer i=0;i<qlil.size();i++)
          {
           
             total=total+qlil[i].totalprice;
          
          }
          if(q.stage__c=='primary')
          {
            opp.amount=q.totalprice+total;
           
          }
          oppl.add(opp);
          update oppl;
}

 Thanks 

 Sreelekha

Problem:    Multiple quotes per opportunity – Reps will be able to have multiple quotes attached to each opportunity.  They will be allowed to designate which quote will be the ‘primary’ quote and that primary quote will pass it’s pricing to the opportunity.  The opportunity amount will only reflect the primary quote’s pricing.

 

For that I have written a trigger to pass the 'primary quote' total price to the opportunity amount field.It is working for it.

But when i adding the product from opportunity detail page then amount field of opportunity becomes read only.But i want to pass the total price of quote to the amount field .Is there any possibility to do this.can any one reply me please.

Hi,

I have created a vf page with two pageblocks .

One "pageBlock" contains "inputText" fields with Save Button.Other Contains a pageBlock table with "Edit" link in each row.

Here when i  click on "Save" button then it is saved to database and automatically updated in the below "PageBlock Table" in the same page.

Now i have the requirement,

when i click on "Edit" link on the particular row of the "PageBlockTable" then automatically the values of each cell of table set to respected "inPutText" fields in the above "PageBlock".

can any one reply me please?

i have written a trigger for updating the amount field value with quote total price when we selet the quote as primary.but it will work only when we adding single quotelinitem to the quote.When i am trying bulky quotelineitems at a time it will throw an exception " Apex trigger qlitem123 caused an unexpected exception, contact your administrator: qlitem123: execution of AfterInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.qlitem123: line 3, column 28  "

 

my code is here:please help me to solve this problem

 

 

trigger qlitem123 on QuoteLineItem (after insert, after update) {
         public static double total=0;
         quotelineitem qli=[select id,quoteid,totalprice from quotelineitem where id in:Trigger.newMap.keyset()];
         List<QuoteLineItem> qlil=new List<Quotelineitem>();
          qlil.add(qli);
         quote q=[select id,opportunityid,totalprice,stage__c from quote where id=:qli.quoteid];
         
         opportunity opp=[select id,amount from opportunity where id=:q.opportunityid];
         List<opportunity> oppl=new List<opportunity>();
         
         for(integer i=0;i<qlil.size();i++)
          {
           
             total=total+qlil[i].totalprice;
          
          }
          if(q.stage__c=='primary')
          {
            opp.amount=q.totalprice+total;
           
          }
          oppl.add(opp);
          update oppl;
}

 Thanks 

 Sreelekha

Hi,

I have created a vf page with two pageblocks .

One "pageBlock" contains "inputText" fields with Save Button.Other Contains a pageBlock table with "Edit" link in each row.

Here when i  click on "Save" button then it is saved to database and automatically updated in the below "PageBlock Table" in the same page.

Now i have the requirement,

when i click on "Edit" link on the particular row of the "PageBlockTable" then automatically the values of each cell of table set to respected "inPutText" fields in the above "PageBlock".

can any one reply me please?

Hi,

 

Iam  new to Apex.I have  custom objects Order and Order Line Items (master detail).The order line items appears as a related list under the Order object.

 

Whenever an order is created from the quote,the quoteline items should be inserted as order line items ....This functionality is just like how the opportunity products are inserted as quote line items whenever a new quote is created from the opportunity.

 

Is it possible to do this using a trigger?

 

If yes ,can i please have some pointers to any sample trigger code that does this kind of insert from a related list of the master object to the related list of the detail object

 

Thanks!