• Beau Gordon 14
  • NEWBIE
  • 55 Points
  • Member since 2015

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
Hello,

I'm trying to create a trigger that updates my campaign members status after a lead or a contact fills a web to case form, my web to case is working fine is getting the id through a javascript,but  my trigger isn't working. Someone could help me?

Here is my code:
trigger bi_WebToCaseLead on Case (before insert) {
Set<String> setCampaignMail = new Set<String>();


//List<CampaignMember> listCm = [SELECT Id,Lead.Email,LeadId,ContactId,Contact.Name,Contact.Email,CampaignId FROM CampaignMember WHERE Campaign.IsActive = true];
List<CampaignMember> listAg = [SELECT Id,Lead.Email,LeadId,ContactId,Contact.Name,Contact.Email,CampaignId FROM CampaignMember WHERE Campaign.IsActive = true AND (Lead.Email  IN :setCampaignMail OR Contact.Email IN :setCampaignMail)];

    for(CampaignMember cm : listAg){
      for(Case caso : Trigger.new){
        if(!setCampaignMail.contains(caso.SuppliedEmail)){
          setCampaignMail.add(caso.SuppliedEmail);
        }
       
        if(caso.ChaveCampanha__c != null && cm.CampaignId.equals(caso.ChaveCampanha__c)){
          cm.Status = 'Respondido';
          caso.RelacionamentoLead__c = cm.LeadId;
          }
        }
      }
  update listAg;
}

 
Hi,

I have an Opportunity after update trigger. The opportunity should contain only the equipments listed in the Equipment list(Custom setting). If any Opp equipment is not present in Custom setting list then I wanted that to be removed from a Map. I am creating a map of Equipment name(Key) and Opp(Value) but that is creating a problem as we have common equipments between opps.

Trigger code - 

Equipmap = PNC_Equipment_List__c.getAll(); //Custom setting data into a map

for(Equipment__c e : [SELECT Id,Name,Opportunity__c FROM Equipment__c WHERE Opportunity__c in :OppOwnerIdMap.keySet()]){
      EqpOppMap.put(e.Name,e.Opportunity__c);
  }

for(String str : EqpOppMap.keySet()){
         if(Equipmap.containsKey(str)){
             System.debug('Equip Present ' + str + '-' + EqpOppMap.get(str));
         }
         else{
             System.debug('**** Equip remove Opp Id :' + EqpOppMap.get(str));
             OppOwnerIdMap.remove(EqpOppMap.get(str));
         }
     }

Problem with the code -

If multiple Opps have same equipment, since am storing it in a map with key as Equipment name only few opporunities are getting stored in that map. This is causing some problem as am misssing out on some opportunities.

Ex - I have 4 opps and 3 opps have same equipments(EqupA,EqupB) which are not present in the Equipment list(Custom setting). so I want them to be removed from further processing. so I need a map/list of Opps after removal.
In this case I want only OppC in the final map/list as this EqupC is present in Equipment list(Custom setting)

Before Filter - (How can I handle this in code)

EqupA,OppA
EqupB,OppA
EqupA,OppB
EqupB,OppB
EqupC,OppC
EqupA,OppD
EqupB,OppD

After Filter -

Equpc,Oppc


Please help!

Thanks
Kumar

 
  • October 13, 2015
  • Like
  • 0
Hello,

I'm trying to create a trigger that updates my campaign members status after a lead or a contact fills a web to case form, my web to case is working fine is getting the id through a javascript,but  my trigger isn't working. Someone could help me?

Here is my code:
trigger bi_WebToCaseLead on Case (before insert) {
Set<String> setCampaignMail = new Set<String>();


//List<CampaignMember> listCm = [SELECT Id,Lead.Email,LeadId,ContactId,Contact.Name,Contact.Email,CampaignId FROM CampaignMember WHERE Campaign.IsActive = true];
List<CampaignMember> listAg = [SELECT Id,Lead.Email,LeadId,ContactId,Contact.Name,Contact.Email,CampaignId FROM CampaignMember WHERE Campaign.IsActive = true AND (Lead.Email  IN :setCampaignMail OR Contact.Email IN :setCampaignMail)];

    for(CampaignMember cm : listAg){
      for(Case caso : Trigger.new){
        if(!setCampaignMail.contains(caso.SuppliedEmail)){
          setCampaignMail.add(caso.SuppliedEmail);
        }
       
        if(caso.ChaveCampanha__c != null && cm.CampaignId.equals(caso.ChaveCampanha__c)){
          cm.Status = 'Respondido';
          caso.RelacionamentoLead__c = cm.LeadId;
          }
        }
      }
  update listAg;
}

 
Hi,

