• NightShade
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 25
    Replies

Hi All,

 

I have a trigger scenario below and a small piece of trigger code which I have written and which is not working . If someone could please help me .

 

Thanks and Regards

 

 

Scenario : I have a custom object DMA and it has two fields currently on it ZIp Code and DMA (it is basically a City name). Also on the Account Object I have a DMA field  and the BillingPostalCode is a Standard Field .Now by comparing the Zip Codes between the Account and DMA object , I want to take the DMA field value from DMA obejct and populate the field DMA on the Account Object . I have begun the trigger as follows but I am running into lot of errors .Right now there is no relationship between the objects , I am wondering if I should be creating a field of some type to establish the relationship.Please help.

 

Error : Initial term of field expression must be a concrete SObject: LIST<Account> at line 11 column 6

 

 

 

trigger UpdActDma on DMA__c (After Update , After Insert ) {


 
 List<Account> act  = new List <Account>();
 act= [Select BillingPostalCode, DMA__c from Account];
 for (DMA__c dma :Trigger.new) {
   
    If( dma.Zip_Code__c == act.BillingPostalCode ){
    
     act.DMA__r.DMA__c = dma.DMA__c;   << ----- Line 11
     
     }
 }

}

 

 

Hi everyone,

 

 

I have a trigger below for which I got help from the discussion board itself but i have not been able to completely resolve it . Below is my Scenario , error and my Trigger code . If  someone could help me please resolve this I would be grateful.

 

Thanks and Regards

 

 

Scenario :

Opportunity Line Items have Products with Product Codes which contain the Strings : FF , RT and (RT and FF). I need to update the account fields “Fit Finder Status “ and “Fit Finder Program “ related to the Opportunity which has products with these product Codes. For an Opportunity with FF string in the product code the  Fit Finder Status  is updated to  ‘Active’ and Fit Finder Program  to ‘Paying-Reg Customer’ .If another product with RT or (RT and FF) is added under the same opportunity the Fit Finder Status  is updated to  ‘Active’ and Fit Finder Program  to ‘Right Track’.

 

 

 

Error : 

FFStatus: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: 001P000000FEbeqIAD: Trigger.FFStatus: line 80, column 9  

The above Id is an Account ID .

 

Trigger Code :

 

trigger FFStatus on Opportunity (after update) {

  String f ='FF';

  String r='RT';

    Set<ID> OppIDs = new Set<ID>();

    Set<ID> AcctIDs = new Set<ID>();

    for(Opportunity o:Trigger.New){

        OppIDs.add(o.id);

        AcctIDs.add(o.accountid);

    }

    Map<ID,Account> ACCTMAP = new Map<ID,Account>([select id,Fit_Finder_Status__c from Account where id in:AcctIDs]);  //create a map list of accounts with the Account ID as the key

    //Added these for debugging

    system.debug('\n\n');//puts a blank line in the debug output

    system.debug('\n\nGOT ' + OppIDs.size() + ' Unique Opportunities in this trigger.');

    system.debug('\n\nGOT ' + AcctIDs.size() + ' Unique Accounts in this trigger.');

    system.debug('\n\n');//puts a blank line in the debug output

    //end debug section 1

 

    List<Account> updACCT = new List<Account>(); //accounts in this list will get updated

    Set<Account> AcctSet = new Set<Account>();

   Map <ID,List<OpportunityLineItem>> OLIOPPMAP  = new Map <ID,List<OpportunityLineItem>> (); //create a map list of OLI with the Opportunity ID as the key, note that each opp could have more than one OLI

    for(OpportunityLineItem oli: [Select o.PricebookEntryId ,o.PricebookEntry.ProductCode,OpportunityID from OpportunityLineItem o where o.OpportunityId in :Trigger.New ]){

        if(OLIOPPMAP.containsKey(oli.OpportunityID)){

            OLIOPPMAP.get(oli.OpportunityID).add(oli);

        }else{

            OLIOPPMAP.put(oli.OpportunityID,new List<OpportunityLineItem>{oli});

        }

    }

     for (Opportunity Op :Trigger.new){

 

       if(OLIOPPMAP.containsKey(Op.id)){

            for (  OpportunityLineItem oli : OLIOPPMAP.get(Op.id) ){

                String pc;

                if(oli.PricebookEntry.ProductCode<>null){

                     pc = oli.PricebookEntry.ProductCode;

                }else{

                     pc ='';

                }

                Boolean Result = pc.Contains(f);  

                Boolean ResultR = pc.Contains(r);  

 

                if ( (Op.StageName== 'Won' || Op.StageName=='Won - Future Activation Date' ) && Result == True ){

                    Account tmpAccount = ACCTMAP.get(Op.AccountID);

                    tmpAccount.Fit_Finder_Status__c = 'Active';

                    tmpAccount.Fit_Finder_Program__c='Paying - Reg Customer';

                    AcctSet.add(tmpAccount);

                   system.debug('\n\nAcctSet has'   +AcctSet.size() + ' records');

                }

                 else if ( ((Op.StageName== 'Won' || Op.StageName=='Won - Future Activation Date' ) && ResultR == True)){

                    Account tmpAccountR  = ACCTMAP.get(Op.AccountID);

                    tmpAccountR.Fit_Finder_Status__c = 'Active';

                    tmpAccountR.Fit_Finder_Program__c='Right Track';

                  AcctSet.add(tmpAccountR);

                system.debug('\n\nAcctSet has'   +AcctSet.size() + ' records');

                    }

                  else if((Op.StageName== 'Won' || Op.StageName=='Won - Future Activation Date' ) && (ResultR == True && Result == True) ){

                     Account tmpAccountRF= ACCTMAP.get(Op.AccountID);

                     tmpAccountRF.Fit_Finder_Status__c = 'Active';

                     tmpAccountRF.Fit_Finder_Program__c='Right Track';

                    AcctSet.add(tmpAccountRF);

                    system.debug('\n\nAcctSet has'   +AcctSet.size() + ' records');

                    }

 

 

 

            }

          }

        }

     //start Debug section 2

 

       system.debug('\n\nAcctSet has'   +AcctSet.size() + ' records');

 

     // end Debug Section 2

 

     updACCT.addall(AcctSet);

 

 

     //start Debug section 3

 

     system.debug('\n\nupdACCT has ' +updACCT.size() +  ' records');

 

     //updACCT should have the same number of items as AcctSET does

 

     //end Debug Section 3

 

 try{

        update updACCT;    <<----- This the line 80 where the error refers to.

    }catch(DMLException d){

        system.debug('\n\nERROR UPDATING ACCOUNTS:  '+d.getDMLMessage(0));

    }

}

 

 

 

 

 

 

