• TC Admin
  • NEWBIE
  • 45 Points
  • Member since 2015
  • System Integration Administrator
  • Litebulb Group

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 14
    Replies
Hi All,
I have created the below code for a trigger that once an opportuntiylineitem is added, edited, deleted or undelted it SUM() the total of all product ids on opportuntilineitems as a particular status.

However I get the below error when you try to update an opportunitylineitem in Salesforce:
LookupRollup: execution of AfterUpdate caused by: System.ListException: Row with null Id at index: 0 Trigger.LookupRollup: line 11, column 1

This is my code for the trigger:
trigger LookupRollup on OpportunityLineItem (after insert,after update, after delete,after undelete) {

     //Declare Variables
    List<Product2> ProductIDs = new List<Product2>();

	//Get list of all product codes on unprocessed orders
    ProductIDs = [ SELECT id,Other_Details__c
							FROM Product2 ];

	//map productid to totals on orders
	MAP<id,AggregateResult > ProductTotal = new MAP<id,AggregateResult >(
        	[SELECT Product2Id,SUM(NUMBER_OF_UNITS__c)vol
			FROM OpportunityLineItem 
			WHERE (Opportunity.Sage_Status__c like 'Processing%' 
			OR Opportunity.Sage_Status__c like 'Despatched%')
             GROUP BY Product2Id]) ;
    
	//Update to product
	FOR (Product2 pt : ProductIds) {
        STRING OnOrderTotal = string.ValueOf(ProductTotal.get(pt.id));
		pt.Other_details__C = OnOrderTotal;
		UPSERT pt;
	}

	}

Any ideas?
Hi All,

I hope someone can help. I'm trying to change the font and font size WITHIN a related list on an S-Doc.  I have managed to change the table headers, footer etc but I cannot see where I change hte font of the results of the related list.

This is what It currently looks like
User-added imageThis is the code on the table:
<!-- ******************** RELATED LIST SECTION UNIQUEID:46********************-->
<style type="text/css">table.table46 {border:none; border-collapse:collapse; border-spacing:0px;font-family:Verdana, Geneva, sans-serif; font-size:10pt; width:100% }
.table46header {text-align:center;font-weight:bold;border:none;color:#FFFFFF;background-color:#FF8200;}
.table46footer {text-align:right;font-weight:bold;border:none; height: 30px}
.table46RowEven{border-top:none ;border-bottom:none;}
.table46RowOdd{border-top:none ;border-bottom:none;}
.table46col0{border-top:none ;border-bottom:none;border-left:none;text-align:left;}
.table46col1{border-top:none ;border-bottom:none;text-align:left;}
.table46col2{border-top:none ;border-bottom:none;text-align:left;}
.table46col3{border-top:none ;border-bottom:none;text-align:left;}
.table46col4{border-top:none ;border-bottom:none;text-align:left;}
.table46col5{border-top:none ;border-bottom:none;text-align:left;}
</style>
<table align="left" class="table46">
	<tbody>
		<tr>
			<th class="table46header"><span style="font-size:11px;"><span style="font-family:verdana,geneva,sans-serif;">Product Code</span></span></th>
			<th class="table46header"><span style="font-size:11px;"><span style="font-family:verdana,geneva,sans-serif;">Item Description</span></span></th>
			<th class="table46header"><span style="font-size:11px;"><span style="font-family:verdana,geneva,sans-serif;">Quantity</span></span></th>
			<th class="table46header"><span style="font-size:11px;"><span style="font-family:verdana,geneva,sans-serif;">Unit MRSP</span></span></th>
			<th class="table46header"><span style="font-size:11px;"><span style="font-family:verdana,geneva,sans-serif;">Extended Cost</span></span></th>
			<th class="table46header"><span style="font-size:11px;"><span style="font-family:verdana,geneva,sans-serif;">Extended Cost</span></span></th>
		</tr>
		<!--{{!
<lineitems><class>table46</class>
<listname>opportunitylineitems</listname>
<column>PricebookEntry.Product2.productcode</column>
<column>PricebookEntry.Product2.name</column>
<column format-number="######" >quantity</column>
<column format-number="###.##" >PricebookEntry.Product2.rrp__c</column>
<column format-number="######.##" >gross_sale_for_opp__c</column>
<column format-number="######.##" >gross_sale_for_opp__c</column>
</lineitems>
}}-->
	</tbody>
</table>
<!-- ******************** END RELATED LIST SECTION UNIQUEID:46********************--><br />

Any ideas?
Hi all. i'm trying to create a button that refreshes the child opportunity products when discounts are changed on a opportunity.

The Apex code ges a list of the child opportunity products and updates them.
The Visual Force button runs the method. howveer i get an error saying:

Attempt to de-reference a null object 
An unexpected error has occurred. Your development organization has been notified.


Any idea what I am doing wrong?
Apex Class
PUBLIC CLASS OpportunityProductCostRefreshController 
{
    //add an instance variable for the standard controller
    private ApexPages.StandardController controller {get; set;}
    
    // add the instance for the variables being passed by id on the url
    public opportunity OP {get;set;}
    
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}
    
    //Add the variable for the list being queried
    PUBLIC LIST <OpportunityLineItem> GetItemsList {get;set;}   

    // Initialize the controller
    PUBLIC OpportunityProductCostRefreshController(ApexPages.StandardController ctrl)
    {     
        //initialize the standard controller
        this.controller = controller;
        // load the current record
        OP = (Opportunity)controller.getRecord();
    }

    // method called from the VF's action attribute to refreshing the op lines
    public PageReference RefreshOpLines() 
    {
    
        // setup the save point for rollback
        Savepoint sp = Database.setSavepoint();

        TRY
        {
        // Get the list of opportunity line items we want to refresh costs for
        GetItemsList = [
            SELECT Id,OpportunityId, productcode, Quantity, unitprice
            FROM OpportunityLineItem OPL
            WHERE       Opportunityid= :OP.id ORDER BY  productcode ASC
            ];
            {
            UPDATE GetItemsList ;
            return null;
            }
        }
        catch (Exception e){
         // roll everything back in case of error
        Database.rollback(sp);
        ApexPages.addMessages(e);

        }
            
        return new PageReference('/'+OP.id);
    }
}

