• Amphitrite
  • NEWBIE
  • 175 Points
  • Member since 2012

  • Chatter
    Feed
  • 7
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 22
    Replies
I may have posted this in the wrong forum. Here is my issue related to the enabler for excel app from taralex.

I'm having an issue with the Enabler for Excel in completing an Insert via VBA. I'm getting the following run-time error on the line listed below.

LIne with error:   ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error)
Error:   Object reference not set to an instance of an object.



Here is my complete VBA code [option explicit]

Sub InsertOpportunityLineItem()

  
    Dim addin As Office.COMAddIn
    Dim automationObject As Object
    Dim column As Integer
    Dim error As String
    Dim ip As Variant
    Dim ObjectName As String
    Dim ProdInArray(10, 9999) As Variant
    Dim Result As Boolean
    Dim Row As Integer
     
    ObjectName = "OpportunityLineItem"

     For Each addin In Application.COMAddIns
                     If addin.Description = "Enabler for Excel" Then
                                 Set automationObject = addin.Object
                   End If
     Next addin
 
                 'Login to environment
                 Result = automationObject.LogIn(Username2, Password2, "https://test.salesforce.com", error)
      
                 If Result = False Then
                    MsgBox error
                    End
                 End If
                 
                     
                'build insert array
                For column = 0 To 10
                      For Row = 0 To 19
                              ProdInArray(column, Row) = Worksheets(ObjectName).Range("B1").Offset(Row, column)
                      Next Row
                Next column
          
          
               set ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error)
                If Not error = Empty Then
                      MsgBox error
                      End
                End If
                   
                   
                'write update results array
                For column = 0 To 1
                     For Row = 0 To 18
                           Worksheets(ObjectName).Range("R2").Offset(Row, column) = ip(column, Row)
                     Next Row
                Next column
        
   
    Result = automationObject.LogOut()
I'm having an issue with the Enabler for Excel in completing an Insert via VBA. I'm getting the following run-time error on the line listed below.

LIne with error:   ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error)
Error:   Object reference not set to an instance of an object.



Here is my complete VBA code [option explicit]

Sub InsertOpportunityLineItem()

   
    Dim addin As Office.COMAddIn
    Dim automationObject As Object
    Dim bot_prod As Integer
    Dim column As Integer
    Dim error As String
    Dim ip As Variant
    Dim ObjectName As String
    Dim ProdInArray(10, 9999) As Variant
    Dim Result As Boolean
    Dim Row As Integer
      
    ObjectName = "OpportunityLineItem"

     For Each addin In Application.COMAddIns
                     If addin.Description = "Enabler for Excel" Then
                                 Set automationObject = addin.Object
                   End If
     Next addin
  
                 'Login to environment
                 Result = automationObject.LogIn(Username2, Password2, "https://test.salesforce.com", error)
       
                 If Result = False Then
                    MsgBox error
                    End
                 End If
                  
                      
                'build insert array
                For column = 0 To 10
                      For Row = 0 To 19
                              ProdInArray(column, Row) = Worksheets(ObjectName).Range("B1").Offset(Row, column)
                      Next Row
                Next column
           
           
                ip = automationObject.InsertData(ProdInArray, ObjectName, False, Nothing, error)
                If Not error = Empty Then
                      MsgBox error
                      End
                End If
                    
                    
                'write update results array
                For column = 0 To 1
                     For Row = 0 To bot_prod - 2
                           Worksheets(ObjectName).Range("R2").Offset(Row, column) = ip(column, Row)
                     Next Row
                Next column
         
    
    Result = automationObject.LogOut()
   


End Sub

I have a test class that isn't improving my test coverage of controller extension. This class should pass an array of cases that has a field that holds a URL [all cases hold same URL]. Then after the Cancel method runs - it should redirect to the URL.

 

I think it isn't passing because the case records are not inserting properly - but not sure how to debug or fix.


Here is the test code:

 

@isTest
private class BulkPageCancelTest {

static testMethod void TestBulkUpdateCancelCRef(){

 

List<User> users = new List<User>{};

for(Integer i = 0; i < 10; i++){
User c = new User(lastname='Testing'+i);
users.add(c);
}
Insert users;

 

List<Case> cases = new List<Case>{};

for(Integer i = 0; i < 10; i++){
Case c = new Case(InEditUserId__c=users[0].Id,InEditViewURL__c='https://cs13.salesforce.com/500?fcf=00B30000002To4e');
cases.add(c);
}
Insert cases;

 

PageReference pageRef = Page.BulkUpdate;
Test.setCurrentPage(pageRef);
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(cases);


test.startTest();

BulkUpdate e = new BulkUpdate(ssc);
string ViewURL=cases[0].InEditViewURL__c;
string nextPage = e.CancelExit().getURL();
System.assertEquals(ViewURL,nextPage);

 

test.stopTest();
}

 

I have 4 text fields that I need to set to null. But am getting an error 'Null is not definied' when trying to use the button. Any feedback as to syntax for this?

 

 

 

Here is the relevant piece of my javascript Onclick button code:

 

var caseUpdate = new sforce.SObject("Case");

 

caseUpdate.Id = caseObj.Id;
caseUpdate.InEditUserId__c = Null;
caseUpdate.InEditUser__c =Null;
caseUpdate.InEditTime__c =Null;
caseUpdate.InEditViewURL__c=Null;


updateRecords.push(caseUpdate);

 

 

 

 

 

 

This is a controller extension which has a custom save method to commit the value of userClick to the database. 

 

1. How do I test userClick 

2. How do I test the SelectOptions method of UserOption dropdown values.

 

 

 

Controller Extension for standardsetcontroller

 

public with sharing class BulkUpdate {

//Global Variables
private ApexPages.StandardSetController controller;

Public String userClick { get; set; }


// Standard Set Controller Constructor
public BulkUpdate(ApexPages.StandardSetController Controller) {

this.controller = controller;

}


public List<Case> getSelected(){
return (List<Case>) controller.getRecords();
}



//getOptions for userClick Method
public List<SelectOption> getUserOptions(){

List<SelectOption> useroptions = new List<SelectOption>();

useroptions.add(new SelectOption('','--select--'));
useroptions.add(new SelectOption('Next','Next RC'));
useroptions.add(new SelectOption('Next-Complete','Next-Complete'));
useroptions.add(new SelectOption('Previous','Previous RC'));
useroptions.add(new SelectOption('Refresh','Refresh Case'));


return useroptions;
}

 

//Save and Next method
public PageReference SaveNext(){


for(Case a :getSelected()){
a.UserActions__c=userClick;
}

Update getSelected();

PageReference pageRef = page.BulkUpdate2;
pageRef.setRedirect(true);
return pageRef;

}

}

 

 

 

 

 

Relevant Visualforce code:

 

<apex:selectList Label="UserActions" value="{!userClick}" size="1">
                     <apex:selectOptions Value="{!userOptions}"/>
                  </apex:selectList>

I need this javascript onclick button to populate fields conditionally. I'm pretty sure I need to query for just the results that need to be update. But am getting malformed query error when I try to run the button.

 

Any help wtih syntax of query would be much appreciated.

 

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
pagRef = window.location.href;
var records = {!GETRECORDIDS($ObjectType.Case)};
var qry="SELECT id,XLS06__c,ReturntoViewURL__c,InEditUser__c,InEditUserId__c,UserLock__c, UserControl__c,IsWriteable__c FROM Case where Id IN records AND IsWriteable__c=TRUE";

var qr = sforce.connection.query(qry);
var records = qr.getArray(records);


var newRecords = [];
if (records[0] == null)
{
alert("Please select at least one row")
}
else
{
for (var n in records) {
var c = new sforce.SObject("Case");
c.id = records[n];
c.XLS06__c =1;
c.ReturntoViewURL__c=pagRef;
c.InEditUserId__c="{!$User.Id}";
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location = pagRef;
}}

This button populates a few fields on a list of cases. I need the field InEditUserId to only update if the UserControl__c=="Read-Write". But I'm having trouble figuring out the syntax. 

 

Here is my code so far - works w/o the conditional statement.

 

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")} 
pagRef = window.location.href; 
var records = {!GETRECORDIDS($ObjectType.Case)}; 
var newRecords = []; 
if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n in records) { 
var c = new sforce.SObject("Case"); 
c.id = records[n]; 
c.XLS06__c =1; 
c.ReturntoViewURL__c=pagRef;

 

IF(c.UserControl__c=="Read-Write"){
c.InEditUserId__c="{!$User.Id}";}

 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 
window.location = pagRef; 
}