Hey ,

Need help with a trigger . Below is a trigger on products which is not firing at all i checked the debug log also and its not there . Once a opportunity is Won or Won-Future Activation date and the product code contains 'FF' the trigger should fire and Update a field on account called Fit Finder Status to 'Active'.The thing is products and opportunities are not directly related although products are shown under a related list under Opportunities.There are also Pricebook and PricebookEntry in the schema .PricebookEntry is related to Opportunities.The Code saves without errors . Can anyone please help since I am still new to these kind of triggers.

 

Thanks and Regards

 

 

trigger FFStatusA on Product2 (after update , after insert ) {

ID ID1;
ID ID2;
ID ID3;
ID ID4;
   Opportunity O = [ Select AccountId , Pricebook2Id from Opportunity  where Pricebook2Id =:ID4];


ID1=O.AccountId;

ID2=O.Pricebook2Id;

PricebookEntry Pe = [Select Pricebook2Id , ProductCode from PricebookEntry where Pricebook2Id=:ID2];
  ID3 = Pe.Pricebook2Id;
 
 Account acc = [Select  Id , Name  from Account where Id  =:ID1];
 ID4 = Acc.Id;
   
    String pc = Pe.ProductCode;
  String f ='FF';
  Boolean Result = pc.Contains(f);
 
 
for (Product2 p :Trigger.new){
 
 
 
//If (acc.Id ==o.AccountId && Pe.Pricebook2Id ==O.Pricebook2Id  ){
 // && Result == True
 
 
 If ( (O.StageName== 'Won' || O.StageName=='Won - Future Activation Date' )&& Result == True  ){
   
    
    acc.Fit_Finder_Status__pc = 'Active';
    
    }
    
 //   }
    }
    database.update(acc);
    
    
}

Hi ,

 

I have a requirement where I need to count the total number of Contacts of  type " Lead_Source_Detail__c == 'freemium LP' " for an account and put that total in a field on Account called " Number_Of_Contacts__c". When some contact upgrades to a different type (i.e other than freemium ) I need to update the Number_of_Contacts__c field so as it reflects the current total. I was initially thinking of  roll up summary fields but that would not work since there is no Master Detail relationship. So I wrote the below trigger . Now it is adding the freemium contacts for the first time but when the contact is upgraded it is not updating the Number_Of_Contacts__c field  to reflect the new total . I have tried a lot of different ways so I  apologize if the code seems messy but i never had to write a trigger at such a scale . Need help urgently .

 

 

