-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
11Questions
-
10Replies
Problem with test coverage
trigger NMO_CaseOppurtunity_PrimaryLogic_BIBU on Opportunity__c(before insert,beforeupdate){
list<Opportunity__c> lstCaseOpptyToUpdate = new list<Opportunity__c>();//lstCaseOpptyToUpdate is used to update CO that are not a part of trigger.
list<lead> lstLeadsToUpdate = new list<lead>();//lstLeadsToUpdate is used to update the lead owner whenever a primary CO changes.
set<Id> setLeadIds = new set<Id>();
map<Id,lead> mapLeads = new map<Id,lead>();
map<id,list<Opportunity__c>> mapLeadWiseCaseOpty = new map<id,list<Opportunity__c>>();
map<id,id> mapLeadAssignOwner = new map<id,id> ();
list<Opportunity__c> colst1=new list<Opportunity__c>() ;
for(Opportunity__c co:trigger.new){
setLeadIds.add(co.lead__c);// Gather all lead IDs related to the Case Oppurtunities.
}
for(Lead l : [select id,ownerId,(select id,OwnerId,Primary_Opportunity__c,Primary_Override__c from Case_Opportunities__r) from Lead where id in :setLeadIds]){
mapLeadWiseCaseOpty.put(l.id,l.Case_Opportunities__r);// map used to have all the related Case Oppurtunities for the lead IDs
mapLeads.put(l.id,l);
}
// When Record is inserted
if(trigger.isInsert){
for(Opportunity__c co:trigger.new){
colst1=mapLeadWiseCaseOpty.get(co.lead__C);// colst1 contains all the case oppurtunities related to the lead.
if(colst1.size()!=0){//check if it has any siblings
if(co.Primary_Override__c=='Yes'){// check if current case oppurtunity wants to become the primary CO.
for(integer i=0;i<colst1.size();i++){ //make all other CO in the system to false
colst1[i].Primary_Opportunity__c=false;
colst1[i].Primary_Override__c='No';
lstCaseOpptyToUpdate.add(colst1[i]);
}
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
else{
co.Primary_Opportunity__c=false;
}
}
else{//No Siblings
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
}
}
// when record is updated
if(trigger.isUpdate) {
set<id> cOids=new set<id>();
for(Opportunity__c coSet:trigger.new){
cOids.add(coSet.id);
}
for(Opportunity__c co:trigger.new){
colst1=mapLeadWiseCaseOpty.get(co.lead__C);// colst1 contains all the case oppurtunities related to the lead.
if(colst1.size()!=0){//it has siblings
if(co.Primary_Override__c=='Yes'){// check if current case oppurtunity wants to become the primary CO.
for(integer i=0;i<colst1.size();i++){ //make all other CO in the system to false
if((colst1[i].id!=co.id) && (!cOids.contains(colst1[i].id))){
colst1[i].Primary_Opportunity__c=false;
colst1[i].Primary_Override__c='No';
lstCaseOpptyToUpdate.add(colst1[i]);
}
}
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
else{
if(co.Primary_Opportunity__c!=true){
co.Primary_Opportunity__c=false;
}
else{
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
}
}
else{//No Sibings
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
}
}
//Final DML
if(lstCaseOpptyToUpdate.size()>0){
try{
update lstCaseOpptyToUpdate;
}
catch(System.DMLException e){
set<id> exleadIds=new set<id>();
for(Opportunity__c coError:lstCaseOpptyToUpdate){
exleadIds.add(coError.lead__c);
}
for(Opportunity__c coError1:trigger.new){
if(exleadIds.contains(coError1.lead__c)){
coError1.addError('The System encountered a problem when attempting to update related Case Oppurtunities:'+e.getMessage());
}
}
}
}
if(lstLeadsToUpdate.size()>0){
try{
update lstLeadsToUpdate;
}
catch(System.DMLException e){
set<id> exleadIds=new set<id>();
for(Lead luerror:lstLeadsToUpdate){
exleadIds.add(luerror.id);
}
for(Opportunity__c coError:trigger.new){
if(exleadIds.contains(coError.lead__c)){
coError.addError('The System encountered a problem when attempting to update lead owner:'+e.getMessage());
}
}
}
}
}
This is my code and i had written a test class for this which is covering only 76% of code and my org needs above 85%. The problem is i cannot cover the try catch methods in the code. could any one help me on how to write test class to throw an exception and enter the code in to exception....its urgent
-
- koti91
- July 03, 2012
- Like
- 0
- Continue reading or reply
Help on trigger
Hello I need to help on writing some trigger logic. Here is the requirement:
I had two objects objA and obj B.
objB has a Master-Detail Relationship to objA.
on objB i had a custom field called: ID_Number__c
on objA i had a custom field called: objB_ID_Numbers__c.
I need to write a trigger on objB...when ever a record is inserted or updated...or deleted ....then what should happen is...ID_Number__c field on obj B needs to be copied to objB_ID_Numbers__c on objA.
Example: when record 1 is inserted with ID_Number__c as 123 to objB then objA.objB_ID_Numbers__c should have the value 123.
when record 2 is inserted with ID_Number__c as 456 to objB then objA.objB_ID_Numbers__c should have the value 123;456
when record1 is deleted then objA.objB_ID_Numbers__c should have 456.
Each time record is inserted or updated or deleted then objA.objB_ID_Numbers__c field should be calculated processing all records(i.e when record 1 is inserted we have 123, when record 2 is inserted then we will be having 123;456 , when second time record is inserted objA.objB_ID_Numbers__c field should again calculate from the first taking record 1 in to consideration).
can any one help in writing this trigger. its very urgent....
-
- koti91
- June 19, 2012
- Like
- 0
- Continue reading or reply
Help for a SOQL Query
I had two objects . Lead__c and Oppurtunity__c.
Oppurtunity__c has a look up to Lead__c . Lead__c has many oppurtunities related to it.
I need to find if Lead__c has one oppurtuntiy or more.
can any one help
-
- koti91
- June 06, 2012
- Like
- 0
- Continue reading or reply
Need Help in a trigger
i had two objects Lead and a custom object named: thisoppurtunity(tO).
thisoppurtunity(tO) had a look up to lead. thisoppurtunity has custom fileds check box named: primarytO(Read Only Field)
and primaryoverride .
now my requirement is:
when ever a tO gets created or updated . i need to make sure that tO is the only tO on the lead with primarytO field checked.i.e a Lead can have only one tO as primarytO.
only one tO can be primary for a lead.if there is only one tO for a lead ,it will be default be the primary
when a second tO is added if that needs to be primary then user needs to then click on the primaryoverride checkbox to then switch the primarytO flag- also at that point primaryoverride field will be unchecked.
and also as per ownership the ownership of primary tO is reflected on the lead(i.e lead owner will be same as the owner of primary tO).
I am trying to write the logic this way but could not complete it.
when trigger is fired :
checks for the primary tO
if the tO is the only tO on the lead it leaves the primarytO flag turned on
if there is more than one tO it ensures there is always only one primarytO
if a primary override flag is checked it transfers the primarytO flag over to requesting tO
steps:
1) sets the old primarytO flag to false
2) sets the requesting tO flag to true
3) unchecks the primaryoverride flag on the requesting tO
on the next iteration of trigger batch if the tO is marked as primary it updates the lead with same owner .
can any one help me in writing a trigger for this. Trigger should be ia bulkify way.
-
- koti91
- June 06, 2012
- Like
- 0
- Continue reading or reply
need to find out start date and end date for a batch to be processed
Hi
I need help in finding out the start and end date for a batch,
.
I had a custom setting initilize check box field , when ever it is false i need to start my batch process from the day it is running to 4 months .i.e end date should be after 4 months.
ex: if my batch is running today (05/30/2012)and initialize is false , then my start date should be today(05/30/2012) and end date should be (08/31/2012).
if initialize is true then my start date should be 08/01/2012 and end date should be 08/31/2012.
Can any one help in finding out the start date and end date for this example.
-
- koti91
- May 30, 2012
- Like
- 0
- Continue reading or reply
Trigger Help
I had two objects : Obj A and Obj B
ObjB has a lookup relationship to objA.
objA-> fields->a1,a2,a3
objB->fields->b1,b2,b3
i need to create a trigger on objB (before insert and before update)
if trigger.isinsert then copy three fields from objA to obj B(i.e copy filed values a1,a2,a3 to b1,b2,b3)
if trigger .is update then check if the three fields are equal on obj A . if equal do nothing else update values from Obj A.
I need to write this in bulkify way. plzzz help.
-
- koti91
- May 30, 2012
- Like
- 0
- Continue reading or reply
clean up record ID
hi
I had an object A where I fire a triggger after update to create an Event and task. Record Id of event and task are stored on object A. but on some condition if i delete Event and task, record id fields are not deleted on object A. i need to clean up the record id fields stored on object A when event and task are deleted. here is my code
for (objectA a: inactive records){
listeventIDs.add(a.event_id__c);
listtaskIds.add(a.task_id__c);
}
list<event> lstevents= [select id from event where Id in: listeventIDs and startDateTime>:now()];
list<task> lsttasks=[select id from task where Id in :listtaskIds and status='not started'];
if(lstevents.size()>0){
delete lstevents;
}
if(lsttasks.size()>0){
delete lsttasks;
}
how do i clean up the record id fields on object A when task and event records are deleted.
plz help??//
-
- koti91
- May 14, 2012
- Like
- 0
- Continue reading or reply
Fetch Error
when i am trying to load the Dev org in to my eclipse i am getting an error saying that:
Unable to fetch and save Force.com components to project:
LIMIT_EXCEEDED: Too many files in retrieve call, limit is:5000(LIMIT_EXCEEDED)
Abort or Continue Force.com project creation?
can anyone tell me the reason why is this hapenning. Its very urgent
Thanks
-
- koti91
- May 08, 2012
- Like
- 0
- Continue reading or reply
Trigger Code Help
Hi
I am new to Apex Coding and i had a scenario like the below which i dont know how to start. can any one plz help.
I need to write a trigger on Object A(with 4 record types in it say 1,2,3,4)
After update trigger fires only when
1. A.checkbox is checked
2. A.Picklist1='test'
3. A.Picklist2=somevalue
4. A.previous value of picklist1 != 'test'
if all the conditions above are met then trigger needs to create records in object B with a Recordtype of R with the following conditions.
1. if ObjectA. record type =1
then need to copy some values from A and put it in B
2. if if ObjectA. record type =2
then need to copy some values from A and put it in B
3. if ObjectA. record type =3
then need to copy some values from A and put it in B
4. if ObjectA. record type =4
then need to copy some values from A and put it in B.
I need this logic to be in a BUlkify way.....can any one help......
-
- koti91
- April 13, 2012
- Like
- 0
- Continue reading or reply
Trigger on Insert adn update help plzzzz
Hi
I am new to salesforce and i need some help in writing a trigger
Object A and Object B . Object B has a look up for Object A
when ever record is inserted in to object A i need to create records in object B( Condition is: I have a start date and end date on object A . Number of records need to be created are Start Date - End Date +1 on object B with each record having a date.ex: Stat Date- 3/12, End Date - 7/12 then i need to create 5 records on object B. with Date field populated.
-
- koti91
- April 13, 2012
- Like
- 0
- Continue reading or reply
Trigger Help
hello
I am new to SFDC Development and i need some help with the trigger.
I created two objects A and B. there is no relation between these objects and i had event id and event id fields on both objects.
On Object A i also had a status pick list field which has pass and Fail values.
on object A records are loaded by some ETL Process and after loading that records i am firing a trigger on A which will process the reocrds for the status value pass and then
1. checks to see if event exists by checking event ID on A against event ID on object B.
how to compare this ......plz help
-
- koti91
- April 11, 2012
- Like
- 0
- Continue reading or reply
Problem with test coverage
trigger NMO_CaseOppurtunity_PrimaryLogic_BIBU on Opportunity__c(before insert,beforeupdate){
list<Opportunity__c> lstCaseOpptyToUpdate = new list<Opportunity__c>();//lstCaseOpptyToUpdate is used to update CO that are not a part of trigger.
list<lead> lstLeadsToUpdate = new list<lead>();//lstLeadsToUpdate is used to update the lead owner whenever a primary CO changes.
set<Id> setLeadIds = new set<Id>();
map<Id,lead> mapLeads = new map<Id,lead>();
map<id,list<Opportunity__c>> mapLeadWiseCaseOpty = new map<id,list<Opportunity__c>>();
map<id,id> mapLeadAssignOwner = new map<id,id> ();
list<Opportunity__c> colst1=new list<Opportunity__c>() ;
for(Opportunity__c co:trigger.new){
setLeadIds.add(co.lead__c);// Gather all lead IDs related to the Case Oppurtunities.
}
for(Lead l : [select id,ownerId,(select id,OwnerId,Primary_Opportunity__c,Primary_Override__c from Case_Opportunities__r) from Lead where id in :setLeadIds]){
mapLeadWiseCaseOpty.put(l.id,l.Case_Opportunities__r);// map used to have all the related Case Oppurtunities for the lead IDs
mapLeads.put(l.id,l);
}
// When Record is inserted
if(trigger.isInsert){
for(Opportunity__c co:trigger.new){
colst1=mapLeadWiseCaseOpty.get(co.lead__C);// colst1 contains all the case oppurtunities related to the lead.
if(colst1.size()!=0){//check if it has any siblings
if(co.Primary_Override__c=='Yes'){// check if current case oppurtunity wants to become the primary CO.
for(integer i=0;i<colst1.size();i++){ //make all other CO in the system to false
colst1[i].Primary_Opportunity__c=false;
colst1[i].Primary_Override__c='No';
lstCaseOpptyToUpdate.add(colst1[i]);
}
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
else{
co.Primary_Opportunity__c=false;
}
}
else{//No Siblings
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
}
}
// when record is updated
if(trigger.isUpdate) {
set<id> cOids=new set<id>();
for(Opportunity__c coSet:trigger.new){
cOids.add(coSet.id);
}
for(Opportunity__c co:trigger.new){
colst1=mapLeadWiseCaseOpty.get(co.lead__C);// colst1 contains all the case oppurtunities related to the lead.
if(colst1.size()!=0){//it has siblings
if(co.Primary_Override__c=='Yes'){// check if current case oppurtunity wants to become the primary CO.
for(integer i=0;i<colst1.size();i++){ //make all other CO in the system to false
if((colst1[i].id!=co.id) && (!cOids.contains(colst1[i].id))){
colst1[i].Primary_Opportunity__c=false;
colst1[i].Primary_Override__c='No';
lstCaseOpptyToUpdate.add(colst1[i]);
}
}
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
else{
if(co.Primary_Opportunity__c!=true){
co.Primary_Opportunity__c=false;
}
else{
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
}
}
else{//No Sibings
co.Primary_Opportunity__c=true;
co.Primary_Override__c='No';
lead l = mapLeads.get(co.lead__c);
l.ownerId = co.ownerId;
lstLeadsToUpdate.add(l);
}
}
}
//Final DML
if(lstCaseOpptyToUpdate.size()>0){
try{
update lstCaseOpptyToUpdate;
}
catch(System.DMLException e){
set<id> exleadIds=new set<id>();
for(Opportunity__c coError:lstCaseOpptyToUpdate){
exleadIds.add(coError.lead__c);
}
for(Opportunity__c coError1:trigger.new){
if(exleadIds.contains(coError1.lead__c)){
coError1.addError('The System encountered a problem when attempting to update related Case Oppurtunities:'+e.getMessage());
}
}
}
}
if(lstLeadsToUpdate.size()>0){
try{
update lstLeadsToUpdate;
}
catch(System.DMLException e){
set<id> exleadIds=new set<id>();
for(Lead luerror:lstLeadsToUpdate){
exleadIds.add(luerror.id);
}
for(Opportunity__c coError:trigger.new){
if(exleadIds.contains(coError.lead__c)){
coError.addError('The System encountered a problem when attempting to update lead owner:'+e.getMessage());
}
}
}
}
}
This is my code and i had written a test class for this which is covering only 76% of code and my org needs above 85%. The problem is i cannot cover the try catch methods in the code. could any one help me on how to write test class to throw an exception and enter the code in to exception....its urgent
- koti91
- July 03, 2012
- Like
- 0
- Continue reading or reply
Trigger Help
I had two objects : Obj A and Obj B
ObjB has a lookup relationship to objA.
objA-> fields->a1,a2,a3
objB->fields->b1,b2,b3
i need to create a trigger on objB (before insert and before update)
if trigger.isinsert then copy three fields from objA to obj B(i.e copy filed values a1,a2,a3 to b1,b2,b3)
if trigger .is update then check if the three fields are equal on obj A . if equal do nothing else update values from Obj A.
I need to write this in bulkify way. plzzz help.
- koti91
- May 30, 2012
- Like
- 0
- Continue reading or reply
Trigger Code Help
Hi
I am new to Apex Coding and i had a scenario like the below which i dont know how to start. can any one plz help.
I need to write a trigger on Object A(with 4 record types in it say 1,2,3,4)
After update trigger fires only when
1. A.checkbox is checked
2. A.Picklist1='test'
3. A.Picklist2=somevalue
4. A.previous value of picklist1 != 'test'
if all the conditions above are met then trigger needs to create records in object B with a Recordtype of R with the following conditions.
1. if ObjectA. record type =1
then need to copy some values from A and put it in B
2. if if ObjectA. record type =2
then need to copy some values from A and put it in B
3. if ObjectA. record type =3
then need to copy some values from A and put it in B
4. if ObjectA. record type =4
then need to copy some values from A and put it in B.
I need this logic to be in a BUlkify way.....can any one help......
- koti91
- April 13, 2012
- Like
- 0
- Continue reading or reply
Trigger Help
hello
I am new to SFDC Development and i need some help with the trigger.
I created two objects A and B. there is no relation between these objects and i had event id and event id fields on both objects.
On Object A i also had a status pick list field which has pass and Fail values.
on object A records are loaded by some ETL Process and after loading that records i am firing a trigger on A which will process the reocrds for the status value pass and then
1. checks to see if event exists by checking event ID on A against event ID on object B.
how to compare this ......plz help
- koti91
- April 11, 2012
- Like
- 0
- Continue reading or reply
bad value for restricted picklist field
when trying to add an Event. I have previously called describeSObject on SaveAs and it brings back these three stings "Busy","Free" and "Out of Office". "Busy" and "Free" work fine but "Out of Office" throws the error.
This just looks like a bug to me. Anyone able to get this to work?
-Bob
- bobmanc
- May 31, 2006
- Like
- 0
- Continue reading or reply