• Jemill
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
public without sharing class trac_SetFieldsOnLockedOppExt {

    private final Opportunity lockedOpp;

    // The extension constructor initializes the private member
    // variable mysObject by using the getRecord method from the standard
    // controller.
    public trac_SetFieldsOnLockedOppExt(ApexPages.StandardController stdController) {
        this.lockedOpp = (Opportunity) stdController.getRecord();
        if( this.lockedOpp.IsClosed ) {
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'The current opportunity has been closed and cannot be modified.') );
        }
    }

    public PageReference saveLockedRecord() {
        PageReference pr = null;
        if( !lockedOpp.IsClosed ) {  
            update new Opportunity(
                Id = lockedOpp.Id,
                CloseDate = lockedOpp.CloseDate,
                Gate__c = lockedOpp.Gate__c,
                Annual_Web_SalesOpp__c = lockedOpp.Annual_Web_SalesOpp__c,
                Estimated_Signature_Date__c = lockedOpp.Estimated_Signature_Date__c,
                Stage_Qualifier__c = lockedOpp.Stage_Qualifier__c,
                Current_Affiliate_Annual_Sales_Revenue__c = lockedOpp.Current_Affiliate_Annual_Sales_Revenue__c,
                Percent_to_CJ__c = lockedOpp.Percent_to_CJ__c,
                Think_Big_Number__c = lockedOpp.Think_Big_Number__c
            );
            pr = new PageReference( '/' + lockedOpp.Id );
            pr.setRedirect( true );
        }
        return pr;
    }
}
I was told I needed to make the above class invocable so that the button/visualforce/field set it is associated with can be used within Skuid, or standard salesforce list view.  The class updates fields on a locked opp.
 
trigger ADAccountTeam on Account (before update, before insert) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Account account: Trigger.new) {
        accountIds.add(Account.Id);
    }
    
    accountIds.remove(null);
    
    Map<Id, Id> accountToTeamMemberMap = new Map<Id, Id>();

    for (AccountTeamMember teamMember: [
        select UserId, AccountId
        from AccountTeamMember
        where Account.Id in :accountIds and
            TeamMemberRole = 'CJ Advertiser Account Director'
    ]) {
        accountToTeamMemberMap.put(teamMember.AccountId, teamMember.UserId);
    }
    
    for (Account account: trigger.new) {
        if (accountToTeamMemberMap.containsKey(Account.Id)) {
            Account.CJ_Advertiser_Account_Director__c = accountToTeamMemberMap.get(Account.Id);
        }
    }

}



So this trigger puts the Account Team member into an Account field when the role = CJ Advertiser Account Director.  The 2 issues I'm having trouble with is when I delete the Account Team member off, the field on the Account doesn't delete the user from the field when Account is edited.  My second question is:  Is there a way for this Trigger to execute without someone editing the actual Account?  So when the Account Team member is added it would automatically update the Account field.
  • February 19, 2016
  • Like
  • 0
Hi,
    I'm trying to create a trigger on my Custom Object named Survey that places an Account Team Member of role = CJ Advertiser Account Director into my lookup field Current AD Test.  I am receiving this error for the below:

"Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger AccountDirector caused an unexpected exception, contact your administrator: AccountDirector: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: AccountTeamMember.AccountId: Trigger.AccountDirector: line 18, column 1"
 
trigger AccountDirector on Survey__c (before update, before insert) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Survey__c survey: Trigger.new) {
        accountIds.add(survey.Account__c);
    }
    
    accountIds.remove(null);
    
    Map<Id, Id> accountToTeamMemberMap = new Map<Id, Id>();

    for (AccountTeamMember teamMember: [
        select UserId
        from AccountTeamMember
        where AccountId in :accountIds and
            TeamMemberRole = 'CJ Advertiser Account Director'
    ]) {
        accountToTeamMemberMap.put(teamMember.AccountId, teamMember.UserId);
    }
    
    for (Survey__c survey: trigger.new) {
        if (accountToTeamMemberMap.containsKey(survey.Account__c)) {
            survey.Current_AD_Test__c = accountToTeamMemberMap.get(survey.Account__c);
        }
    }
}

 
  • November 08, 2014
  • Like
  • 0