Thanks and Regards

 

 

 

trigger UpdAct on Contact (after insert , after delete , after update ) {

Set<id> acctsids = new Set<id>();
    List<Account> ActtoUpdate = new List<Account>();
 

for (Contact c : Trigger.new)

    if (c.Lead_Source_Detail__c=='freemium LP'){
    
   
        acctsids.add(c.AccountId);
 }
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Contact c : Trigger.old){
       if  (c.Lead_Source_Detail__c =='freemium LP'){
         
         acctsids.add(c.AccountId);
         }
         
         
       else if (c.Lead_Source_Detail__c!='freemium LP'){
          
          acctsids.remove(c.AccountId);
     }
    }
    }
  database.update(ActtoUpdate);
 
 
Map<id,Account> AcctMap = new Map<id,Account>([select id, Number_Of_Contacts__c from Account where id IN :acctsids]);

 //  for (Account acc : [ Select Count_distinct(id), Number_Of_Contacts__c, (select Contact.id from Account.Contacts) from Account where Id IN :acctsids]){


// for (Contact c : [ Select Count(AccountId) from Contact where AccountId IN : acctsids]){


  for (Account acc: [select Id, Name,Number_Of_Contacts__c ,(select Contact.id from Account.Contacts) from Account where Id IN :acctsids]) {
        
        
       Contact c;  
        
       
      //  Account acc;
        
        AcctMap.get(acc.Id).Number_Of_Contacts__c = acc.Contacts.size();       
        
       // [Select Count_distinct(Name) from Contact where Lead_Source_Detail__c='freemium LP'];
        
      
        
       ActtoUpdate.add(AcctMap.get(acc.Id));
    
    
   
 // if(c.Lead_Source_Detail__c != 'freemium LP'){
 
 
//  AcctMap.get(acc.Id).Number_Of_Contacts__c = acc.Contacts.size();
 
 //Delete(ActtoUpdate);
 
   // }
 
}


    update ActtoUpdate;


}

Hi,

 

I have an urgent requirement . When the AccountName is selected on Opportunity Object I want the values from two fields on Account to  fill the same two fields on Opportunity Object before I click the save button so that if I want I can change the field values and then save it.  Please can someone help me as I am not sure how this will work out.

 

Thanks 

Hi ,

 

I need to copy the RecordTypeId into a field called Prev_Record_Type which is a text field on opportunity. There are multiple record types on the Object and I need to get the selected recordtypId.Can someone please help me with the Trigger code since  i am not all experienced in this and urgently need help .

 

Thanks and Regards

Hi ,

 

I have a requirement where in I need to have a Detail Page Button called Confirm Opportunity . When the users Click this button the Opportunity Approval Status must change to " Approved" from "To Be Confirmed " and the record type and page layout must change back to the original one before the Opportunity Approval Status was set to "To Be Confirmed".I used the On Click Java Script type and I wrote the below code for the first part but I am not sure if it is Java Script and why it is not working, it gives the below error .Also can someone please help me writing the second part that is changing the record type and page layout back to the original one since I have not had much experience with this.

 

 

Error - Missing ; before Statement .

 

if( '{!Opportunity.Approval_Status__c}'=='To Be Confirmed' && '{!Opportunity.RecordType}' == "To Be Confirmed")

{
{!Opportunity.Approval_Status__c} = "Approved";


}

Hi All,

 

I have a trigger scenario below and a small piece of trigger code which I have written and which is not working . If someone could please help me .

 

Thanks and Regards

 

 

Scenario : I have a custom object DMA and it has two fields currently on it ZIp Code and DMA (it is basically a City name). Also on the Account Object I have a DMA field  and the BillingPostalCode is a Standard Field .Now by comparing the Zip Codes between the Account and DMA object , I want to take the DMA field value from DMA obejct and populate the field DMA on the Account Object . I have begun the trigger as follows but I am running into lot of errors .Right now there is no relationship between the objects , I am wondering if I should be creating a field of some type to establish the relationship.Please help.

 

Error : Initial term of field expression must be a concrete SObject: LIST<Account> at line 11 column 6

 

 

 

trigger UpdActDma on DMA__c (After Update , After Insert ) {


 
 List<Account> act  = new List <Account>();
 act= [Select BillingPostalCode, DMA__c from Account];
 for (DMA__c dma :Trigger.new) {
   
    If( dma.Zip_Code__c == act.BillingPostalCode ){
    
     act.DMA__r.DMA__c = dma.DMA__c;   << ----- Line 11
     
     }
 }

}

 

 