Error: Compile Error: Constructor not defined: [ApexPages.StandardSetController].<Constructor>(SOBJECT:Case) at line 13 column 39

 

Getting this error - not sure how to proceed.

 

 

@isTest

private class CaseBulkConfirmTest {

static testMethod void TestCaseBulkConfirm(){

PageReference pageRef = Page.CaseBulkConfirm;

Test.setCurrentPageReference(pageRef);

Case c = new case();

ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(c);

CaseBulkConfirm e = new CaseBulkConfirm(ssc);


String nextPage1 = e.ConfirmNext().getURL();
String nextPage2 = e.CancelClose().getURL();


System.assertEquals('apex/CaseBulkUpdate',nextPage1);
System.assertEquals('/500/o',nextPage2);

}
}

can I try and catch errors without the statement 'updates getcSelected;' actually running?

 

//Save and Next method
public PageReference SaveNext(){

 

for(Case a :getcSelected()){

a.InEditUserId__c=InEditUserId;
a.InEditUser__c=InEditUserName;
a.UserLock__c=InEditUserName + ' '+InEditTime;
a.Cancellation_Reason__c=cancelClick;
a.UserActions__c=userClick;
a.AdminActions__c=adminClick;

 

}

 

try{
Update getcSelected();
}


catch(DmlException dmle){
If(dmle.getDmlType(0) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION){
ApexPages.addMessages(dmle);
return null;
}
else throw dmle;
}

Update getcSelected();

 

 

PageReference pageRef = page.BulkUpdateCases2;
pageRef.setRedirect(true);
return pageRef;

}

This script code triggers the unload actionfunction appropriately. However, I need it to not trigger if the saveClose or saveNext command buttons are hit. Any suggestions?

 

 

<script>
window.onbeforeunload = unloadPage;
function unloadPage(){unload();}

</script>


<apex:actionFunction name="unload" action="{!unload}" rerender="MyPage" />

<apex:commandButton value="Save and Close" action="{!saveClose}"/>
<apex:commandButton value="Save and Next" action="{!saveNext}"/>

I have some Javascript that should trigger an actionFunction method if user tries to close window or browser. However - it isn't actually running. Any ideas?

 

 

<script LANGUAGE="JavaScript1.2" TYPE="text/javascript">



var allowPrompt=true;

function unloadUserLock(){
IF(allowPrompt){
window.onbeforeunload = unloadPage;
}
}

function unloadPage()
{
unload();
}

function NoPrompt()
{
allowPrompt=false;
}

</script>

I'd like to update a field to hold the NOW() datetime. What is syntax to do this?

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")} 
var records = {!GETRECORDIDS($ObjectType.Case)}; 
var newRecords = []; 
if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n in records) { 
var c = new sforce.SObject("Case"); 
c.id = records[n]; 
c.XLS05__c =1; 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 
window.location = '/Apex/CaseCollider'; 
}

I'm trying to call a VF page from my custom button OnClick. But getting the error 'URL no longer exists'. Any suggestions?

 

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")} 
var records = {!GETRECORDIDS($ObjectType.Case)}; 
var newRecords = []; 
if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n in records) { 
var c = new sforce.SObject("Case"); 
c.id = records[n]; 
c.XLS05__c =1; 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 
window.location = '/Apex/CaseCollider'; 
}

I'm getting this system error when trying to update just a small list of properties. Can anyone assist? It works as expected on a single record - but more than one hits limit pretty quickly.

 

This code should write 4 fields on a property object if a checkbox called writecodes is TRUE. 

 

This is code that is triggered by a 'before update' trigger.

 

Apex Class:

 

public class PropertyProductCodes{

    Public List<Property_Account__c> lstNewProps = new List<Property_Account__c>();
    Public List<Property_Account__c> lstOldProps = new List<Property_Account__c>();    

public void ProductCodes(){
       
     List<Case> propertycases = [select Id,Product_Code__c,IsClosed FROM case where Property__c IN: lstNewProps AND XLS01__c=:TRUE AND Status!=:'Cancelled'];
     List<Property_Account__c> props = new List<Property_Account__c>();
          
     
     String codes; 
     String SEO = 'SEO';
     String SEOcodes;
     Integer SEOlen=3;
     Integer SEOindex;
     Integer SEOcount = 0;
     Integer SEOclosed = 0;
     String LSCW = 'LSCW';
     String LSCWcodes;
     Integer LSCWlen=4;
     Integer LSCWindex;
     Integer LSCWcount = 0;
     
   IF(lstNewProps.size()>0 && propertycases.size()>0){
     
     For(Property_Account__c NewProps: lstNewProps){
       IF(NewProps.WriteCodes__c == True){
     
         For(Case wc : propertycases){
     
             IF(codes==null && wc.IsClosed==False){
         
                codes=wc.product_code__c+'F';
                  
             }
             
             Else IF(codes==null && wc.IsClosed==True){
         
                codes=wc.product_code__c+'T';
                IF(wc.product_code__c.contains(SEO)==TRUE){
                SEOclosed++;
                }
                  
             }
         
             Else IF(wc.IsClosed==False){
         
                 codes=codes+'-'+wc.product_code__c+'F';
             } 
         
             Else{
                 codes=codes+'-'+wc.product_code__c+'T';
                 IF(wc.product_code__c.contains(SEO)==TRUE){
                    SEOclosed++;
                 }
             }
         
         }
     
         SEOcodes=codes;
         SEOindex=SEOcodes.indexOf(SEO);
         while(SEOindex >=0){
               SEOcount++;
               SEOcodes=SEOcodes.substring(SEOindex+SEOlen);
               SEOindex=SEOcodes.indexOf(SEO);
         }
         
         
         
         LSCWcodes=codes;
         LSCWindex=LSCWcodes.indexOf(LSCW);
         while(LSCWindex >=0){
               LSCWcount++;
               LSCWcodes=LSCWcodes.substring(LSCWindex+LSCWlen);
               LSCWindex=LSCWcodes.indexOf(LSCW);
         } 
   
        props.add(NewProps);
        NewProps.SEO_Count__c=SEOcount;
        NewProps.LSCW_Count__c=LSCWcount;
        NewProps.SEO_Closed__c=SEOclosed;
        NewProps.ImplementationCodes__c=codes;
        NewProps.WriteCodes__c=False; 
        SEOcodes=Null;
        SEOindex=0;
        SEOcount=0;
        SEOclosed=0;
        LSCWcodes=Null;
        LSCWindex=0;
        LSCWcount=0;
        codes=Null;
        
    }
   
   }
   }
   
   
   
}

}

 

 

 

Here is trigger:

 

Re: System.LimitException: Too many code statements: 200001

Here is the before update trigger:

 

trigger PropertyUpdates on Property_Account__c (before update) {

    public PropertyProductCodes  clsPropertyProductCodes=new PropertyProductCodes();

           clsPropertyProductCodes.lstNewProps = Trigger.new;
           clsPropertyProductCodes.lstOldProps = Trigger.old;

           clsPropertyProductCodes.ProductCodes();
    
}

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger CaseUpdates caused an unexpected exception, contact your administrator: CaseUpdates: execution of BeforeUpdate caused by: System.ListException: DML statment found null SObject at position 0: Class.PropertyUpdatebyCode.PropertyUpdatebyCode: line 23, column 1". 

 

 

Getting this error anytime the for loop should be populating my properties array. 

 

 

Apex Class

 

public class PropertyUpdatebyCode{

      Public List<Case> lstNewCases = new List<Case>();
      Public List<Case> lstOldCases = new List<Case>();
    
