• LAMCORP
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 44
    Replies

Hi all,

 

I have written a trigger that is intended to create a record of the same object when certain fields are populated. Like a clone with different fields populated as required. 

 

The triggers works fine and clones when I update one record. When I try to update more than one (EG 10) in one time it just brings back either one clone or 2 of the same clone. 

 

Puzzling... Any one able to see what I am doing wrong?

 

Appreciate your time in advance:)

 

trigger cloneElecAMsignOff on Electricity_Meter__c (before update,after update) {

     List<Electricity_Meter__c> myList = new List<Electricity_Meter__c>();
      

     for(Electricity_Meter__c a: trigger.new) {

        // insert Elec meter if Deal Done
        if (
        a.Account_Manager_Sign_Off_Date_Time__c != Null &&
        a.Lam_Clone_Date_Time_Stamp__c == Null && (
        a.Deal_Done_Not__c == 'Deal Done (Existing client / Existing meter)' ||
        a.Deal_Done_Not__c == 'Deal Done (New Meter, New Client)' || 
        a.Deal_Done_Not__c == 'Deal Done (New Meter, Exisiting Client)')) {
        
        Electricity_Meter__c b = new Electricity_Meter__c();                
        b.Name = a.Name; 
        b.Site_name__c = a.Site_name__c;
        b.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c;
        b.Account__c = a.Account__c; 
        b.Linked_Basket__c = a.Linked_Basket__c;
        b.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        b.Current_Supplier__c = a.Winning_Supplier__c;
        b.Previous_Supplier__c = a.Current_Supplier__c;
        b.Meter_Status__c = '(2) Active (Not yet live)';
        b.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;       
        b.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        b.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        b.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        b.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        b.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        b.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        b.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        b.Site_Address_New__c = a.Site_Address_New__c;
        b.Site_Postcode__c = a.Site_Postcode__c;
        b.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        b.Billing_Address_New__c = a.Billing_Address_New__c;
        b.Billing_Postcode__c = a.Billing_Postcode__c;
        b.Number_of_employees__c = a.Number_of_employees__c;
        b.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        b.Profile_Class__c = a.Profile_Class__c;
        b.MTC_LLF__c = a.MTC_LLF__c;
        b.Meter_Details__c = a.Meter_Details__c; 
        b.MOP_CED__c = a.MOP_CED__c;
        b.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        b.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        b.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        b.Payment_Method__c = a.Payment_Method__c;
        b.DD_Type__c = a.DD_Type__c;
        b.VAT__c = a.VAT__c;
        b.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        b.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        b.AQ__c = a.Winning_Supply_AQ__c;
        b.Total_KVA__c = a.Total_KVA__c; 
        b.Commission_p__c = a.Winning_Commision_p_kwh__c;
        b.Commission_per_year__c = a.Winning_Commission_year__c;
        b.Commission_Percent__c = a.Winning_Commission_Contract__c;  
        myList.add(b);  
        
        }


               
        // insert Elec meter if Deal Not Done
        else if (a.Account_Manager_Sign_Off_Date_Time__c != Null && 
        a.Lam_Clone_Date_Time_Stamp__c == Null && (
        a.Deal_Done_Not__c == 'Deal not done / Not responding - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Not responding - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Went direct with supplier - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Went direct with supplier - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Went with another consultant - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Went with another consultant - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Meter removed - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Meter removed - Client lost')) {
        
        Electricity_Meter__c c = new Electricity_Meter__c();                
        c.Name = a.Name; 
        c.Site_name__c = a.Site_name__c;
        c.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c; 
        c.Account__c = a.Account__c; 
        c.Linked_Basket__c = a.Linked_Basket__c;
        c.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        c.Current_Supplier__c = a.Winning_Supplier__c;
        c.Previous_Supplier__c = a.Current_Supplier__c;
        c.Meter_Status__c = '(5) Active (Not with Maxim Eyes)';
        c.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;        
        c.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        c.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        c.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        c.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        c.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        c.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        c.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        c.Site_Address_New__c = a.Site_Address_New__c;
        c.Site_Postcode__c = a.Site_Postcode__c;
        c.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        c.Billing_Address_New__c = a.Billing_Address_New__c;
        c.Billing_Postcode__c = a.Billing_Postcode__c;
        c.Number_of_employees__c = a.Number_of_employees__c;
        c.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        c.Profile_Class__c = a.Profile_Class__c;
        c.MTC_LLF__c = a.MTC_LLF__c;
        c.Meter_Details__c = a.Meter_Details__c; 
        c.MOP_CED__c = a.MOP_CED__c;
        c.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        c.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        c.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        c.Payment_Method__c = a.Payment_Method__c;
        c.DD_Type__c = a.DD_Type__c;
        c.VAT__c = a.VAT__c;
        c.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        c.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        c.AQ__c = a.Winning_Supply_AQ__c;
        c.Total_KVA__c = a.Total_KVA__c; 
        c.Commission_p__c = a.Winning_Commision_p_kwh__c;
        c.Commission_per_year__c = a.Winning_Commission_year__c;
        c.Commission_Percent__c = a.Winning_Commission_Contract__c;
        myList.add(c);           
        
        }

         
    try {
        insert myList; 
    } catch (system.Dmlexception e) {
        system.debug (e);   
        
    }
        
    }
        
        
}