VF Page
<apex:page standardController="Opportunity"
     extensions="OpportunityProductCostRefreshController"
     action="{!RefreshOpLines}">
     <apex:pageMessages />
</apex:page>

​​​​​​​
Hi All, I have a Apex class and VF Button that Clones an opportunity while overwritting certian fields.

Before lightening the user would be re-directed to their newly created opportunity after they press save on the edit page.
However since Lighting have taken away teh URL hacking it does not work.
Original URL hack:
return new PageReference('/'+newOP.id+'/e?retURL=%2F'+newOP.id);

I have dones some research and found I can use the below code however this BYPASSES the edit screen and takes them directly to the new cloned opportunity. meaning people cannot edit the new clone before actually saving.
return new PageReference('https://cs109.lightning.force.com/'+newOP.id);

Any ideas how I can combine the two so that when the user presses "Clone with items" They are taken to an edit screen. Once they press send they are taken to to newly created clone not just a blank page?
Hi, I'm struggling to write a test class that has over 75% code coverage. I currently only have 57% since adding an override to the save button.
Before the save button I have 82%.
I thought I just needed to add the save method to the class but obviously not. Any help would be hugly welcome.

APEX CLASS CONTROLLER
PUBLIC CLASS TimeSheetEditAllItemsList {
PUBLIC LIST <Time_sheet_items__c> GetItemsList {get;set;}
PUBLIC TimeSheetEditAllItemsList(ApexPages.StandardController ctrl){ 
 GetItemsList = [
        SELECT Id,Time_Sheet__c,D_Product_Manager__c,D_Type__c,D_Project__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,
Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
        FROM Time_Sheet_Items__c 
        WHERE       Time_Sheet__c= : ctrl.getId() ORDER BY  id ASC
        ];
    }
    public pageReference save(){
        UPSERT GetItemsList ;
        return null;
}
}

 

TEST CLASS
@isTest