Hi,

    I'm trying to create a trigger on my Custom Object named Survey that places an Account Team Member of role = CJ Advertiser Account Director into my lookup field Current AD Test.  I am new to coding and am aware my code might be extremely wrong.  Any help appreciated!
trigger AccountDirector on Survey__c (before update, after insert) {
    for (Survey_c SUR : Trigger.net){
        try{
            ID samID = [select UserId from AccountTeamMember where AccountId = : SUR.Account_link_id and TeamMemberRole = 'CJ Advertiser Account Director'].UserId; SUR.Current_AD_Test_c = samID;
            }
      }
}

 
  • November 06, 2014
  • Like
  • 0
trigger ADAccountTeam on Account (before update, before insert) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Account account: Trigger.new) {
        accountIds.add(Account.Id);
    }
    
    accountIds.remove(null);
    
    Map<Id, Id> accountToTeamMemberMap = new Map<Id, Id>();

    for (AccountTeamMember teamMember: [
        select UserId, AccountId
        from AccountTeamMember
        where Account.Id in :accountIds and
            TeamMemberRole = 'CJ Advertiser Account Director'
    ]) {
        accountToTeamMemberMap.put(teamMember.AccountId, teamMember.UserId);
    }
    
    for (Account account: trigger.new) {
        if (accountToTeamMemberMap.containsKey(Account.Id)) {
            Account.CJ_Advertiser_Account_Director__c = accountToTeamMemberMap.get(Account.Id);
        }
    }

}



So this trigger puts the Account Team member into an Account field when the role = CJ Advertiser Account Director.  The 2 issues I'm having trouble with is when I delete the Account Team member off, the field on the Account doesn't delete the user from the field when Account is edited.  My second question is:  Is there a way for this Trigger to execute without someone editing the actual Account?  So when the Account Team member is added it would automatically update the Account field.
  • February 19, 2016
  • Like
  • 0
Hi,

    I'm trying to create a trigger on my Custom Object named Survey that places an Account Team Member of role = CJ Advertiser Account Director into my lookup field Current AD Test.  I am new to coding and am aware my code might be extremely wrong.  Any help appreciated!
trigger AccountDirector on Survey__c (before update, after insert) {
    for (Survey_c SUR : Trigger.net){
        try{
            ID samID = [select UserId from AccountTeamMember where AccountId = : SUR.Account_link_id and TeamMemberRole = 'CJ Advertiser Account Director'].UserId; SUR.Current_AD_Test_c = samID;
            }
      }
}

 
  • November 06, 2014
  • Like
  • 0

Hello - hope someone can help out. I have a custom object, "Services", that tracks customer onboarding post sale. 

So when the Opportunity is marked closed won, a trigger will automatically insert a "Services" record for that account - pulling in information from the related Opportunity and Account (Both account and related opportunity fields are custom lookup fields on the Service object, NOT master detail).

 

What I am trying to do is pull two members from the Account Team of that Account into the Service:

1.) The user marked as the "Integration Manager" on the Account Team will be the Service Owner

2.) The user marked as the "Client Manager" on the Account Team will be pulled into a custom user lookupfield "Client Manager" on the service record

 

Below is my trigger, attempting to pull from AccountTeamMember

         for(AccountTeamMember teamMember:[select id,TeamMemberRole from AccountTeamMember where accountId=:OPP.AccountID]){
               
                if (teamMember.TeamMemberRole=='Integration Manager'){
                    SVC.OwnerId = teammember.id;
                } else if (teamMember.TeamMemberRole=='Client Manager'){
                    SVC.Client_Manager__c = teammember.id;
                }  
                
            }

 

However, I am getting the following error upon save: Error:Apex trigger ServiceCreation caused an unexpected exception, contact your administrator: ServiceCreation: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Client Manager: id value of incorrect type: 01Mn0000000DVyNEAW: [Client_Manager__c]: Trigger.ServiceCreation: line 51, column 1

 

 

I think I am pulling the ID of the teammember role, rather than the user itself. Looking through workbench, I can not find the right value to set these users. Can anybody help?