Hi all,

 

I am having a bit of bother. Hoping someone that has come across this can help.

 

I used to have a lead convert trigger and test class that worked fine.

 

Because of the usual (adding required fields) my test class needs updating.

 

It passes in Sandbox without any problems but I get an error when validating in production.

 

The error is:

LeadConvert2.TestLeadConvert2()Class711

Failure Message: "System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00Qa0000014MjCuEAK; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert2: execution of AfterUpdate caused by: System.DmlException: I...

 

 

Line 71 is " Database.LeadConvertResult lcr = Database.convertLead(lc);  "

 

Can anyone help?

 

 

@isTest
Private Class LeadConvert2{
static TestMethod void TestLeadConvert2(){

    Lead ld = new Lead(
    Company = 'TestCompany',
    OwnerId = '00530000005dI0c',
    LastName = 'Test',
    Phone = '07856656565',
    Email = 'test@test.com',
    Preferred_to_be_contacted_by__c = 'Email Only',
    Util_Eyes__c = True,
    LeadSource = 'Other',
    Linked_Basket__c  = '00130000015Cxwt',     
    Linked_Affiliate_1__c = 'a0N30000005aRCu',
    Aff_1_Profit_Share__c = 0,
    ME_rep_that_nurtured_this_lead__c = '00530000004WakH',
    industry = 'Finance',
    Initial_Email_Sent__c = True,
    Elec_AQ_Guestimation__c = 1000000000,
    Relationship_Status_New__c = 'Green [All good]',
    Client_Potential__c = 'Diamond [More than 100k]',
   
    Sales_Team__c = 'a0P300000053ps9',
    Sales_ME1__c = '00530000004WakH',
    Sales_ME2__c= '00530000005dI0c',
    Sales_DTR__c = System.Today(),
    Sales_Division__c = 'Util-Eyes',
    Sales_Utility__c = 'Gas',
    Sales_Acquisition__c = 'Acquisition',

    CR_ME1__c = '00530000004WakH',
    CR_ME2__c = '00530000005dI0c',
    CR_DTR__c = System.Today()
    );
    insert ld;
    
    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(ld.id);
    lc.setDoNotCreateOpportunity(true);
    lc.setOverwriteLeadSource(false);
    lc.setSendNotificationEmail(false);
    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);
    System.assert(lcr.isSuccess());
    system.debug('leadconvert'+lcr.isSuccess());
    system.debug('errors=' + lcr.getErrors());

    Account accts = new Account(
    Name = 'TestCompany',
    OwnerId = '00530000004WakH',
    ParentId = '00130000015Cxwt',
    Team_s_Dept_s__c = 'a0P300000053ps9',
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',
    Account_Status__c = 'Live',
    Local_Network_Folder__c = 'Test',
    Relationship_Status__c = 'Green [All good]',
    Client_Potential__c = 'Diamond [More than 100k]',
    Linked_Affiliate_1__c = 'a0N30000005aRCu',
    Aff_1_Profit_Split__c = 0
    );
    insert accts;
                
    //insert a Contact
    Contact con1 = new Contact (
    AccountId = accts.Id,
    FirstName = 'Contact',
    LastName = 'One',
    Email = 'contact1@test.com',
    Phone = '08445715544',
    MobilePhone = '07966565985',
    Title = 'Manager'
    );
    insert con1;
    
    Line_del__c salesLine = new Line_del__c(
    Name = 'Test insert new Monitor Line',
    Team_s_Dept_s_del__c = 'a0P300000053ps9',
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',  
    DTR3__c = System.Today(),
    Stage__c ='Closed Off',
    Division__c = 'Util-Eyes',
    Utility__c = 'Gas',
    Renewal_Acquisition__c = 'Acquisition',
    Linked_Account__c = accts.Id
    );

    Line_del__c CRLine = new Line_del__c (
    Name = 'Test insert new Monitor Line',
    Team_s_Dept_s_del__c = 'a0P300000053prk',
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',      
    DTR3__c = System.Today(),
    Stage__c ='Closed Off',
    Division__c = 'Dept',
    Utility__c = 'n/a',
    Renewal_Acquisition__c = 'n/a',
    Linked_Account__c = accts.Id   
    );
        
    test.StartTest();
    insert salesLine;
    insert CRLine;
    test.StopTest();
    
    }    
}

