-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
15Questions
-
44Replies
Trigger to create a copy record (similar to clone - Not handling bulk)
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:)
|
- LAMCORP
- February 16, 2013
- Like
- 0
- Continue reading or reply
Test Coverage for Lead Convert -Database.LeadConvertResult lcr = Database.convertLead(lc);
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() | Class | 71 | 1 | 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();
}
}
- LAMCORP
- February 11, 2013
- Like
- 0
- Continue reading or reply
Update all child records lookups associated with a change to the parent lookup
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.
- LAMCORP
- August 22, 2012
- Like
- 0
- Continue reading or reply
Trigger to update a child custom object from a parent (Account) record
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;
}
- LAMCORP
- August 02, 2012
- Like
- 0
- Continue reading or reply
Lookup as a dropdown - Possibly a VF page?
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
- LAMCORP
- July 05, 2012
- Like
- 0
- Continue reading or reply
Does anyone know how to simply redirect a page to a specific URL using VF?
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?
- LAMCORP
- May 28, 2012
- Like
- 0
- Continue reading or reply
VForce Inputfields not writing blank entry
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?
- LAMCORP
- May 11, 2012
- Like
- 0
- Continue reading or reply
VForce pages are not writing blank values to the database!
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>
- LAMCORP
- May 04, 2012
- Like
- 0
- Continue reading or reply
VForce pages not allowing blank values to be written to the database!
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>
- LAMCORP
- May 03, 2012
- Like
- 0
- Continue reading or reply
Test Class hitting 60% and cannot see which lines are being covered
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();
}
}
- LAMCORP
- April 24, 2012
- Like
- 0
- Continue reading or reply
Lead convert creating duplicate records
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;
}
}
}
}
- LAMCORP
- April 11, 2012
- Like
- 0
- Continue reading or reply
Trigger that creates an object record - Pass "Name" details
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;
}
}
- LAMCORP
- January 10, 2012
- Like
- 0
- Continue reading or reply
CODE COVERAGE 84% - WANTING 100% Please help :)
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;
}
}
- LAMCORP
- January 05, 2012
- Like
- 0
- Continue reading or reply
Trigger - when the "submit for approval" button is pressed automatically saves the record first
Does anyone have any idea how to create a trigger that will save a record upon (& before) the "submit for approval" is pressed?
- LAMCORP
- December 24, 2011
- Like
- 0
- Continue reading or reply
Simple Trigger and Code Coverage - Update an OwnerID from a lookup field
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;
}
}
- LAMCORP
- December 20, 2011
- Like
- 0
- Continue reading or reply
Trigger to create a copy record (similar to clone - Not handling bulk)
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:)
|
- LAMCORP
- February 16, 2013
- Like
- 0
- Continue reading or reply
Test Coverage for Lead Convert -Database.LeadConvertResult lcr = Database.convertLead(lc);
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() | Class | 71 | 1 | 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();
}
}
- LAMCORP
- February 11, 2013
- Like
- 0
- Continue reading or reply
Trigger to update a child custom object from a parent (Account) record
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;
}
- LAMCORP
- August 02, 2012
- Like
- 0
- Continue reading or reply
Does anyone know how to simply redirect a page to a specific URL using VF?
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?
- LAMCORP
- May 28, 2012
- Like
- 0
- Continue reading or reply
VForce pages are not writing blank values to the database!
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>
- LAMCORP
- May 04, 2012
- Like
- 0
- Continue reading or reply
List Controller, sorting, and the {!selected} VF value
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
Step 2: Display the mass edit page
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?
- crop1645
- November 23, 2011
- Like
- 0
- Continue reading or reply