I have an Opportunity after update trigger. The opportunity should contain only the equipments listed in the Equipment list(Custom setting). If any Opp equipment is not present in Custom setting list then I wanted that to be removed from a Map. I am creating a map of Equipment name(Key) and Opp(Value) but that is creating a problem as we have common equipments between opps.

Trigger code - 

Equipmap = PNC_Equipment_List__c.getAll(); //Custom setting data into a map

for(Equipment__c e : [SELECT Id,Name,Opportunity__c FROM Equipment__c WHERE Opportunity__c in :OppOwnerIdMap.keySet()]){
      EqpOppMap.put(e.Name,e.Opportunity__c);
  }

for(String str : EqpOppMap.keySet()){
         if(Equipmap.containsKey(str)){
             System.debug('Equip Present ' + str + '-' + EqpOppMap.get(str));
         }
         else{
             System.debug('**** Equip remove Opp Id :' + EqpOppMap.get(str));
             OppOwnerIdMap.remove(EqpOppMap.get(str));
         }
     }

Problem with the code -

If multiple Opps have same equipment, since am storing it in a map with key as Equipment name only few opporunities are getting stored in that map. This is causing some problem as am misssing out on some opportunities.

Ex - I have 4 opps and 3 opps have same equipments(EqupA,EqupB) which are not present in the Equipment list(Custom setting). so I want them to be removed from further processing. so I need a map/list of Opps after removal.
In this case I want only OppC in the final map/list as this EqupC is present in Equipment list(Custom setting)

Before Filter - (How can I handle this in code)

EqupA,OppA
EqupB,OppA
EqupA,OppB
EqupB,OppB
EqupC,OppC
EqupA,OppD
EqupB,OppD

After Filter -

Equpc,Oppc


Please help!

Thanks
Kumar

 
  • October 13, 2015
  • Like
  • 0
Dear Folks,

I'm very new to Salesforce and VisualForce (of course Programming), Can some one please educate me: 

1. Why Constrcutor is required for a VisualForce Page?
2. What is the actual need of this?
3. What would happen If a constructor is not used inthe Controller?

Here is a sample code.. I understood the logic but I don't understand wht we need AcExt Constructor?

Public with sharing class AcExt {     

Public Account ac;     

Public AcExt(ApexPages.StandardController stdctrl){     
     ac = (Account)stdctrl.getRecord();     
}          

Public string GetGreeting(){     
return 'Your ID is ' +ac.id;     
}     

}

Thanks,
Kumar
I have the trigger below set up in Sandbox, but I have no Code Coverage. I need help writing a test class to check code coverage.