Private class TestClassTimeSheetEditAllItemsList {

    static testMethod void GetItemsList() {
        
        // create new TS record to test against
        Time_Sheet__C TS = new Time_Sheet__c();
        TS.Time_sheet_week_ending__C = date.Newinstance (2016,06,06);
        TS.Employee__C ='a0Gb000000Cm6OHEAZ';
        insert TS;

        // create a line item for the TS to test against
        Time_Sheet_Items__c TSi = new TIme_Sheet_Items__c();
        TSi.D_project__C ='011 GFX';
        TSi.D_Type__c = '05 Editorial';
        TSi.Time_Sheet__c =TS.Id;
        TSi.RecordTypeid ='012b00000009cosAAA';
        insert TSi;

        // Construct the standard controller
        ApexPages.StandardController con = new ApexPages.StandardController(TS);
        
         // create the controller
        TimeSheetEditAllItemsList ext = new TimeSheetEditAllItemsList(con);
        
        //Start the test
         Test.startTest();
         
        // Check that Time sheets created and can query data with items lines
        Time_Sheet_Items__c TSiL=[
                    SELECT Id,Time_Sheet__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
                    FROM Time_Sheet_Items__c 
                    ];
		// Check the save works
		con.save();
        // Check it ran
        System.assert(TSiL!=null);   
        
        // Stop test
        Test.stopTest();
    }

}

I have the below visual force page that displays a table of the time sheet itesm on a time sheet.
However if you try to press save i get " ERROR: There is no record to save"

Any ideas what i'm missing?