        public void PropertyUpdatebyCode() {

 

        //variables
        Map<Id,Case>  mapVerifyOldCases=new Map<Id,Case>();
        List<Property_Account__c> properties = new list<Property_Account__c>();
        

 

        //populates map with old values for comparison
        For(Case CaseOld : lstOldCases){ mapVerifyOldCases.put(CaseOld.id,CaseOld);}
        

 

        //populates array for DML update expression
        For(Case CaseNew: lstNewCases){ 
            IF(CaseNew.Property__c!=Null && 

                CaseNew.XLS01__c==TRUE &&

                (CaseNew.IsClosed != mapVerifyOldCases.get(CaseNew.Id).IsClosed || 

                CaseNew.Property__c!= mapVerifyOldCases.get(Case New.Id).Property__c)){
                            
                properties.add(CaseNew.Property__r);
        
             }
        }     
        

        //DML updates if array isn't empty
        IF(properties.size()>0){
          
          update properties;
        
        }      
                        
                   
}        
}

 

 

Here is my trigger - which just populates the variable arrays for my apex class.

 

trigger CaseUpdates on Case (before insert,before update) 
{
         
           //instantiate class
           public PropertyUpdatebyCode  clsPropertyUpdatebyCode=new PropertyUpdatebyCode();

 

           //populate varibles
           clsPropertyUpdatebyCode.lstNewCases = Trigger.new;
           clsPropertyUpdatebyCode.lstOldCases = Trigger.old;

 

           //calls method
           clsPropertyUpdatebyCode.PropertyUpdatebyCode();
           
}

I have a page that loads a set of records [based on a query] and includes some inputfields to apply changes to the associated records. The page loads the right records and the fields that I 'get-set' [inputtext] in the controller extension do update. But any values in the inputfields type get lost.

 

The inputText fields are ButtonClick and RC Setter - these two save - but the rest of the field values are lost. Any suggestions would be great!

 

Here is my controller extension [extends the case StandardSetController]- which includes two methods for 'SaveClose' and 'SaveNext' and following this is the visualforce page code.

 

 

public with sharing class CaseExtension {

    //Global Variables    
    private ApexPages.StandardSetController controller;
    Private final string InEditUser=UserInfo.getUserId();
    public String onClick { get; set; }  
    Public String RCSetter   { get; set; } 
    
    // Standard Controller Constructor  
    public CaseExtension(ApexPages.StandardSetController Controller) {
    
    this.controller = controller;
            
    }
    
    public ApexPages.StandardSetController caseRecords{
    
       Get{
           if(caseRecords==null){
           

             caseRecords = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id,ButtonClick__c,CaseNumber,Account.Name,

                  Cancellation_Date__c,Completion_Date__c,Target_SLA_Current__c,Implementation_Notes__c,
                  Implementation_Delay__c,Implementation_Delay_Notes__c,Delay_Details__c,Cancellation_Reason__c,New_Case_Comment__c,

                 OMS_Quote_no__c,Property_Name__c,
                  Opportunity_c__c,Bundle__c,Product__c,Status_RC__c,InEditUser__c,InEditExpiring__c FROM Case WHERE InEditUser__c =: InEditUser]));
           }
           return caseRecords;
       }
       Private set;
    }       
       
    public List<Case> getcSelected(){
       return (List<Case>) caseRecords.getRecords();
    }   
    
     
         //getOptions for ButtonClick Method
        public List<SelectOption> getOptions(){
               
        List<SelectOption> options = new List<SelectOption>();
        
        options.add(new SelectOption('','--select--'));
        options.add(new SelectOption('Next','Next RC'));
        options.add(new SelectOption('Previous','Previous RC'));
        options.add(new SelectOption('getProperty','Assign Property Contact'));
        options.add(new SelectOption('getCorporate','Assign Corporate Contact'));
        
        return options;
        }     

    
       //Save and Close method
   
        
      public PageReference SaveClose(){
           
           
           for(Case e :getcSelected()){
                     
             e.ButtonClick__c=onClick;
             e.InEditUser__c=Null;
             e.RC_Setter__c=RCSetter;
                          
           }
                  
           Update getcSelected();
                  
       
        PageReference pageRef = new PageReference('/500/o');
        pageRef.setRedirect(true);
        return pageRef;
     
       } 
         

 //Save and Next method
         public PageReference SaveNext(){
            
          
            for(Case g :getcSelected()){
          
            g.ButtonClick__c=onClick;
            g.RC_Setter__c=RCSetter;
            }
           
           Update getcSelected();
                 
           PageReference pageRef =  page.InEditUpdateOne;
           pageRef.setRedirect(true);
           return pageRef;  
        
        }       
     
 }

 

 

 

VisualForce Page:

 

<apex:page standardController="Case" extensions="CaseExtension"
    recordSetVar="implementations">
    
   
  <apex:sectionHeader title="New Field Values"/>
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
         <apex:commandButton value="Save and Close"
            action="{!saveClose}" onclick="NoPrompt();"/>
            <apex:commandButton value="Save and Next"
            action="{!saveNext}" onclick="NoPrompt();"/>
        
       </apex:pageBlockButtons>
     
     
      <apex:tabPanel switchType="client" selectedTab="TabOne" id="theTabPanel">
       <apex:tab label="Standard Details" name="StandardDetails" id="tabOne">

        <apex:pageBlockSection title="" showHeader="false" 
          collapsible="false">
          
                  <apex:selectList Label="ButtonClick" value="{!onClick}" size="1">
                     <apex:selectOptions Value="{!Options}"/>
                  </apex:selectList>
                  
                  
                  <apex:inputField Label="Case Owner" value="{!Case.OwnerId}" Required="False"/>
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:inputField value="{!Case.Target_SLA_Current__c}"/>
                  
                  <apex:inputField value="{!Case.Client_Contacted_Date__c}" Required="False"/>
                  
                   <apex:inputField value="{!Case.ContactId}" Required="False"/>
                   
                    <apex:pageBlockSectionItem />
                   <apex:inputTextArea value="{!Case.Implementation_Notes__c}" rows="5" cols="75"/>
                   <apex:inputTextArea value="{!Case.Implementation_Delay_Notes__c}" rows="5" cols="75"/>
                    <apex:pageBlockSectionItem />
                   
          </apex:pageBlockSection>
        </apex:tab>
        
        <apex:tab label="Administration" name="Administration" id="tabTwo">

            <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">
        
        <apex:inputText Label="RC Setter" value="{!RCSetter}"/>
        <apex:inputField value="{!Case.Cancellation_Reason__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Case.Completion_Date__c}"/>
        <apex:inputField value="{!Case.Cancellation_Date__c}"/>
         <apex:pageBlockSectionItem />
        

          </apex:pageBlockSection>
        </apex:tab>

        

        </apex:tabPanel>
        
      <apex:pageBlockSection title="Selected Implementations" columns="1">
        <apex:pageBlockTable value="{!cSelected}"
            var="c">
               
                 <apex:column headerValue="Case No">
                              <apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink>
                  </apex:column>
                  <apex:column value="{!c.OMS_Quote_No__c}"/>
                  <apex:column value="{!c.Account.Name}"/>
                  <apex:column value="{!c.Property_Name__c}"/>
                  <apex:column value="{!c.Opportunity_c__c}"/>
                  <apex:column value="{!c.Bundle__c}"/>
                  
                <apex:column value="{!c.Product__c}"/>
                <apex:column value="{!c.Status_RC__c}"/>
    <apex:column value="{!c.Target_SLA_Current__c}"/>
    <apex:column value="{!c.Implementation_Delay__c}"/>
    <apex:column value="{!c.Implementation_Delay_Notes__c}"/>
    <apex:column value="{!c.InEditExpiring__c}"/>
                                                
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

 

This controller extension to the standardsetcontroller defines a custom Save method called 'SaveClose'. A query in the constructor holds the 'InEdit' array of records that should be updated when this method is called. The page loads as expected with the records - but the SaveClose method line for Update 'InEdit' doesn't actually update the records. 

 

I know the method is running - because the page reference lines do run. But the Update InEdit line isn't updating any records. Maybe I'm not defining my array correctly? 

 

Any help or suggestions would be great.

 

