• 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,

 

Does anyone know if it is possible to update all child records associated with a change to the parent?

 

EG:

One Account called: Monster Toys LTD - with a lookup field that looks up to the Opportunitity object

 

100 Contacts related to the Monster Toys LTD - with a lookup field that looks up to the Opportunitity object

 

I would like that when the Monster Toys LTD opportunity lookup is changed it will also change all the related Contact record lookups also.

 

Any help and code example would be so helpful and appreciated. Many thanks in advance.

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,

 

Does anyone have some idea / sample code for turning a lookup relationship in a dropdown list?

 

My users are finding it tuff with so many lookup options.

 

Hoping someone can assist. Thanks

 

 

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,

 

I am having a head scratching moment with VF. I have uploaded this same post a couple of times already but with no luck so far. Hoping someone can help this time around.

 

I have created a series of VF Pages. When using inputfields and entering data into a blank field all is fine. But when the field has data stored and you are trying to enter a blank entry the blank update does not write to the database. Just like it ignores the blank entry.

 

Can someone.. anyone help please? 

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>

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>

Dear all,

 

Hoping someone can help here.

 

I am trying to write a trigger and class on Lead Convert to create a couple of custom object records.

 

The thing is I am only hitting 60% of coverage but the tested trigger is not showing in the

 

"Trigger code coverage" part? Any clues?

 

Also can someone help me with trying to achieve 100% please? Been trying for a couple of weeks to get this right now.

Thanks in advance

 

trigger LeadConvert2 on Lead (before update) {
     
      if (Trigger.new.size() == 1) {
      
        if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {
  
            if (Trigger.new[0].ConvertedAccountId != null) {

                Account a = [Select a.Id, a.Name, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
                a.Description = Trigger.new[0].Name;
                a.OwnerId = Trigger.new[0].Sales_ME1__c;
                update a;
 
                    // insert a Sales Monitor Line
                    Line_del__c obj = new Line_del__c();
                    obj.Name = a.Name;
                    obj.Team_s_Dept_s_del__c = Trigger.new[0].Sales_Team__c;
                    obj.ME1__c = Trigger.new[0].Sales_ME1__c;
                    obj.ME2__c = Trigger.new[0].Sales_ME2__c;
                    obj.DTR3__c = Trigger.new[0].Sales_DTR__c; 
                    obj.CU__c = Trigger.new[0].Sales_CU__c;
                    obj.Project_Completion_Date__c = Trigger.new[0].Sales_Project_Completion_Date__c;
                    obj.Division__c = Trigger.new[0].Sales_Division__c; 
                    obj.Utility__c = Trigger.new[0].Sales_Utility__c;
                    obj.Renewal_Acquisition__c = Trigger.new[0].Sales_Acquisition__c;
                    obj.Next_Action_Comments__c = Trigger.new[0].Sales_Next_Action_Comments__c;
                    obj.Notes__c = Trigger.new[0].Sales_Notes__c;                                        
                    obj.Linked_Account__c = a.Id;                    
                    insert obj;
                    
                    // insert a CR Monitor Line
                    if (Trigger.new[0].CR_ME1__c!= Null && Trigger.new[0].CR_DTR__c != Null) {
                    
                    Line_del__c obj2 = new Line_del__c();
                    obj2.Name = a.Name;
                    obj2.Team_s_Dept_s_del__c = 'a0P300000053prk';
                    obj2.ME1__c = Trigger.new[0].CR_ME1__c;
                    obj2.ME2__c = Trigger.new[0].CR_ME2__c;
                    obj2.DTR3__c = Trigger.new[0].CR_DTR__c; 
                    obj2.CU__c = Trigger.new[0].CR_CU__c;
                    obj2.Next_Action_Comments__c = Trigger.new[0].CR_Next_Action_Comments__c;
                    obj2.Notes__c = Trigger.new[0].CR_Notes__c;
                    obj2.Linked_Account__c = a.Id;
                    insert obj2;
                    
                    }
                    }
               }      
        }
 
}



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

    Account accts = new Account(
    Name = 'TestCompany',
    OwnerId = '00530000004WakH' );
    insert accts;
    
    Line_del__c salesLine = new Line_del__c(
    Name = 'Test insert new Monitor Line',
    // FF Sales Team 
    Team_s_Dept_s_del__c = 'a0P300000053ps9', 
    ME1__c = '00530000004WakH',
    ME2__c = '00530000005dI0c',  
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Project_Completion_Date__c = System.Today(),
    Division__c = 'Util-Eyes',
    Utility__c = 'Gas',
    Renewal_Acquisition__c = 'Acquisition', 
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id   
    );

    Line_del__c CRLine = new Line_del__c (
    Name = 'Test insert new Monitor Line', 
    // CR Team 
    Team_s_Dept_s_del__c = 'a0P300000053prk', 
    ME1__c = '00530000004WakH', 
    ME2__c = '00530000005dI0c',      
    DTR3__c = System.Today(),
    CU__c = System.Today(),
    Next_Action_Comments__c = 'Test Next Action Text',
    Notes__c = 'Test Notes Text',
    Linked_Account__c = accts.Id   
    );
        
    test.StartTest();
    insert salesLine;
    insert CRLine;
    test.StopTest();
    
    }    
}

