• Chrisbrisbane
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

Good Morning,

 

I am fairly new to apex and have been trying to create a Trigger that updates all OpportunityLineItem Quantity field to a specific value from a named Expected_Number_Of_Students__c on the related Opportunity.

 

I have got the following  compile error:

 

Error: Initial term of field expression must be a concrete SObject: MAP<String,Decimal> at line 23 column 32

 

The code is as follows.

 

trigger opportunityLineItemsQuantity on Opportunity (after update) {
    //Get list of record types from Opportunity
    list<RecordType> rTypes = [Select Name, Id from RecordType Where SObjectType= 'Opportunity'];
    
    //Create a Map for the Opportunity record types
    Map<String,Id> OppRecordTypes = new Map<String, Id>{};
    for(RecordType rt: rtypes)
    OppRecordTypes.put(rt.Name,rt.Id);
       
    //Create a map for Opportunity records
    Map<String, Decimal> oppList = new Map<String, Decimal>{};
    
    //Iterate through the Opportunities
    for(Opportunity opp : Trigger.New)  
    if(opp.RecordTypeId == OppRecordTypes.get('ELT Digital Products Opportunity')){
    if(Opp.Expected_Number_of_Students__c != Null){
    oppList.put(opp.Id,Opp.Expected_Number_Of_Students__c);
    }
    }

    //Get Opportunity Line Items that are associated to the Opportunity
    for(OpportunityLineItem oli :  [Select OpportunityId, Quantity From OpportunityLineItem Where OpportunityId In : oppList.keyset()]){
   //This is where the code is failing. This is where I want the OpportunityLineItem Quantity to be the same as the Opportunity Expected_Number_Of_Sudents__c value.

   oli.Quantity = oppList.get(oppList.Expected_Number_Of_Students__c);
    
    }

}

 

 

I am not sure how to resolve this on line 23 I would be very grateful for some guidance on this.

 

Thanks

Hello,

 

I am  new to Apex and I am trying to write a trigger.

 

In the User object I have a field called Business_Stream__c which is a picklist.

 

In the Account object I havea field called Business_Stream__c which is a multi select picklist and is a required field.

 

On creation of the account record I would like the Business_Stream__c field in Account to be the same as the Owners Business_Stream__c field in the User object.

 

The trigger that I have at the moment is below 

 

trigger ChrisAccountTest on Account (before insert) {
    Set<string> ownerId = new Set<string>();
    for(Account act : Trigger.New) {
        ownerId.add(act.ownerId);
    } 
    Map<id,User> idToUser = new Map<id,user([select id,Business_Stream__c from user where id in : ownerId]);
    for(Account act: Trigger.New){
        act.Business_Stream__c = (idToUser.get(act.ownerId)).Business_Stream__c ;
    }
}

 

The problem is on creation of the Account record the Business_Stream__c field is not being pre populated to that of the Business_Sream__c field in the User object. Business_Stream_c in Accounts is a required field so I have to set the Business_Stream__c field to a value and then save the record. After saving the record the you can see that the trigger has fired and the Business_Stream__c field on Accounts matches that of the Owners in the User object.

 

Is there anyway to have the field Business_Stream__c in Accounts pre populated before the record is saved?

 

Any help is greatly appreciated. 

Good Morning,

 

I am fairly new to apex and have been trying to create a Trigger that updates all OpportunityLineItem Quantity field to a specific value from a named Expected_Number_Of_Students__c on the related Opportunity.

 

I have got the following  compile error:

 

Error: Initial term of field expression must be a concrete SObject: MAP<String,Decimal> at line 23 column 32

 

The code is as follows.

 

trigger opportunityLineItemsQuantity on Opportunity (after update) {
    //Get list of record types from Opportunity
    list<RecordType> rTypes = [Select Name, Id from RecordType Where SObjectType= 'Opportunity'];
    
    //Create a Map for the Opportunity record types
    Map<String,Id> OppRecordTypes = new Map<String, Id>{};
    for(RecordType rt: rtypes)
    OppRecordTypes.put(rt.Name,rt.Id);
       
    //Create a map for Opportunity records
    Map<String, Decimal> oppList = new Map<String, Decimal>{};
    
    //Iterate through the Opportunities
    for(Opportunity opp : Trigger.New)  
    if(opp.RecordTypeId == OppRecordTypes.get('ELT Digital Products Opportunity')){
    if(Opp.Expected_Number_of_Students__c != Null){
    oppList.put(opp.Id,Opp.Expected_Number_Of_Students__c);
    }
    }

    //Get Opportunity Line Items that are associated to the Opportunity
    for(OpportunityLineItem oli :  [Select OpportunityId, Quantity From OpportunityLineItem Where OpportunityId In : oppList.keyset()]){
   //This is where the code is failing. This is where I want the OpportunityLineItem Quantity to be the same as the Opportunity Expected_Number_Of_Sudents__c value.

   oli.Quantity = oppList.get(oppList.Expected_Number_Of_Students__c);
    
    }

}

 

 

I am not sure how to resolve this on line 23 I would be very grateful for some guidance on this.

 

Thanks

Hello,

 

I am  new to Apex and I am trying to write a trigger.

 

In the User object I have a field called Business_Stream__c which is a picklist.

 

In the Account object I havea field called Business_Stream__c which is a multi select picklist and is a required field.

 

On creation of the account record I would like the Business_Stream__c field in Account to be the same as the Owners Business_Stream__c field in the User object.

 

The trigger that I have at the moment is below 

 

trigger ChrisAccountTest on Account (before insert) {
    Set<string> ownerId = new Set<string>();
    for(Account act : Trigger.New) {
        ownerId.add(act.ownerId);
    } 
    Map<id,User> idToUser = new Map<id,user([select id,Business_Stream__c from user where id in : ownerId]);
    for(Account act: Trigger.New){
        act.Business_Stream__c = (idToUser.get(act.ownerId)).Business_Stream__c ;
    }
}

 

The problem is on creation of the Account record the Business_Stream__c field is not being pre populated to that of the Business_Sream__c field in the User object. Business_Stream_c in Accounts is a required field so I have to set the Business_Stream__c field to a value and then save the record. After saving the record the you can see that the trigger has fired and the Business_Stream__c field on Accounts matches that of the Owners in the User object.

 

Is there anyway to have the field Business_Stream__c in Accounts pre populated before the record is saved?

 

Any help is greatly appreciated.