Here is extension class:

 

public with sharing class InEditExtensionOne {

//Global Variables
private ApexPages.StandardSetController controller;
Private final string InEditUser=UserInfo.getUserId();
public list<case> InEdit { get; set; }


// Standard Controller Constructor
public InEditExtensionOne(ApexPages.StandardSetController Controller) {

this.controller = controller;
this.InEdit=[SELECT Id,CaseNumber,Account.Name,Cancellation_Date__c,Completion_Date__c
FROM Case WHERE InEditUser__c =InEditUser];

}




//Save and Close method


public PageReference SaveClose(){




for(Case e :InEdit){


e.InEditUser__c=Null;
e.InEditTime__c=Null;
e.InEditExpiring__c=Null;

}

Update InEdit;



PageReference pageRef = new PageReference('/500/o');
pageRef.setRedirect(true);
return pageRef;

}

}

 

 

 

Here is the visualforce page:

 

<apex:page standardController="Case" extensions="InEditExtensionOne"
    recordSetVar="implementations">
    
    <script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
    
    var allowPrompt = true;
    
    function unloadMessage(){
        if(allowPrompt){
        message = "Wait! Please hit 'Save and Close' before exiting the page."
        
        }
         else {
         message = "Please confirm your changes."
         allowPrompt = true;
        }
        return message;
    }
    
    function setBunload(on){
        window.onbeforeunload = (on) ? unloadMessage : null;
    }
    setBunload(true);
    
    
    function NoPrompt()
    {
      allowPrompt = false;
    }
    
    
    </script>
   
  <apex:sectionHeader title="New Field Values"/>
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save and Close"
            action="{!saveClose}" onclick="NoPrompt();"/>
            <apex:commandButton value="Save and Next"
            action="{!saveNext}" onclick="NoPrompt();"/>
       </apex:pageBlockButtons>
     
     
      <apex:tabPanel switchType="client" selectedTab="TabOne" id="theTabPanel">
       <apex:tab label="Standard Details" name="StandardDetails" id="tabOne">

        <apex:pageBlockSection title="" showHeader="false" 
          collapsible="false">
          
                  <apex:selectList Label="ButtonClick" value="{!onClick}" size="1">
                     <apex:selectOptions Value="{!Options}"/>
                  </apex:selectList>
                  <apex:inputField Label="Case Owner" value="{!Case.OwnerId}" Required="False"/>
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:inputField value="{!Case.Target_SLA_Current__c}"/>
                  
                  
                  
                  <apex:inputField value="{!Case.Implementation_Delay__c}"/>
                  <apex:inputField value="{!Case.Client_Contacted_Date__c}" Required="False"/>
                  <apex:inputField value="{!Case.Delay_Details__c}"/>
                  
                   <apex:inputField value="{!Case.ContactId}" Required="False"/>
                   
                                  
                   
                    <apex:pageBlockSectionItem />
                   <apex:inputTextArea value="{!Case.Implementation_Notes__c}" rows="5" cols="75"/>
                   <apex:inputTextArea value="{!Case.Implementation_Delay_Notes__c}" rows="5" cols="75"/>
                    <apex:pageBlockSectionItem />
                   
          </apex:pageBlockSection>
        </apex:tab>
        
        <apex:tab label="Administration" name="Administration" id="tabTwo">

            <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

           

        
        <apex:inputField value="{!Case.RC_Setter__c}"/>
        <apex:inputField value="{!Case.Cancellation_Reason__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Case.Completion_Date__c}"/>
        <apex:inputField value="{!Case.Cancellation_Date__c}"/>
         <apex:pageBlockSectionItem />
        

          </apex:pageBlockSection>
        </apex:tab>

        <apex:tab label="India Operations" name="IndiaOperations" id="tabThree">

        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

        <apex:inputField value="{!Case.Property__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:inputTextArea value="{!Case.New_Case_Comment__c}" rows="3" cols="75"/>
         <apex:pageBlockSectionItem />
          <apex:pageBlockSectionItem />

        </apex:pageBlockSection>
        </apex:tab>

        <apex:tab label="Marketplace Suite" name="Marketplace" id="tabFour">

        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

        <apex:inputField value="{!Case.Pilot__c}"/>
        <apex:inputField value="{!Case.Kick_off_Meeting__c}"/>
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Case.Project_Plan__c}"/>
        <apex:inputField value="{!Case.Sales_Checklist__c}"/>
        <apex:inputField value="{!Case.Weekly_Status__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        </apex:pageBlockSection>
        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false" Columns="1">
        
        <apex:inputTextArea value="{!Case.Historical_Comments__c}" rows="4" cols="185"/>
         <apex:pageBlockSectionItem />

        </apex:pageBlockSection>
        </apex:tab>

        <apex:tab label="Migration" name="Migration" id="tabFive">

        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

        <apex:inputField value="{!Case.Products_Sold__c}"/>
         <apex:inputField value="{!Case.Account_Set_Up__c}"/>
          <apex:inputField value="{!Case.Upsell__c}"/>
           <apex:inputField value="{!Case.Dev_Prep_Work__c}"/>
            <apex:inputField value="{!Case.Upsell_Detail__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        
        <apex:inputField value="{!Case.Resident_Portal_Last_Activity_Date__c}"/>
          <apex:inputField value="{!Case.Date_Sent_to_Sales__c}"/>
           <apex:inputField value="{!Case.Uses_Velocity_06062013__c}"/>
            <apex:inputField value="{!Case.Date_Back_from_Sales__c}"/>
            <apex:inputField value="{!Case.WH_Price_List__c}"/>
             <apex:pageBlockSectionItem />


        </apex:pageBlockSection>
        </apex:tab>


        </apex:tabPanel>
        
      <apex:pageBlockSection title="Selected Implementations" columns="1">
        <apex:pageBlockTable value="{!InEdit}"
            var="c">
               
                 <apex:column headerValue="Case No">
                              <apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink>
                  </apex:column>
                  
                  <apex:column value="{!c.Account.Name}"/>
                  
                  
                
                                                
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

I've written a controller extension for a standardset controller driven Visualforce Page. I've include a custom 'Save and Close' button that saves the records and closes the page. However - it isn't updating the list I've called in the constructor. Here is the controller extension and vforce page - limited to just the basics - any assistance would be great.

 

 

Controller extension:

 

public with sharing class InEditExtensionOne {

//Global Variables
private ApexPages.StandardSetController controller;
Private final string InEditUser=UserInfo.getUserId();
public list<Case> InEdit { get; set; }
public String onClick { get; set; }

// Standard Controller Constructor
public InEditExtensionOne(ApexPages.StandardSetController Controller) {

this.controller = controller;
this.InEdit=[SELECT Id,CaseNumber,Account.Name,Account.Id,Description,Subject,ButtonClick__c FROM Case WHERE InEditUser__c =: InEditUser];

}



//Save and Close method


public PageReference SaveClose(){

for(Case g :InEdit){

g.ButtonClick__c=onClick;


}

update InEdit;



PageReference pageRef = new PageReference('/500/o');
pageRef.setRedirect(true);
return pageRef;

}

}

 

 

 

 

VForce Page

 

 

<apex:page standardController="Case" extensions="InEditExtensionOne"
recordSetVar="implementations">



<apex:sectionHeader title="New Field Values"/>
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save and Close"
action="{!saveClose}" onclick="NoPrompt();"/>
<apex:commandButton value="Save and Next"
action="{!saveNext}" onclick="NoPrompt();"/>
</apex:pageBlockButtons>



<apex:pageBlockSection title="Input Fields" showHeader="false"
collapsible="false">

<apex:inputField value="{!Case.AccountId__c}"/>
<apex:inputField value="{!Case.Subject__c}"/>
<apex:inputTextArea value="{!Case.Description__c}" rows="5" cols="75"/>
<apex:inputField Label="ButtonClick" value=""{!onClick}">

</apex:pageBlockSection>



<apex:pageBlockSection title="Selected Implementations" columns="1">
<apex:pageBlockTable value="{!InEdit}"
var="c">