VisualForce page:
<apex:page standardController="Time_Sheet__c" extensions="TimeSheetEditAllItemsList"> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!GetItemsList}" var="TSi"> <apex:column style="width:5%" value="{!TSi.D_Project__c}"/> <apex:column style="width:5%" value="{!TSi.D_Type__c}"/> <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/> <apex:column style="width:5%" headerValue="Monday"> <apex:inputField value="{!TSi.Day_Monday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Tuesday"> <apex:inputField value="{!TSi.Day_Tuesday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Wednesday"> <apex:inputField value="{!TSi.Day_Wednesday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Thursday"> <apex:inputField value="{!TSi.Day_Thursday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Friday"> <apex:inputField value="{!TSi.Day_Friday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Weekend"> <apex:inputField value="{!TSi.Day_Weekend__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

Apex Class:
PUBLIC CLASS TimeSheetEditAllItemsList {
PUBLIC LIST <Time_sheet_items__c> GetItemsList {get;set;}
PUBLIC TimeSheetEditAllItemsList(ApexPages.StandardController ctrl){ 
 GetItemsList = [
        SELECT Id,Time_Sheet__c,D_Product_Manager__c,D_Type__c,D_Project__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
        FROM Time_Sheet_Items__c 
        WHERE       Time_Sheet__c= : ctrl.getId() ORDER BY  id ASC
        ];
    }
}

ERROR:
Error upon save button
Hi All, Sorry I'm quit new to Apex coding and I'm sure the answer is staring my in the face.
 have an Apex Class that clones an opportunity with items. When the user clicks "Clone" the VisualForece page button action takes them to an edit screen which is perfect. However once the users Saves the new record it takes them to a blank screen, see below:
New record saved

How can I change my code so that once the users presses "Save" they are taken to the new record created?

I have been working with code from the below post:
https://blog.jeffdouglas.com/2009/11/19/apex-deep-clone-controller/ 



Apex Class
public class OpportunityCloneWithItemsController {

     //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    private opportunity OP {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}

    // initialize the controller
    public OpportunityCloneWithItemsController(ApexPages.StandardController controller) {

        //initialize the standard controller
        this.controller = controller;
        // load the current record
        OP = (Opportunity)controller.getRecord();

    }

    // method called from the VF's action attribute to clone the OP
    public PageReference cloneWithItems() {

         // setup the save point for rollback
         Savepoint sp = Database.setSavepoint();
         Opportunity newOP;

         try {

              //copy the Opportunity - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             OP = [select Id,
                          Accountid,
                          CloseDate,
                          Promised_Delivery_Date__c,
                          Requested_Delivery_Date__c,
                          Description,
                          DocType__C,
                          CurrencyIsoCode,
                          Name,
                          Ownerid,
                          RecordTypeid,
                          Pricebook2id,
                          Campaignid,
                          Probability,
                          StageName,
                          warehouse__c,
                          Delivery_Address_if_diff_from_main_add__c,
                          Invoice_type__c,
                          Type,
                          A6_Combined_Discount__c,
                          A6_Total_Trade_Disc__c,
                          A6_Contributions_and_Provisions__c,
                          O1_2_return_reason__c,
                          Sale_Or_Return_Record__c
                    from Opportunity where id = :OP.id];
             newOP = OP.clone(false);
             newOP.Date_sent_to_warehouse__c = NULL;
             newOP.Sage_status__c ='Not Ready';
             insert newOP;

             // set the id of the new op created for testing
               newRecordId = newOP.id;

             // copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             List<OpportunityLineItem> items = new List<OpportunityLineItem>();
             for (OpportunityLineItem OPL : [Select OL.Id, OL.UnitPrice, OL.Quantity, OL.opportunityid, OL.pricebookentryid From OpportunityLineItem OL where Opportunityid = :OP.id]) {
                  OpportunityLineItem newOPL = OPL.clone(false);
                  newOPL.OpportunityId = newOP.id;
                  items.add(newOPL);
             }
             insert items;

         } catch (Exception e){
             // roll everything back in case of error
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
         }

        return new PageReference('/'+newOP.id+'/e?retURL=%2F'+newOP.id);
    }

}

VisualForce Page
<apex:page standardController="Opportunity" extensions="OpportunityCloneWithItemsController" action="{!cloneWithItems}"> <apex:pageMessages /> </apex:page> 
I have a VF page that gets  child records for a custom object master record and displays in an editable grid format.

However once I press "Save" i get the below error:
Error: There is no record to save

I'm guessing this is becasue the button triggers from the master object but the page controller uses the child records however if I switch the controller and page to be a related list the controller no longer works.

Controller:
public class EditAllButtonForTimeSheetController {

    public EditAllButtonForTimeSheetController(ApexPages.StandardController controller) {

    }

  public String TSRecordId        {get; set;}

  public List<Time_Sheet_Items__c> getTimeSheetRecords()
     {
    
       //Sets Time Shet id to variable
       TSRecordId = ApexPages.CurrentPage().getparameters().get('id');

        // this query needs a where clause, don't leave it unbounded
        List<Time_sheet_Items__C> TimeSheetRecords = 
         [SELECT Id,
            Time_Sheet__c,
            D_Type__c,
            D_Product_manager__c,
            D_Project__c,
            Day_Monday__c,
            Day_Tuesday__c,
            Day_Wednesday__c,
            Day_Thursday__c,
            Day_Friday__c,
            Day_Weekend__c
       FROM Time_Sheet_Items__c 
       WHERE Time_sheet__c = :TSRecordId  ];
    return TimeSheetRecords;
    }
}



VF Page:

<apex:page standardController="Time_Sheet__c"
         Extensions="EditAllButtonForTimeSheetController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save"
                            action="{!save}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!TimeSheetRecords}"
                           var="TSi">
        <apex:column style="width:5%" value="{!TSi.D_Project__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Type__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/>
    <apex:column style="width:5%" headerValue="Monday">
          <apex:inputField value="{!TSi.Day_Monday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Tuesday">
          <apex:inputField value="{!TSi.Day_Tuesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Wednesday">
          <apex:inputField value="{!TSi.Day_Wednesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Thursday">
          <apex:inputField value="{!TSi.Day_Thursday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Friday">
          <apex:inputField value="{!TSi.Day_Friday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Weekend">
          <apex:inputField value="{!TSi.Day_Weekend__c}"/>
        </apex:column>
      </apex:pageBlockTable>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

                

 
Hi all,

I'm trying to write a related list button on a master record that opens a table that you can edit certain fields of the masters child records.

My visual force page works but gets ALL child records in the system not just those relating to the master record I am on.

My Apex coding is:

public class EditAllButtonForTimeSheetController
{
    //This will store the Id from the URL i.e., the Id of the Record that belongs to the Master Object
    public String TSRecordId        {get; set;}
    public List<Time_Sheet_Items__c> TSiRecords  {get; set;}
    public Time_Sheet__c TSRecord                 {get; set;}
    //Constructor. This would build everything for our VF Page.
    public EditAllButtonForTimeSheetController()
    {
        TSRecordId = ApexPages.CurrentPage().getparameters().get('id');

        //Make sure we have the Id in the URL
        if(!String.isBlank(TSRecordId)){

            //Fetch the Time Sheet Record Details
            TSRecord =
            [SELECT ID,Name,Time_Sheet_Week_Ending__c FROM Time_Sheet__c WHERE Id = :TSRecordId ];

            //Fetch all the Time_Sheet_Items Records with respect to the Time_sheet Record. 
        //Note: Child_To_Parent_Lookup__c  is Lookup/M-D field on my Child SObject to the Parent – Master
            TSiRecords =
                [SELECT Id,Time_Sheet__c,D_Type__c,D_Product_manager__c,D_Project__c,
        Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c
                FROM TIme_Sheet_Items__c WHERE Time_sheet_ID__c = :TSRecordId ];
                
        }
    }
}


VF PAGE

<apex:page standardController="Time_Sheet_Items__c"
              Extensions="EditAllButtonForTimeSheetController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save"
                            action="{!save}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!Time_Sheet_Items__c}"
                           var="TSi">
        <apex:column style="width:5%" value="{!TSi.D_Project__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Type__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/>
    <apex:column style="width:5%" headerValue="Monday">
          <apex:inputField value="{!TSi.Day_Monday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Tuesday">
          <apex:inputField value="{!TSi.Day_Tuesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Wednesday">
          <apex:inputField value="{!TSi.Day_Wednesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Thursday">
          <apex:inputField value="{!TSi.Day_Thursday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Friday">
          <apex:inputField value="{!TSi.Day_Friday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Weekend">
          <apex:inputField value="{!TSi.Day_Weekend__c}"/>
        </apex:column>
      </apex:pageBlockTable>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

Any help would be great.
Hi All,

I was wondering if its possible to create a customer button that work like the "Edit All" button but instead allows you to actually replace products for new codes in the pricebook without having to delete the products from the opportunity?

 
Hi All,
I have created the below code for a trigger that once an opportuntiylineitem is added, edited, deleted or undelted it SUM() the total of all product ids on opportuntilineitems as a particular status.

However I get the below error when you try to update an opportunitylineitem in Salesforce:
LookupRollup: execution of AfterUpdate caused by: System.ListException: Row with null Id at index: 0 Trigger.LookupRollup: line 11, column 1

This is my code for the trigger:
trigger LookupRollup on OpportunityLineItem (after insert,after update, after delete,after undelete) {

     //Declare Variables
    List<Product2> ProductIDs = new List<Product2>();

	//Get list of all product codes on unprocessed orders
    ProductIDs = [ SELECT id,Other_Details__c
							FROM Product2 ];

	//map productid to totals on orders
	MAP<id,AggregateResult > ProductTotal = new MAP<id,AggregateResult >(
        	[SELECT Product2Id,SUM(NUMBER_OF_UNITS__c)vol
			FROM OpportunityLineItem 
			WHERE (Opportunity.Sage_Status__c like 'Processing%' 
			OR Opportunity.Sage_Status__c like 'Despatched%')
             GROUP BY Product2Id]) ;
    
	//Update to product
	FOR (Product2 pt : ProductIds) {
        STRING OnOrderTotal = string.ValueOf(ProductTotal.get(pt.id));
		pt.Other_details__C = OnOrderTotal;
		UPSERT pt;
	}

	}

Any ideas?
Hi all. i'm trying to create a button that refreshes the child opportunity products when discounts are changed on a opportunity.

The Apex code ges a list of the child opportunity products and updates them.
The Visual Force button runs the method. howveer i get an error saying:

Attempt to de-reference a null object 
An unexpected error has occurred. Your development organization has been notified.


Any idea what I am doing wrong?
Apex Class
PUBLIC CLASS OpportunityProductCostRefreshController 
{
    //add an instance variable for the standard controller
    private ApexPages.StandardController controller {get; set;}
    
    // add the instance for the variables being passed by id on the url
    public opportunity OP {get;set;}
    
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}
    
    //Add the variable for the list being queried
    PUBLIC LIST <OpportunityLineItem> GetItemsList {get;set;}   

    // Initialize the controller
    PUBLIC OpportunityProductCostRefreshController(ApexPages.StandardController ctrl)
    {     
        //initialize the standard controller
        this.controller = controller;
        // load the current record
        OP = (Opportunity)controller.getRecord();
    }

    // method called from the VF's action attribute to refreshing the op lines
    public PageReference RefreshOpLines() 
    {
    
        // setup the save point for rollback
        Savepoint sp = Database.setSavepoint();

        TRY
        {
        // Get the list of opportunity line items we want to refresh costs for
        GetItemsList = [
            SELECT Id,OpportunityId, productcode, Quantity, unitprice
            FROM OpportunityLineItem OPL
            WHERE       Opportunityid= :OP.id ORDER BY  productcode ASC
            ];
            {
            UPDATE GetItemsList ;
            return null;
            }
        }
        catch (Exception e){
         // roll everything back in case of error
        Database.rollback(sp);
        ApexPages.addMessages(e);

        }
            
        return new PageReference('/'+OP.id);
    }
}

VF Page
<apex:page standardController="Opportunity"
     extensions="OpportunityProductCostRefreshController"
     action="{!RefreshOpLines}">
     <apex:pageMessages />
</apex:page>

​​​​​​​
Hi All, I have a Apex class and VF Button that Clones an opportunity while overwritting certian fields.

Before lightening the user would be re-directed to their newly created opportunity after they press save on the edit page.
However since Lighting have taken away teh URL hacking it does not work.
Original URL hack:
return new PageReference('/'+newOP.id+'/e?retURL=%2F'+newOP.id);

I have dones some research and found I can use the below code however this BYPASSES the edit screen and takes them directly to the new cloned opportunity. meaning people cannot edit the new clone before actually saving.
return new PageReference('https://cs109.lightning.force.com/'+newOP.id);

Any ideas how I can combine the two so that when the user presses "Clone with items" They are taken to an edit screen. Once they press send they are taken to to newly created clone not just a blank page?
Hi, I'm struggling to write a test class that has over 75% code coverage. I currently only have 57% since adding an override to the save button.
Before the save button I have 82%.
I thought I just needed to add the save method to the class but obviously not. Any help would be hugly welcome.

APEX CLASS CONTROLLER
PUBLIC CLASS TimeSheetEditAllItemsList {
PUBLIC LIST <Time_sheet_items__c> GetItemsList {get;set;}
PUBLIC TimeSheetEditAllItemsList(ApexPages.StandardController ctrl){ 
 GetItemsList = [
        SELECT Id,Time_Sheet__c,D_Product_Manager__c,D_Type__c,D_Project__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,
Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
        FROM Time_Sheet_Items__c 
        WHERE       Time_Sheet__c= : ctrl.getId() ORDER BY  id ASC
        ];
    }
    public pageReference save(){
        UPSERT GetItemsList ;
        return null;
}
}

 

TEST CLASS
@isTest

Private class TestClassTimeSheetEditAllItemsList {

    static testMethod void GetItemsList() {
        
        // create new TS record to test against
        Time_Sheet__C TS = new Time_Sheet__c();
        TS.Time_sheet_week_ending__C = date.Newinstance (2016,06,06);
        TS.Employee__C ='a0Gb000000Cm6OHEAZ';
        insert TS;

        // create a line item for the TS to test against
        Time_Sheet_Items__c TSi = new TIme_Sheet_Items__c();
        TSi.D_project__C ='011 GFX';
        TSi.D_Type__c = '05 Editorial';
        TSi.Time_Sheet__c =TS.Id;
        TSi.RecordTypeid ='012b00000009cosAAA';
        insert TSi;

        // Construct the standard controller
        ApexPages.StandardController con = new ApexPages.StandardController(TS);
        
         // create the controller
        TimeSheetEditAllItemsList ext = new TimeSheetEditAllItemsList(con);
        
        //Start the test
         Test.startTest();
         
        // Check that Time sheets created and can query data with items lines
        Time_Sheet_Items__c TSiL=[
                    SELECT Id,Time_Sheet__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
                    FROM Time_Sheet_Items__c 
                    ];
		// Check the save works
		con.save();
        // Check it ran
        System.assert(TSiL!=null);   
        
        // Stop test
        Test.stopTest();
    }

}

I have the below visual force page that displays a table of the time sheet itesm on a time sheet.
However if you try to press save i get " ERROR: There is no record to save"

Any ideas what i'm missing?

VisualForce page:
<apex:page standardController="Time_Sheet__c" extensions="TimeSheetEditAllItemsList"> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!GetItemsList}" var="TSi"> <apex:column style="width:5%" value="{!TSi.D_Project__c}"/> <apex:column style="width:5%" value="{!TSi.D_Type__c}"/> <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/> <apex:column style="width:5%" headerValue="Monday"> <apex:inputField value="{!TSi.Day_Monday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Tuesday"> <apex:inputField value="{!TSi.Day_Tuesday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Wednesday"> <apex:inputField value="{!TSi.Day_Wednesday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Thursday"> <apex:inputField value="{!TSi.Day_Thursday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Friday"> <apex:inputField value="{!TSi.Day_Friday__c}"/> </apex:column> <apex:column style="width:5%" headerValue="Weekend"> <apex:inputField value="{!TSi.Day_Weekend__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

Apex Class:
PUBLIC CLASS TimeSheetEditAllItemsList {
PUBLIC LIST <Time_sheet_items__c> GetItemsList {get;set;}
PUBLIC TimeSheetEditAllItemsList(ApexPages.StandardController ctrl){ 
 GetItemsList = [
        SELECT Id,Time_Sheet__c,D_Product_Manager__c,D_Type__c,D_Project__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c 
        FROM Time_Sheet_Items__c 
        WHERE       Time_Sheet__c= : ctrl.getId() ORDER BY  id ASC
        ];
    }
}

ERROR:
Error upon save button
Hi All, Sorry I'm quit new to Apex coding and I'm sure the answer is staring my in the face.
 have an Apex Class that clones an opportunity with items. When the user clicks "Clone" the VisualForece page button action takes them to an edit screen which is perfect. However once the users Saves the new record it takes them to a blank screen, see below:
New record saved

How can I change my code so that once the users presses "Save" they are taken to the new record created?

I have been working with code from the below post:
https://blog.jeffdouglas.com/2009/11/19/apex-deep-clone-controller/ 



Apex Class
public class OpportunityCloneWithItemsController {

     //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    private opportunity OP {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}

    // initialize the controller
    public OpportunityCloneWithItemsController(ApexPages.StandardController controller) {

        //initialize the standard controller
        this.controller = controller;
        // load the current record
        OP = (Opportunity)controller.getRecord();

    }

    // method called from the VF's action attribute to clone the OP
    public PageReference cloneWithItems() {

         // setup the save point for rollback
         Savepoint sp = Database.setSavepoint();
         Opportunity newOP;

         try {

              //copy the Opportunity - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             OP = [select Id,
                          Accountid,
                          CloseDate,
                          Promised_Delivery_Date__c,
                          Requested_Delivery_Date__c,
                          Description,
                          DocType__C,
                          CurrencyIsoCode,
                          Name,
                          Ownerid,
                          RecordTypeid,
                          Pricebook2id,
                          Campaignid,
                          Probability,
                          StageName,
                          warehouse__c,
                          Delivery_Address_if_diff_from_main_add__c,
                          Invoice_type__c,
                          Type,
                          A6_Combined_Discount__c,
                          A6_Total_Trade_Disc__c,
                          A6_Contributions_and_Provisions__c,
                          O1_2_return_reason__c,
                          Sale_Or_Return_Record__c
                    from Opportunity where id = :OP.id];
             newOP = OP.clone(false);
             newOP.Date_sent_to_warehouse__c = NULL;
             newOP.Sage_status__c ='Not Ready';
             insert newOP;

             // set the id of the new op created for testing
               newRecordId = newOP.id;

             // copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             List<OpportunityLineItem> items = new List<OpportunityLineItem>();
             for (OpportunityLineItem OPL : [Select OL.Id, OL.UnitPrice, OL.Quantity, OL.opportunityid, OL.pricebookentryid From OpportunityLineItem OL where Opportunityid = :OP.id]) {
                  OpportunityLineItem newOPL = OPL.clone(false);
                  newOPL.OpportunityId = newOP.id;
                  items.add(newOPL);
             }
             insert items;

         } catch (Exception e){
             // roll everything back in case of error
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
         }

        return new PageReference('/'+newOP.id+'/e?retURL=%2F'+newOP.id);
    }

}

VisualForce Page
<apex:page standardController="Opportunity" extensions="OpportunityCloneWithItemsController" action="{!cloneWithItems}"> <apex:pageMessages /> </apex:page> 
I have a VF page that gets  child records for a custom object master record and displays in an editable grid format.

However once I press "Save" i get the below error:
Error: There is no record to save

I'm guessing this is becasue the button triggers from the master object but the page controller uses the child records however if I switch the controller and page to be a related list the controller no longer works.

Controller:
public class EditAllButtonForTimeSheetController {

    public EditAllButtonForTimeSheetController(ApexPages.StandardController controller) {

    }

  public String TSRecordId        {get; set;}

  public List<Time_Sheet_Items__c> getTimeSheetRecords()
     {
    
       //Sets Time Shet id to variable
       TSRecordId = ApexPages.CurrentPage().getparameters().get('id');

        // this query needs a where clause, don't leave it unbounded
        List<Time_sheet_Items__C> TimeSheetRecords = 
         [SELECT Id,
            Time_Sheet__c,
            D_Type__c,
            D_Product_manager__c,
            D_Project__c,
            Day_Monday__c,
            Day_Tuesday__c,
            Day_Wednesday__c,
            Day_Thursday__c,
            Day_Friday__c,
            Day_Weekend__c
       FROM Time_Sheet_Items__c 
       WHERE Time_sheet__c = :TSRecordId  ];
    return TimeSheetRecords;
    }
}



VF Page:

<apex:page standardController="Time_Sheet__c"
         Extensions="EditAllButtonForTimeSheetController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save"
                            action="{!save}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!TimeSheetRecords}"
                           var="TSi">
        <apex:column style="width:5%" value="{!TSi.D_Project__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Type__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/>
    <apex:column style="width:5%" headerValue="Monday">
          <apex:inputField value="{!TSi.Day_Monday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Tuesday">
          <apex:inputField value="{!TSi.Day_Tuesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Wednesday">
          <apex:inputField value="{!TSi.Day_Wednesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Thursday">
          <apex:inputField value="{!TSi.Day_Thursday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Friday">
          <apex:inputField value="{!TSi.Day_Friday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Weekend">
          <apex:inputField value="{!TSi.Day_Weekend__c}"/>
        </apex:column>
      </apex:pageBlockTable>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

                

 
Hi all,

I'm trying to write a related list button on a master record that opens a table that you can edit certain fields of the masters child records.

My visual force page works but gets ALL child records in the system not just those relating to the master record I am on.

My Apex coding is:

public class EditAllButtonForTimeSheetController
{
    //This will store the Id from the URL i.e., the Id of the Record that belongs to the Master Object
    public String TSRecordId        {get; set;}
    public List<Time_Sheet_Items__c> TSiRecords  {get; set;}
    public Time_Sheet__c TSRecord                 {get; set;}
    //Constructor. This would build everything for our VF Page.
    public EditAllButtonForTimeSheetController()
    {
        TSRecordId = ApexPages.CurrentPage().getparameters().get('id');

        //Make sure we have the Id in the URL
        if(!String.isBlank(TSRecordId)){

            //Fetch the Time Sheet Record Details
            TSRecord =
            [SELECT ID,Name,Time_Sheet_Week_Ending__c FROM Time_Sheet__c WHERE Id = :TSRecordId ];

            //Fetch all the Time_Sheet_Items Records with respect to the Time_sheet Record. 
        //Note: Child_To_Parent_Lookup__c  is Lookup/M-D field on my Child SObject to the Parent – Master
            TSiRecords =
                [SELECT Id,Time_Sheet__c,D_Type__c,D_Product_manager__c,D_Project__c,
        Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c
                FROM TIme_Sheet_Items__c WHERE Time_sheet_ID__c = :TSRecordId ];
                
        }
    }
}


VF PAGE

<apex:page standardController="Time_Sheet_Items__c"
              Extensions="EditAllButtonForTimeSheetController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save"
                            action="{!save}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockTable value="{!Time_Sheet_Items__c}"
                           var="TSi">
        <apex:column style="width:5%" value="{!TSi.D_Project__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Type__c}"/>
        <apex:column style="width:5%" value="{!TSi.D_Product_Manager__c}"/>
    <apex:column style="width:5%" headerValue="Monday">
          <apex:inputField value="{!TSi.Day_Monday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Tuesday">
          <apex:inputField value="{!TSi.Day_Tuesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Wednesday">
          <apex:inputField value="{!TSi.Day_Wednesday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Thursday">
          <apex:inputField value="{!TSi.Day_Thursday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Friday">
          <apex:inputField value="{!TSi.Day_Friday__c}"/>
        </apex:column>
    <apex:column style="width:5%" headerValue="Weekend">
          <apex:inputField value="{!TSi.Day_Weekend__c}"/>
        </apex:column>
      </apex:pageBlockTable>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

Any help would be great.
Hi All,

I was wondering if its possible to create a customer button that work like the "Edit All" button but instead allows you to actually replace products for new codes in the pricebook without having to delete the products from the opportunity?