trigger UpdateOrderOppPrice on Order_Product__c (before insert) {
    set<Id> psi = new set<Id>();
    set<Id> osi = new set<Id>();
    set<Id> asi = new set<Id>();
    set<string> pci = new set<string>();
    set<decimal> acn = new set<decimal>();
    map<Id,string> pdci = new map<Id,string>();
    map<String,Id> msi = new map<String,Id>();
    map<Id,case> mis = new map<Id,case>();
    map<string,Titan_Contract__c> mst = new map<string,Titan_Contract__c>();
    map<string,Titan_Contract__c> mdct = new map<string,Titan_Contract__c>();
    map<string,Titan_Contract__c> mpdct = new map<string,Titan_Contract__c>();
    map<Id,decimal> pbe = new map<Id,decimal>();
    
    for(Order_Product__c order:trigger.new){
        psi.add(order.Product__c);
        osi.add(order.case_record__c);
    }
    for(PricebookEntry pe :[Select Id, UnitPrice,Product2ID,Product2.Discount_Code__c from PricebookEntry where Product2ID IN:psi]){
        pbe.put(pe.Product2ID,pe.UnitPrice);
        pdci.put(pe.Product2ID,pe.Product2.Discount_Code__c);
    }
    for(Case c:[Select ID,Bill_To_Account__c,customer_number__c,company__c,Account.Discount_Code__c,Account.Company__c from Case where Id IN:osi]){
        asi.add((id)c.Bill_To_Account__c);
        mis.put(c.Id,c);
        if(c.Account.Discount_Code__c!=null)pci.add(c.Account.Discount_Code__c);
        if(c.Account.Company__c!=null)acn.add(decimal.valueOf(c.Account.Company__c));
    }    
    for(Order_Product__c order:trigger.new){
        if(msi.containsKey(string.valueOf(order.Product__c)+mis.get(order.case_record__c).Company__c))
            order.Product__C=msi.get(string.valueOf(order.Product__c)+mis.get(order.case_record__c).Company__c);
    }
    for(Titan_Contract__c t:[SELECT Account__c, Beginning_Date__c, Customer_Number_or_Discount_Code__c, Expiration_Date__c, Price_or_Multiplier_Contract__c, 
                                Price_or_Percent_of_List_Price_1__c, Price_or_Percent_of_List_Price_2__c, Price_or_Percent_of_List_Price_3__c, 
                                Price_or_Percent_of_List_Price_4__c, Price_or_Percent_of_List_Price_5__c, Price_or_Percent_of_List_Price_6__c, 
                                Price_or_Percent_of_List_Price_7__c, Price_or_Percent_of_List_Price_8__c, Product__c, Quantity_Level_1__c, Quantity_Level_2__c, 
                                Quantity_Level_3__c, Quantity_Level_4__c, Quantity_Level_5__c, Quantity_Level_6__c, Quantity_Level_7__c, Quantity_Level_8__c, 
                                Quote_Number__c, Quote_Revision__c, Id, SystemModstamp, Name, Universal_Customer__c
                                FROM Titan_Contract__c
                                where Account__c IN:asi and Product__c IN:psi and Beginning_Date__c <:system.today() and Expiration_Date__c >:system.today()]){
        mst.put(string.ValueOf(t.Account__c).left(15)+string.ValueOf(t.Product__c),t);                              
    }
    for(Titan_Contract__c t:[SELECT Account__c, Beginning_Date__c, Customer_Number_or_Discount_Code__c, Expiration_Date__c, Price_or_Multiplier_Contract__c, 
                                Price_or_Percent_of_List_Price_1__c, Price_or_Percent_of_List_Price_2__c, Price_or_Percent_of_List_Price_3__c, 
                                Price_or_Percent_of_List_Price_4__c, Price_or_Percent_of_List_Price_5__c, Price_or_Percent_of_List_Price_6__c, 
                                Price_or_Percent_of_List_Price_7__c, Price_or_Percent_of_List_Price_8__c, Product__c, Quantity_Level_1__c, Quantity_Level_2__c, 
                                Quantity_Level_3__c, Quantity_Level_4__c, Quantity_Level_5__c, Quantity_Level_6__c, Quantity_Level_7__c, Quantity_Level_8__c, 
                                Quote_Number__c, Quote_Revision__c, Id, SystemModstamp, Name, Universal_Customer__c,Product_Discount_Code__c,Company_Number__c
                                FROM Titan_Contract__c
                                where Customer_Number_or_Discount_Code__c!=null and Customer_Number_or_Discount_Code__c IN:pci and Beginning_Date__c <:system.today() and Expiration_Date__c >:system.today()
                                 and Company_Number__c IN:acn and (Product__c IN:psi or Product__c=null)]){
        mdct.put(t.Customer_Number_or_Discount_Code__c+(t.Company_Number__c!=null?string.ValueOf(t.Company_Number__c):'')+(t.Product__c!=null?string.ValueOf(t.Product__c):''),t);                              
    }
    for(Titan_Contract__c t:[SELECT Account__c, Beginning_Date__c, Customer_Number_or_Discount_Code__c, Expiration_Date__c, Price_or_Multiplier_Contract__c, 
                                Price_or_Percent_of_List_Price_1__c, Price_or_Percent_of_List_Price_2__c, Price_or_Percent_of_List_Price_3__c, 
                                Price_or_Percent_of_List_Price_4__c, Price_or_Percent_of_List_Price_5__c, Price_or_Percent_of_List_Price_6__c, 
                                Price_or_Percent_of_List_Price_7__c, Price_or_Percent_of_List_Price_8__c, Product__c, Quantity_Level_1__c, Quantity_Level_2__c, 
                                Quantity_Level_3__c, Quantity_Level_4__c, Quantity_Level_5__c, Quantity_Level_6__c, Quantity_Level_7__c, Quantity_Level_8__c, 
                                Quote_Number__c, Quote_Revision__c, Id, SystemModstamp, Name, Universal_Customer__c,Product_Discount_Code__c,Company_Number__c
                                FROM Titan_Contract__c
                                where Product_Discount_Code__c!=null and Product_Discount_Code__c IN:pdci.values() and Product__c IN:psi  and Company_Number__c IN:acn 
                                and Beginning_Date__c <:system.today() and Expiration_Date__c >:system.today()]){
        mpdct.put(t.Product_Discount_Code__c+(t.Company_Number__c!=null?string.ValueOf(t.Company_Number__c):'')+string.ValueOf(t.Product__c),t);                                
    }
    for(Order_Product__c order:trigger.new){
        order.Price__c=null;
        string key = mis.get(order.case_record__c).Bill_To_Account__c+string.ValueOf(order.Product__c);
        system.debug(mst);
        system.debug(key);
        if(mst.containskey(key)){
            Titan_Contract__c t = mst.get(key);
            for(integer i=1;i<10;i++){
                if(t.get('Quantity_Level_'+(i+1)+'__c')==null || order.Quantity__c < (decimal)t.get('Quantity_Level_'+(i+1)+'__c')){
                    order.Price__c = (t.Price_or_Multiplier_Contract__c == 'P')?(decimal)t.get('Price_or_Percent_of_List_Price_'+i+'__c'):pbe.get(t.Product__c)*(decimal)t.get('Price_or_Percent_of_List_Price_'+i+'__c');
                    break;
                }
            }
        }
        if(order.Price__c==null){
            if(mis.get(order.case_record__c).Account.Discount_Code__c!=null){
                key=mis.get(order.case_record__c).Account.Discount_Code__c+(mis.get(order.case_record__c).Account.Company__c!=null?mis.get(order.case_record__c).Account.Company__c:'');
                if(mdct.containskey(key+string.ValueOf(order.Product__c)))key+=string.ValueOf(order.Product__c);
                if(mdct.containskey(key)){
                    Titan_Contract__c t = mdct.get(key);
                    for(integer i=1;i<10;i++){
                        if(t.get('Quantity_Level_'+(i+1)+'__c')==null || order.Quantity__c < (decimal)t.get('Quantity_Level_'+(i+1)+'__c')){
                            order.Price__c = (t.Price_or_Multiplier_Contract__c == 'P')?(decimal)t.get('Price_or_Percent_of_List_Price_'+i+'__c'):pbe.get((t.Product__c!=null?t.Product__c:order.Product__c))*(decimal)t.get('Price_or_Percent_of_List_Price_'+i+'__c');
                            break;
                        }
                    }
                }
            }
        }
        if(order.Price__c==null){
            if(pdci.containskey(order.Product__c) && pdci.get(order.Product__c)!=null){
                key=pdci.get(order.Product__c)+(mis.get(order.case_record__c).Account.Company__c!=null?mis.get(order.case_record__c).Account.Company__c:'')+string.ValueOf(order.Product__c);
                if(mpdct.containskey(key)){
                    Titan_Contract__c t = mpdct.get(key);
                    for(integer i=1;i<10;i++){
                        if(t.get('Quantity_Level_'+(i+1)+'__c')==null || order.Quantity__c < (decimal)t.get('Quantity_Level_'+(i+1)+'__c')){
                            order.Price__c = (t.Price_or_Multiplier_Contract__c == 'P')?(decimal)t.get('Price_or_Percent_of_List_Price_'+i+'__c'):pbe.get((t.Product__c!=null?t.Product__c:order.Product__c))*(decimal)t.get('Price_or_Percent_of_List_Price_'+i+'__c');
                            break;
                        }
                    }
                }
            }
        }
        if(order.Price__c==null)order.Price__c = pbe.get(order.Product__c);
    }   
}