Dear all,

 

I am hoping some can solve this puzzle. It is testing my patience. I have a lead convert trigger on convert. The trigger is supposed to create 2 custom object records but it is creating duplicates of each record so that is 4 records!!!

 

trigger LeadConvert on Lead (after update) {
     
    for(Lead lead:System.Trigger.new) {     

    if (Trigger.new.size() == 1) {
  
            if (Trigger.new[0].ConvertedAccountId != null) {
 
                Account a = [Select a.Id, a.Name, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
                a.Description = Trigger.new[0].Name;
                update a;
 
                    // insert a Sales Monitor Line
                    Line_del__c obj = new Line_del__c();
                    obj.Name = a.Name;
                    obj.Team_s_Dept_s_del__c = lead.Sales_Team__c;
                    obj.ME1__c = lead.Sales_ME1__c;
                    obj.ME2__c = lead.Sales_ME2__c;
                    obj.DTR3__c = lead.Sales_DTR__c; 
                    obj.CU__c = lead.Sales_CU__c;                    
                    obj.Linked_Account__c = a.Id;                    
                    insert obj;
                    
                    // insert a CR Monitor Line
                    Line_del__c obj2 = new Line_del__c();
                    obj2.Name = a.Name;
                    obj2.Team_s_Dept_s_del__c = 'a0PV0000000F8Kr';
                    obj2.ME1__c = lead.CR_ME1__c;
                    obj2.ME2__c = lead.CR_ME2__c;
                    obj2.DTR3__c = lead.CR_DTR__c; 
                    obj2.CU__c = lead.CR_CU__c;
                    obj2.Linked_Account__c = a.Id;
                    insert obj2;
                   
                 }
        
        
        }
 
    }
}

Hi,

 

I have written a trigger to creates a record for a custom obj "Line_del__c" after a Lead is inserted. 

 

The only thing I can not get the Name of the Lead to pass over to "Line_del__c" Name field. It keeps passing an id like "a0OV000000078Mg"

 

Can not work it out!! Can anyone help please?

 

trigger InsertNewMonitorLine on Lead (after insert) {

    List<Lead> lam = new List<Lead>();
    
    for(Lead a: trigger.new){
    
        // insert a custom object 
        Line_del__c obj = new Line_del__c();
        obj.Name = a.Name;
        obj.Team_s_Dept_s_del__c = 'a0PV0000000EhlM';
        obj.ME1__c = '00530000004WakH';
        obj.Linked_NB__c = a.Id;
        obj.DTR3__c = System.Today();
        insert obj;
        
        insert lam;
    }
}


 


Hi all,

 

I have a written a trigger and Test class to go with but only getting 84%. I have searched high and low for some sort of reason why the 2 lines in red are not being covered but have had no luck and no idea. Can anyone help please?

 



trigger CopyDownME1ME2 on Line_del__c (before insert, before update) {

    List<String> CopyME1ME2 = new List<String>{};
    
    if (Trigger.isInsert) {
    for(Line_del__c a: trigger.new)
        a.suggested_ME1__c = a.ME1__c;
    
    for(Line_del__c b: trigger.new)
        b.suggested_ME2__c = b.ME2__c;
    }
    if (Trigger.isUpdate) {
    for(Line_del__c c: trigger.new)
    if (Trigger.new[0].ME1__c != Trigger.old[0].ME1__c)
        c.suggested_ME1__c = c.ME1__c;
    
    for(Line_del__c d: trigger.new)
    if (Trigger.new[0].ME2__c != Trigger.old[0].ME2__c)
        d.suggested_ME2__c = d.ME2__c;
    }
}

Code Coverage 84%

 
Hi all,
Does anyone have any idea how to create a trigger that will save a record upon (& before) the "submit for approval" is pressed?

Hi all,

 

I am very new to Apex and have written my first Trigger to Update an OwnerID from a custom lookup field. Both fields on the same Merchandise__c custom object. Although a very simple trigger it works in my developer org. I have a couple of questions.. I would be more than grateful.. if anyone can kindly assist.

 

1. Is it safe to have such simple code for a Trigger (re: governor limits and endless loops etc)? Should I add anything else?

 

2. Can anyone help with the test code for this trigger please?

 

Thanks in advance :smileyhappy:

 

trigger UpdateOwner on Merchandise__c (before insert, before update) {
    for (Merchandise__c a: Trigger.New){
    a.Ownerid= a.TriggerUser__c;
    }
}

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?