<apex:column headerValue="Case No">
<apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink>
</apex:column>
<apex:column value="{!c.Account.Name}"/>
<apex:column value="{!c.Subject}"/>
<apex:column value="{!c.Description}"/>
<apex:column value="{!c.ButtonClick__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Can anyone assist with the test code for the following controller extension method? It returns a default set of options and then additional options based on profile. Any assistance would be appreciated.

 

 

 //getOptions Method
        public List<SelectOption> getOptions(){
               
        List<SelectOption> options = new List<SelectOption>();
        
        options.add(new SelectOption('','--select--'));
        options.add(new SelectOption('Next','Next RC'));
        options.add(new SelectOption('Previous','Previous RC'));
        options.add(new SelectOption('getProperty','Assign Property Contact'));
        options.add(new SelectOption('getCorporate','Assign Corporate Contact'));
        
               
        IF(InEditProfileTest =='000e50000000pnH3' || InEditProfileTest =='00e50000000pnCc' ){
        options.add(new SelectOption('Close','Close AM Case'));
        
        }
        
        Else IF(InEditProfileTest =='00e50000000pnCmAAI'){
        options.add(new SelectOption('ExceptionON','Owner Exception ON'));
        options.add(new SelectOption('ExceptionOFF','Owner Exception OFF'));
        options.add(new SelectOption('Refresh','Refresh Case'));
        
        }
                
        Else If(InEditProfileTest=='00e30000000gvVd' || InEditProfileTest =='00e50000000pl2e'){
        
        options.add(new SelectOption('ExceptionON','Owner Exception ON'));
        options.add(new SelectOption('ExceptionOFF','Owner Exception OFF'));
        options.add(new SelectOption('Refresh','Refresh Case'));
        options.add(new SelectOption('Complete','Auto Complete'));
        options.add(new SelectOption('Cancel','Cancel'));
        options.add(new SelectOption('Clear Cancel','Clear Cancel'));
        options.add(new SelectOption('ResetAll','Reset'));
        options.add(new SelectOption('Terminate','Terminate'));
        options.add(new SelectOption('Delete','Delete'));
               
               
        }
        
  
         return options;
        }      

 

 

 

 

This trigger ends up passing nothing to the two class methods I'm calling. Can someone help me debug? Here is my Trigger.

 

Purpose - if one of two contact lookups is changed in the account - it should update the related contact lookup field on a related Property_Account__c object.

 

 

trigger AccountUpdate on Account (before update) {
       
        Map<Id,Account> newAccountMap = Trigger.newMap;
        Map<Id,Account> oldAccountMap = Trigger.oldMap;
      
        List<Account> accspmig = new list<Account>();
        List<Account> accsppay = new list<Account>();
     
       for(Id AccountId: newAccountMap.keySet()){
             Account myNewAccount = newAccountMap.get(AccountId);
             Account myOldAccount = oldAccountMap.get(Accountid);
  
           IF(myNewAccount.MigrationContacta__r  <> myOldAccount.MigrationContacta__r){
            accspmig.add(myNewAccount);          
           }
        

           IF(myNewAccount.PaymentsContacta__r <> myOldAccount.PaymentsContacta__r){
            accsppay.add(myNewAccount);  
           }

           }

            AccountUpdate.MigContact(accspmig);
            AccountUpdate.PayContact(accsppay);

}

 

I've written a controller extension for a standardset controller driven Visualforce Page. I've include a custom 'Save and Close' button that saves the records and closes the page. However - it isn't updating the list I've called in the constructor. Here is the controller extension and vforce page - limited to just the basics - any assistance would be great.

 

 

Controller extension:

 

public with sharing class InEditExtensionOne {

//Global Variables
private ApexPages.StandardSetController controller;
Private final string InEditUser=UserInfo.getUserId();
public list<Case> InEdit { get; set; }
public String onClick { get; set; }

// Standard Controller Constructor
public InEditExtensionOne(ApexPages.StandardSetController Controller) {

this.controller = controller;
this.InEdit=[SELECT Id,CaseNumber,Account.Name,Account.Id,Description,Subject,ButtonClick__c FROM Case WHERE InEditUser__c =: InEditUser];

}



//Save and Close method


public PageReference SaveClose(){

for(Case g :InEdit){

g.ButtonClick__c=onClick;


}

update InEdit;



PageReference pageRef = new PageReference('/500/o');
pageRef.setRedirect(true);
return pageRef;

}

}

 

 

 

 

VForce Page

 

 

<apex:page standardController="Case" extensions="InEditExtensionOne"
recordSetVar="implementations">



<apex:sectionHeader title="New Field Values"/>
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save and Close"
action="{!saveClose}" onclick="NoPrompt();"/>
<apex:commandButton value="Save and Next"
action="{!saveNext}" onclick="NoPrompt();"/>
</apex:pageBlockButtons>



<apex:pageBlockSection title="Input Fields" showHeader="false"
collapsible="false">

<apex:inputField value="{!Case.AccountId__c}"/>
<apex:inputField value="{!Case.Subject__c}"/>
<apex:inputTextArea value="{!Case.Description__c}" rows="5" cols="75"/>
<apex:inputField Label="ButtonClick" value=""{!onClick}">

</apex:pageBlockSection>



<apex:pageBlockSection title="Selected Implementations" columns="1">
<apex:pageBlockTable value="{!InEdit}"
var="c">

<apex:column headerValue="Case No">
<apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink>
</apex:column>
<apex:column value="{!c.Account.Name}"/>
<apex:column value="{!c.Subject}"/>
<apex:column value="{!c.Description}"/>
<apex:column value="{!c.ButtonClick__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

I have a test class that isn't improving my test coverage of controller extension. This class should pass an array of cases that has a field that holds a URL [all cases hold same URL]. Then after the Cancel method runs - it should redirect to the URL.

 

I think it isn't passing because the case records are not inserting properly - but not sure how to debug or fix.


Here is the test code:

 

@isTest
private class BulkPageCancelTest {

static testMethod void TestBulkUpdateCancelCRef(){

 

List<User> users = new List<User>{};

for(Integer i = 0; i < 10; i++){
User c = new User(lastname='Testing'+i);
users.add(c);
}
Insert users;

 

List<Case> cases = new List<Case>{};

for(Integer i = 0; i < 10; i++){
Case c = new Case(InEditUserId__c=users[0].Id,InEditViewURL__c='https://cs13.salesforce.com/500?fcf=00B30000002To4e');
cases.add(c);
}
Insert cases;

 

PageReference pageRef = Page.BulkUpdate;
Test.setCurrentPage(pageRef);
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(cases);


test.startTest();

BulkUpdate e = new BulkUpdate(ssc);
string ViewURL=cases[0].InEditViewURL__c;
string nextPage = e.CancelExit().getURL();
System.assertEquals(ViewURL,nextPage);

 

test.stopTest();
}

 

 

This is a controller extension which has a custom save method to commit the value of userClick to the database. 

 

1. How do I test userClick 

2. How do I test the SelectOptions method of UserOption dropdown values.

 

 

 

Controller Extension for standardsetcontroller

 

public with sharing class BulkUpdate {

//Global Variables
private ApexPages.StandardSetController controller;

Public String userClick { get; set; }


// Standard Set Controller Constructor
public BulkUpdate(ApexPages.StandardSetController Controller) {

this.controller = controller;

}


public List<Case> getSelected(){
return (List<Case>) controller.getRecords();
}



//getOptions for userClick Method
public List<SelectOption> getUserOptions(){

List<SelectOption> useroptions = new List<SelectOption>();

useroptions.add(new SelectOption('','--select--'));
useroptions.add(new SelectOption('Next','Next RC'));
useroptions.add(new SelectOption('Next-Complete','Next-Complete'));
useroptions.add(new SelectOption('Previous','Previous RC'));
useroptions.add(new SelectOption('Refresh','Refresh Case'));


return useroptions;
}

 

//Save and Next method
public PageReference SaveNext(){


for(Case a :getSelected()){
a.UserActions__c=userClick;
}

Update getSelected();

PageReference pageRef = page.BulkUpdate2;
pageRef.setRedirect(true);
return pageRef;

}

}

 

 

 

 

 

Relevant Visualforce code:

 

<apex:selectList Label="UserActions" value="{!userClick}" size="1">
                     <apex:selectOptions Value="{!userOptions}"/>
                  </apex:selectList>

I need this javascript onclick button to populate fields conditionally. I'm pretty sure I need to query for just the results that need to be update. But am getting malformed query error when I try to run the button.

 

Any help wtih syntax of query would be much appreciated.

 

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
pagRef = window.location.href;
var records = {!GETRECORDIDS($ObjectType.Case)};
var qry="SELECT id,XLS06__c,ReturntoViewURL__c,InEditUser__c,InEditUserId__c,UserLock__c, UserControl__c,IsWriteable__c FROM Case where Id IN records AND IsWriteable__c=TRUE";

var qr = sforce.connection.query(qry);
var records = qr.getArray(records);


var newRecords = [];
if (records[0] == null)
{
alert("Please select at least one row")
}
else
{
for (var n in records) {
var c = new sforce.SObject("Case");
c.id = records[n];
c.XLS06__c =1;
c.ReturntoViewURL__c=pagRef;
c.InEditUserId__c="{!$User.Id}";
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location = pagRef;
}}

This button populates a few fields on a list of cases. I need the field InEditUserId to only update if the UserControl__c=="Read-Write". But I'm having trouble figuring out the syntax. 

 

Here is my code so far - works w/o the conditional statement.

 

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")} 
pagRef = window.location.href; 
var records = {!GETRECORDIDS($ObjectType.Case)}; 
var newRecords = []; 
if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n in records) { 
var c = new sforce.SObject("Case"); 
c.id = records[n]; 
c.XLS06__c =1; 
c.ReturntoViewURL__c=pagRef;

 

IF(c.UserControl__c=="Read-Write"){
c.InEditUserId__c="{!$User.Id}";}

 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 
window.location = pagRef; 
}