Hey ,

Need help with a trigger . Below is a trigger on products which is not firing at all i checked the debug log also and its not there . Once a opportunity is Won or Won-Future Activation date and the product code contains 'FF' the trigger should fire and Update a field on account called Fit Finder Status to 'Active'.The thing is products and opportunities are not directly related although products are shown under a related list under Opportunities.There are also Pricebook and PricebookEntry in the schema .PricebookEntry is related to Opportunities.The Code saves without errors . Can anyone please help since I am still new to these kind of triggers.

 

Thanks and Regards

 

 

trigger FFStatusA on Product2 (after update , after insert ) {

ID ID1;
ID ID2;
ID ID3;
ID ID4;
   Opportunity O = [ Select AccountId , Pricebook2Id from Opportunity  where Pricebook2Id =:ID4];


ID1=O.AccountId;

ID2=O.Pricebook2Id;

PricebookEntry Pe = [Select Pricebook2Id , ProductCode from PricebookEntry where Pricebook2Id=:ID2];
  ID3 = Pe.Pricebook2Id;
 
 Account acc = [Select  Id , Name  from Account where Id  =:ID1];
 ID4 = Acc.Id;
   
    String pc = Pe.ProductCode;
  String f ='FF';
  Boolean Result = pc.Contains(f);
 
 
for (Product2 p :Trigger.new){
 
 
 
//If (acc.Id ==o.AccountId && Pe.Pricebook2Id ==O.Pricebook2Id  ){
 // && Result == True
 
 
 If ( (O.StageName== 'Won' || O.StageName=='Won - Future Activation Date' )&& Result == True  ){
   
    
    acc.Fit_Finder_Status__pc = 'Active';
    
    }
    
 //   }
    }
    database.update(acc);
    
    
}

Hi ,

 

I have a requirement where I need to count the total number of Contacts of  type " Lead_Source_Detail__c == 'freemium LP' " for an account and put that total in a field on Account called " Number_Of_Contacts__c". When some contact upgrades to a different type (i.e other than freemium ) I need to update the Number_of_Contacts__c field so as it reflects the current total. I was initially thinking of  roll up summary fields but that would not work since there is no Master Detail relationship. So I wrote the below trigger . Now it is adding the freemium contacts for the first time but when the contact is upgraded it is not updating the Number_Of_Contacts__c field  to reflect the new total . I have tried a lot of different ways so I  apologize if the code seems messy but i never had to write a trigger at such a scale . Need help urgently .

 

 

Thanks and Regards

 

 

 

trigger UpdAct on Contact (after insert , after delete , after update ) {

Set<id> acctsids = new Set<id>();
    List<Account> ActtoUpdate = new List<Account>();
 

for (Contact c : Trigger.new)

    if (c.Lead_Source_Detail__c=='freemium LP'){
    
   
        acctsids.add(c.AccountId);
 }
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Contact c : Trigger.old){
       if  (c.Lead_Source_Detail__c =='freemium LP'){
         
         acctsids.add(c.AccountId);
         }
         
         
       else if (c.Lead_Source_Detail__c!='freemium LP'){
          
          acctsids.remove(c.AccountId);
     }
    }
    }
  database.update(ActtoUpdate);
 
 
Map<id,Account> AcctMap = new Map<id,Account>([select id, Number_Of_Contacts__c from Account where id IN :acctsids]);

 //  for (Account acc : [ Select Count_distinct(id), Number_Of_Contacts__c, (select Contact.id from Account.Contacts) from Account where Id IN :acctsids]){


// for (Contact c : [ Select Count(AccountId) from Contact where AccountId IN : acctsids]){


  for (Account acc: [select Id, Name,Number_Of_Contacts__c ,(select Contact.id from Account.Contacts) from Account where Id IN :acctsids]) {
        
        
       Contact c;  
        
       
      //  Account acc;
        
        AcctMap.get(acc.Id).Number_Of_Contacts__c = acc.Contacts.size();       
        
       // [Select Count_distinct(Name) from Contact where Lead_Source_Detail__c='freemium LP'];
        
      
        
       ActtoUpdate.add(AcctMap.get(acc.Id));
    
    
   
 // if(c.Lead_Source_Detail__c != 'freemium LP'){
 
 
//  AcctMap.get(acc.Id).Number_Of_Contacts__c = acc.Contacts.size();
 
 //Delete(ActtoUpdate);
 
   // }
 
}


    update ActtoUpdate;


}