Dear all,

 

I am trying to write a simple trigger that will update child custom object fields from a parent (Account) record.

When I save the record it seems to make the fields null. Can anyone suggest anything? Probably something very simple I just can't see it.

 

trigger ElecPassME1ME2Team on Electricity_Meter__c (after insert, after update) {

    For(Electricity_Meter__c Elec: Trigger.New){
        Elec.Sales_Team__c = Elec.Account__r.Team_s_Dept_s__c;
        Elec.ME1__c = Elec.Account__r.ME1__c;
        Elec.ME2__c = Elec.Account__r.ME2__c;  
    }

Dear all,

 

I have been looking for a way to redirect a user when they click on a VF page button.

I want to redirect the user away from the standard new buttons found when you first click on any object each object.

 

Similarly to html <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">

 

Does anyone have a solution to this?

 


Dear all,

 

Hoping someone can help. I have written a VF page that has input fields.The issue that when there is data in a field and then wanting to enter a blank value, the changes are not written to the database.

 

Does anyone know if this a common issue or is there a solution to this?

 

 

 

<apex:page standardController="Electricity_Meter__c" recordSetVar="ElecMeters" tabStyle="Electricity_Meter__c" sidebar="false">

<style>
    body {font-family: Arial Unicode MS;}
    h1 {color:black;font-size: 20px;text-decoration: none}
</style>
    <p><h1> Logging Table - Elec Meter(s) </h1></p><p></p>  
    <apex:form >
        
        <apex:pageblock >
        <apex:pageMessage summary="Validation error" severity="warning" strength="3" />
        <apex:pageMessages />
                
        <apex:pageBlockButtons >        
            <apex:commandButton value="Save" action="{!save}" reRender="resultBlock"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>            
        </apex:pageBlockButtons>
        
                <apex:pageBlockTable value="{!selected}" var="elecM">
                
                    <apex:column value="{!elecM.name}"/>
                    <apex:column value="{!elecM.Site_Address2__c}"/>
                    <apex:column value="{!elecM.Meter_Details__c}"/>
                    
                    <apex:column headerValue="Winning Supplier">
                    <apex:inputField value="{!elecM.Winning_Supplier__c}"/>
                    </apex:column>
                                      
                    <apex:column headerValue="Commission (p/kwh)">
                    <apex:inputField value="{!elecM.Required_Commision_p_kwh__c}"/>
                    </apex:column>                    
                    
                    <apex:column headerValue="Commission (£/year))">
                    <apex:inputField value="{!elecM.Required_Commision_Contract__c}"/>
                    </apex:column>
                    
                    <apex:column headerValue="Commission (%/Contract)">
                    <apex:inputField value="{!elecM.Required_Commision_Contract_Spend__c}"/>
                    </apex:column>
                                       
                    <apex:column value="{!elecM.AQ__c}"/>
                    <apex:column headerValue="Annual Consumption as contract">
                    <apex:inputField value="{!elecM.Renw_Contract_Consumption__c}"/>
                    </apex:column>
                    
                    <apex:column headerValue="Start Date">
                    <apex:inputField value="{!elecM.Required_contract_start_date__c}"/>
                    </apex:column>
                    
                    <apex:column headerValue="End Date">
                    <apex:inputField value="{!elecM.Required_contract_end_date_1__c}"/>
                    </apex:column>
                                        
                    <apex:column headerValue="TL Check)">
                    <apex:inputField value="{!elecM.TL_Logging_Check__c }"/>
                    </apex:column>
                                        
                </apex:pageBlockTable>
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

Scenario: mass edit selected items in a related list (Opportunities of an Account) - how to get the mass edit page to sort same as selected items?

 

Step 1: Select using check boxes 3 Opportunities in the Account related list of Opportunities

Oppo Mass Edit

Step 2: Display the mass edit page

oppo mass edit 2 of 2

 

RESULT: the mass edit page is not sorted in same order as the related list (Month 02 - Month 01 - Month 03 rather than Month 03 - Month 02 - Month 01)

 

Why would this be?

 

Here is the VF code for the page:

<apex:page standardController="Opportunity" recordSetVar="opps">
<script>function setFocusOnLoad() {}</script> <!-- disables focus from going to first field calendar picker -->
<apex:form >
    <apex:sectionHeader title="Change fields on monthly billing opportunities"/>
    <apex:pageBlock mode="edit">
        <apex:pagemessages />
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Change to new value">
            <apex:inputField value="{!Opportunity.Opportunity_Source__c}"/>
            <apex:inputField value="{!Opportunity.NextStep}"/>
            <apex:inputField value="{!Opportunity.Remarks__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Changes apply to these selected items">    
            <apex:pageBlockTable value="{!selected}" var="o" cellspacing="20px">
                <apex:column value="{!o.name}"/>
                <apex:column value="{!o.stagename}"/>
                <apex:column value="{!o.closeDate}"/>
                <apex:column value="{!o.amount}"/>
                <apex:column headerValue="Service Start Date">
                    <apex:inputField value="{!o.SnS_Contract_Start_Date__c}"/>
                </apex:column>    
                <apex:column headerValue="Service End Date">
                    <apex:inputField value="{!o.ContractEndDate__c}"/>
                </apex:column>
            </apex:pageBlockTable>        
        </apex:pageBlockSection>
    </apex:pageBlock>   
</apex:form>

</apex:page>

 

So, here is the detailed question:

 

A. The pageBlockTable uses the {!selected} value which maps to the getSelected() method on the StandardSetController so it correctly picks up the three selected items. There is no controllerExtension.

 

B. The VF documentation Winter 12 version pg 68 states: "When you are using a standard list controller, the returned records sort on the first column of data, as defined by the current view, even if that column is not rendered."  Well, wouldn't the current view be the related list Account>Opportunities? and that first column is Opportunity Name so why is the pageBlockTable not sorted by Opportunity.Name?  It appears to sort randomly as if out of a map.

 

I realize this could be solved with APEX controllerextension but fidelity to the selected items should be preserved without recourse to APEX.

 

Thoughts?