Error: Compile Error: Constructor not defined: [ApexPages.StandardSetController].<Constructor>(SOBJECT:Case) at line 13 column 39

 

Getting this error - not sure how to proceed.

 

 

@isTest

private class CaseBulkConfirmTest {

static testMethod void TestCaseBulkConfirm(){

PageReference pageRef = Page.CaseBulkConfirm;

Test.setCurrentPageReference(pageRef);

Case c = new case();

ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(c);

CaseBulkConfirm e = new CaseBulkConfirm(ssc);


String nextPage1 = e.ConfirmNext().getURL();
String nextPage2 = e.CancelClose().getURL();


System.assertEquals('apex/CaseBulkUpdate',nextPage1);
System.assertEquals('/500/o',nextPage2);

}
}

can I try and catch errors without the statement 'updates getcSelected;' actually running?

 

//Save and Next method
public PageReference SaveNext(){

 

for(Case a :getcSelected()){

a.InEditUserId__c=InEditUserId;
a.InEditUser__c=InEditUserName;
a.UserLock__c=InEditUserName + ' '+InEditTime;
a.Cancellation_Reason__c=cancelClick;
a.UserActions__c=userClick;
a.AdminActions__c=adminClick;

 

}

 

try{
Update getcSelected();
}


catch(DmlException dmle){
If(dmle.getDmlType(0) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION){
ApexPages.addMessages(dmle);
return null;
}
else throw dmle;
}

Update getcSelected();

 

 

PageReference pageRef = page.BulkUpdateCases2;
pageRef.setRedirect(true);
return pageRef;

}

This script code triggers the unload actionfunction appropriately. However, I need it to not trigger if the saveClose or saveNext command buttons are hit. Any suggestions?

 

 

<script>
window.onbeforeunload = unloadPage;
function unloadPage(){unload();}

</script>


<apex:actionFunction name="unload" action="{!unload}" rerender="MyPage" />

<apex:commandButton value="Save and Close" action="{!saveClose}"/>
<apex:commandButton value="Save and Next" action="{!saveNext}"/>

I have some Javascript that should trigger an actionFunction method if user tries to close window or browser. However - it isn't actually running. Any ideas?

 

 

<script LANGUAGE="JavaScript1.2" TYPE="text/javascript">



var allowPrompt=true;

function unloadUserLock(){
IF(allowPrompt){
window.onbeforeunload = unloadPage;
}
}

function unloadPage()
{
unload();
}

function NoPrompt()
{
allowPrompt=false;
}

</script>

I'm getting this system error when trying to update just a small list of properties. Can anyone assist? It works as expected on a single record - but more than one hits limit pretty quickly.

 

This code should write 4 fields on a property object if a checkbox called writecodes is TRUE. 

 

This is code that is triggered by a 'before update' trigger.

 

Apex Class:

 

public class PropertyProductCodes{

    Public List<Property_Account__c> lstNewProps = new List<Property_Account__c>();
    Public List<Property_Account__c> lstOldProps = new List<Property_Account__c>();    

public void ProductCodes(){
       
     List<Case> propertycases = [select Id,Product_Code__c,IsClosed FROM case where Property__c IN: lstNewProps AND XLS01__c=:TRUE AND Status!=:'Cancelled'];
     List<Property_Account__c> props = new List<Property_Account__c>();
          
     
     String codes; 
     String SEO = 'SEO';
     String SEOcodes;
     Integer SEOlen=3;
     Integer SEOindex;
     Integer SEOcount = 0;
     Integer SEOclosed = 0;
     String LSCW = 'LSCW';
     String LSCWcodes;
     Integer LSCWlen=4;
     Integer LSCWindex;
     Integer LSCWcount = 0;
     
   IF(lstNewProps.size()>0 && propertycases.size()>0){
     
     For(Property_Account__c NewProps: lstNewProps){
       IF(NewProps.WriteCodes__c == True){
     
         For(Case wc : propertycases){
     
             IF(codes==null && wc.IsClosed==False){
         
                codes=wc.product_code__c+'F';
                  
             }
             
             Else IF(codes==null && wc.IsClosed==True){
         
                codes=wc.product_code__c+'T';
                IF(wc.product_code__c.contains(SEO)==TRUE){
                SEOclosed++;
                }
                  
             }
         
             Else IF(wc.IsClosed==False){
         
                 codes=codes+'-'+wc.product_code__c+'F';
             } 
         
             Else{
                 codes=codes+'-'+wc.product_code__c+'T';
                 IF(wc.product_code__c.contains(SEO)==TRUE){
                    SEOclosed++;
                 }
             }
         
         }
     
         SEOcodes=codes;
         SEOindex=SEOcodes.indexOf(SEO);
         while(SEOindex >=0){
               SEOcount++;
               SEOcodes=SEOcodes.substring(SEOindex+SEOlen);
               SEOindex=SEOcodes.indexOf(SEO);
         }
         
         
         
         LSCWcodes=codes;
         LSCWindex=LSCWcodes.indexOf(LSCW);
         while(LSCWindex >=0){
               LSCWcount++;
               LSCWcodes=LSCWcodes.substring(LSCWindex+LSCWlen);
               LSCWindex=LSCWcodes.indexOf(LSCW);
         } 
   
        props.add(NewProps);
        NewProps.SEO_Count__c=SEOcount;
        NewProps.LSCW_Count__c=LSCWcount;
        NewProps.SEO_Closed__c=SEOclosed;
        NewProps.ImplementationCodes__c=codes;
        NewProps.WriteCodes__c=False; 
        SEOcodes=Null;
        SEOindex=0;
        SEOcount=0;
        SEOclosed=0;
        LSCWcodes=Null;
        LSCWindex=0;
        LSCWcount=0;
        codes=Null;
        
    }
   
   }
   }
   
   
   
}

}

 

 

 

Here is trigger:

 

Re: System.LimitException: Too many code statements: 200001

Here is the before update trigger:

 

trigger PropertyUpdates on Property_Account__c (before update) {

    public PropertyProductCodes  clsPropertyProductCodes=new PropertyProductCodes();

           clsPropertyProductCodes.lstNewProps = Trigger.new;
           clsPropertyProductCodes.lstOldProps = Trigger.old;

           clsPropertyProductCodes.ProductCodes();
    
}

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger CaseUpdates caused an unexpected exception, contact your administrator: CaseUpdates: execution of BeforeUpdate caused by: System.ListException: DML statment found null SObject at position 0: Class.PropertyUpdatebyCode.PropertyUpdatebyCode: line 23, column 1". 

 

 

Getting this error anytime the for loop should be populating my properties array. 

 

 

Apex Class

 

public class PropertyUpdatebyCode{

      Public List<Case> lstNewCases = new List<Case>();
      Public List<Case> lstOldCases = new List<Case>();
    
        public void PropertyUpdatebyCode() {

 

        //variables
        Map<Id,Case>  mapVerifyOldCases=new Map<Id,Case>();
        List<Property_Account__c> properties = new list<Property_Account__c>();
        

 

        //populates map with old values for comparison
        For(Case CaseOld : lstOldCases){ mapVerifyOldCases.put(CaseOld.id,CaseOld);}
        

 

        //populates array for DML update expression
        For(Case CaseNew: lstNewCases){ 
            IF(CaseNew.Property__c!=Null && 

                CaseNew.XLS01__c==TRUE &&

                (CaseNew.IsClosed != mapVerifyOldCases.get(CaseNew.Id).IsClosed || 

                CaseNew.Property__c!= mapVerifyOldCases.get(Case New.Id).Property__c)){
                            
                properties.add(CaseNew.Property__r);
        
             }
        }     
        

        //DML updates if array isn't empty
        IF(properties.size()>0){
          
          update properties;
        
        }      
                        
                   
}        
}

 

 

Here is my trigger - which just populates the variable arrays for my apex class.

 

trigger CaseUpdates on Case (before insert,before update) 
{
         
           //instantiate class
           public PropertyUpdatebyCode  clsPropertyUpdatebyCode=new PropertyUpdatebyCode();

 

           //populate varibles
           clsPropertyUpdatebyCode.lstNewCases = Trigger.new;
           clsPropertyUpdatebyCode.lstOldCases = Trigger.old;

 

           //calls method
           clsPropertyUpdatebyCode.PropertyUpdatebyCode();
           
}

I have a page that loads a set of records [based on a query] and includes some inputfields to apply changes to the associated records. The page loads the right records and the fields that I 'get-set' [inputtext] in the controller extension do update. But any values in the inputfields type get lost.

 

The inputText fields are ButtonClick and RC Setter - these two save - but the rest of the field values are lost. Any suggestions would be great!

 

Here is my controller extension [extends the case StandardSetController]- which includes two methods for 'SaveClose' and 'SaveNext' and following this is the visualforce page code.

 

 

public with sharing class CaseExtension {

    //Global Variables    
    private ApexPages.StandardSetController controller;
    Private final string InEditUser=UserInfo.getUserId();
    public String onClick { get; set; }  
    Public String RCSetter   { get; set; } 
    
    // Standard Controller Constructor  
    public CaseExtension(ApexPages.StandardSetController Controller) {
    
    this.controller = controller;
            
    }
    
    public ApexPages.StandardSetController caseRecords{
    
       Get{
           if(caseRecords==null){
           

             caseRecords = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id,ButtonClick__c,CaseNumber,Account.Name,

                  Cancellation_Date__c,Completion_Date__c,Target_SLA_Current__c,Implementation_Notes__c,
                  Implementation_Delay__c,Implementation_Delay_Notes__c,Delay_Details__c,Cancellation_Reason__c,New_Case_Comment__c,

                 OMS_Quote_no__c,Property_Name__c,
                  Opportunity_c__c,Bundle__c,Product__c,Status_RC__c,InEditUser__c,InEditExpiring__c FROM Case WHERE InEditUser__c =: InEditUser]));
           }
           return caseRecords;
       }
       Private set;
    }       
       
    public List<Case> getcSelected(){
       return (List<Case>) caseRecords.getRecords();
    }   
    
     
         //getOptions for ButtonClick Method
        public List<SelectOption> getOptions(){
               
        List<SelectOption> options = new List<SelectOption>();
        
        options.add(new SelectOption('','--select--'));
        options.add(new SelectOption('Next','Next RC'));
        options.add(new SelectOption('Previous','Previous RC'));
        options.add(new SelectOption('getProperty','Assign Property Contact'));
        options.add(new SelectOption('getCorporate','Assign Corporate Contact'));
        
        return options;
        }     

    
       //Save and Close method
   
        
      public PageReference SaveClose(){
           
           
           for(Case e :getcSelected()){
                     
             e.ButtonClick__c=onClick;
             e.InEditUser__c=Null;
             e.RC_Setter__c=RCSetter;
                          
           }
                  
           Update getcSelected();
                  
       
        PageReference pageRef = new PageReference('/500/o');
        pageRef.setRedirect(true);
        return pageRef;
     
       } 
         

 //Save and Next method
         public PageReference SaveNext(){
            
          
            for(Case g :getcSelected()){
          
            g.ButtonClick__c=onClick;
            g.RC_Setter__c=RCSetter;
            }
           
           Update getcSelected();
                 
           PageReference pageRef =  page.InEditUpdateOne;
           pageRef.setRedirect(true);
           return pageRef;  
        
        }       
     
 }

 

 

 

VisualForce Page:

 

<apex:page standardController="Case" extensions="CaseExtension"
    recordSetVar="implementations">
    
   
  <apex:sectionHeader title="New Field Values"/>
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
         <apex:commandButton value="Save and Close"
            action="{!saveClose}" onclick="NoPrompt();"/>
            <apex:commandButton value="Save and Next"
            action="{!saveNext}" onclick="NoPrompt();"/>
        
       </apex:pageBlockButtons>
     
     
      <apex:tabPanel switchType="client" selectedTab="TabOne" id="theTabPanel">
       <apex:tab label="Standard Details" name="StandardDetails" id="tabOne">

        <apex:pageBlockSection title="" showHeader="false" 
          collapsible="false">
          
                  <apex:selectList Label="ButtonClick" value="{!onClick}" size="1">
                     <apex:selectOptions Value="{!Options}"/>
                  </apex:selectList>
                  
                  
                  <apex:inputField Label="Case Owner" value="{!Case.OwnerId}" Required="False"/>
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:inputField value="{!Case.Target_SLA_Current__c}"/>
                  
                  <apex:inputField value="{!Case.Client_Contacted_Date__c}" Required="False"/>
                  
                   <apex:inputField value="{!Case.ContactId}" Required="False"/>
                   
                    <apex:pageBlockSectionItem />
                   <apex:inputTextArea value="{!Case.Implementation_Notes__c}" rows="5" cols="75"/>
                   <apex:inputTextArea value="{!Case.Implementation_Delay_Notes__c}" rows="5" cols="75"/>
                    <apex:pageBlockSectionItem />
                   
          </apex:pageBlockSection>
        </apex:tab>
        
        <apex:tab label="Administration" name="Administration" id="tabTwo">

            <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">
        
        <apex:inputText Label="RC Setter" value="{!RCSetter}"/>
        <apex:inputField value="{!Case.Cancellation_Reason__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Case.Completion_Date__c}"/>
        <apex:inputField value="{!Case.Cancellation_Date__c}"/>
         <apex:pageBlockSectionItem />
        

          </apex:pageBlockSection>
        </apex:tab>

        

        </apex:tabPanel>
        
      <apex:pageBlockSection title="Selected Implementations" columns="1">
        <apex:pageBlockTable value="{!cSelected}"
            var="c">
               
                 <apex:column headerValue="Case No">
                              <apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink>
                  </apex:column>
                  <apex:column value="{!c.OMS_Quote_No__c}"/>
                  <apex:column value="{!c.Account.Name}"/>
                  <apex:column value="{!c.Property_Name__c}"/>
                  <apex:column value="{!c.Opportunity_c__c}"/>
                  <apex:column value="{!c.Bundle__c}"/>
                  
                <apex:column value="{!c.Product__c}"/>
                <apex:column value="{!c.Status_RC__c}"/>
    <apex:column value="{!c.Target_SLA_Current__c}"/>
    <apex:column value="{!c.Implementation_Delay__c}"/>
    <apex:column value="{!c.Implementation_Delay_Notes__c}"/>
    <apex:column value="{!c.InEditExpiring__c}"/>
                                                
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

 

This controller extension to the standardsetcontroller defines a custom Save method called 'SaveClose'. A query in the constructor holds the 'InEdit' array of records that should be updated when this method is called. The page loads as expected with the records - but the SaveClose method line for Update 'InEdit' doesn't actually update the records. 

 

I know the method is running - because the page reference lines do run. But the Update InEdit line isn't updating any records. Maybe I'm not defining my array correctly? 

 

Any help or suggestions would be great.

 

Here is extension class:

 

public with sharing class InEditExtensionOne {

//Global Variables
private ApexPages.StandardSetController controller;
Private final string InEditUser=UserInfo.getUserId();
public list<case> InEdit { get; set; }


// Standard Controller Constructor
public InEditExtensionOne(ApexPages.StandardSetController Controller) {

this.controller = controller;
this.InEdit=[SELECT Id,CaseNumber,Account.Name,Cancellation_Date__c,Completion_Date__c
FROM Case WHERE InEditUser__c =InEditUser];

}




//Save and Close method


public PageReference SaveClose(){




for(Case e :InEdit){


e.InEditUser__c=Null;
e.InEditTime__c=Null;
e.InEditExpiring__c=Null;

}

Update InEdit;



PageReference pageRef = new PageReference('/500/o');
pageRef.setRedirect(true);
return pageRef;

}

}

 

 

 

Here is the visualforce page:

 

<apex:page standardController="Case" extensions="InEditExtensionOne"
    recordSetVar="implementations">
    
    <script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
    
    var allowPrompt = true;
    
    function unloadMessage(){
        if(allowPrompt){
        message = "Wait! Please hit 'Save and Close' before exiting the page."
        
        }
         else {
         message = "Please confirm your changes."
         allowPrompt = true;
        }
        return message;
    }
    
    function setBunload(on){
        window.onbeforeunload = (on) ? unloadMessage : null;
    }
    setBunload(true);
    
    
    function NoPrompt()
    {
      allowPrompt = false;
    }
    
    
    </script>
   
  <apex:sectionHeader title="New Field Values"/>
  <apex:form >
    <apex:pageBlock >
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save and Close"
            action="{!saveClose}" onclick="NoPrompt();"/>
            <apex:commandButton value="Save and Next"
            action="{!saveNext}" onclick="NoPrompt();"/>
       </apex:pageBlockButtons>
     
     
      <apex:tabPanel switchType="client" selectedTab="TabOne" id="theTabPanel">
       <apex:tab label="Standard Details" name="StandardDetails" id="tabOne">

        <apex:pageBlockSection title="" showHeader="false" 
          collapsible="false">
          
                  <apex:selectList Label="ButtonClick" value="{!onClick}" size="1">
                     <apex:selectOptions Value="{!Options}"/>
                  </apex:selectList>
                  <apex:inputField Label="Case Owner" value="{!Case.OwnerId}" Required="False"/>
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:pageBlockSectionItem />
                  <apex:inputField value="{!Case.Target_SLA_Current__c}"/>
                  
                  
                  
                  <apex:inputField value="{!Case.Implementation_Delay__c}"/>
                  <apex:inputField value="{!Case.Client_Contacted_Date__c}" Required="False"/>
                  <apex:inputField value="{!Case.Delay_Details__c}"/>
                  
                   <apex:inputField value="{!Case.ContactId}" Required="False"/>
                   
                                  
                   
                    <apex:pageBlockSectionItem />
                   <apex:inputTextArea value="{!Case.Implementation_Notes__c}" rows="5" cols="75"/>
                   <apex:inputTextArea value="{!Case.Implementation_Delay_Notes__c}" rows="5" cols="75"/>
                    <apex:pageBlockSectionItem />
                   
          </apex:pageBlockSection>
        </apex:tab>
        
        <apex:tab label="Administration" name="Administration" id="tabTwo">

            <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

           

        
        <apex:inputField value="{!Case.RC_Setter__c}"/>
        <apex:inputField value="{!Case.Cancellation_Reason__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Case.Completion_Date__c}"/>
        <apex:inputField value="{!Case.Cancellation_Date__c}"/>
         <apex:pageBlockSectionItem />
        

          </apex:pageBlockSection>
        </apex:tab>

        <apex:tab label="India Operations" name="IndiaOperations" id="tabThree">

        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

        <apex:inputField value="{!Case.Property__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        <apex:inputTextArea value="{!Case.New_Case_Comment__c}" rows="3" cols="75"/>
         <apex:pageBlockSectionItem />
          <apex:pageBlockSectionItem />

        </apex:pageBlockSection>
        </apex:tab>

        <apex:tab label="Marketplace Suite" name="Marketplace" id="tabFour">

        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

        <apex:inputField value="{!Case.Pilot__c}"/>
        <apex:inputField value="{!Case.Kick_off_Meeting__c}"/>
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Case.Project_Plan__c}"/>
        <apex:inputField value="{!Case.Sales_Checklist__c}"/>
        <apex:inputField value="{!Case.Weekly_Status__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        </apex:pageBlockSection>
        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false" Columns="1">
        
        <apex:inputTextArea value="{!Case.Historical_Comments__c}" rows="4" cols="185"/>
         <apex:pageBlockSectionItem />

        </apex:pageBlockSection>
        </apex:tab>

        <apex:tab label="Migration" name="Migration" id="tabFive">

        <apex:pageBlockSection title="" showHeader="false" 
            collapsible="false">

        <apex:inputField value="{!Case.Products_Sold__c}"/>
         <apex:inputField value="{!Case.Account_Set_Up__c}"/>
          <apex:inputField value="{!Case.Upsell__c}"/>
           <apex:inputField value="{!Case.Dev_Prep_Work__c}"/>
            <apex:inputField value="{!Case.Upsell_Detail__c}"/>
        <apex:pageBlockSectionItem />
        <apex:pageBlockSectionItem />
        
        <apex:inputField value="{!Case.Resident_Portal_Last_Activity_Date__c}"/>
          <apex:inputField value="{!Case.Date_Sent_to_Sales__c}"/>
           <apex:inputField value="{!Case.Uses_Velocity_06062013__c}"/>
            <apex:inputField value="{!Case.Date_Back_from_Sales__c}"/>
            <apex:inputField value="{!Case.WH_Price_List__c}"/>
             <apex:pageBlockSectionItem />


        </apex:pageBlockSection>
        </apex:tab>


        </apex:tabPanel>
        
      <apex:pageBlockSection title="Selected Implementations" columns="1">
        <apex:pageBlockTable value="{!InEdit}"
            var="c">
               
                 <apex:column headerValue="Case No">
                              <apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink>
                  </apex:column>
                  
                  <apex:column value="{!c.Account.Name}"/>
                  
                  
                
                                                
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

This trigger ends up passing nothing to the two class methods I'm calling. Can someone help me debug? Here is my Trigger.

 

Purpose - if one of two contact lookups is changed in the account - it should update the related contact lookup field on a related Property_Account__c object.

 

 

trigger AccountUpdate on Account (before update) {
       
        Map<Id,Account> newAccountMap = Trigger.newMap;
        Map<Id,Account> oldAccountMap = Trigger.oldMap;
      
        List<Account> accspmig = new list<Account>();
        List<Account> accsppay = new list<Account>();
     
       for(Id AccountId: newAccountMap.keySet()){
             Account myNewAccount = newAccountMap.get(AccountId);
             Account myOldAccount = oldAccountMap.get(Accountid);
  
           IF(myNewAccount.MigrationContacta__r  <> myOldAccount.MigrationContacta__r){
            accspmig.add(myNewAccount);          
           }
        

           IF(myNewAccount.PaymentsContacta__r <> myOldAccount.PaymentsContacta__r){
            accsppay.add(myNewAccount);  
           }

           }

            AccountUpdate.MigContact(accspmig);
            AccountUpdate.PayContact(accsppay);

}