• Pappu
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 29
    Replies
Hi any one help me to write test class for this code? I tried but not getting enough code coverage.

 List<AccountTeamMember> accountTeamList = [select userId,AccountId from AccountTeamMember where userId IN :userIds];
 Map<Id, user> ObjMap = new Map<Id, user>([select id,unit, function  from user where Id IN :userIds AND IsActive=true]);
List<AccountTeamMember> updatedaccountlist = new List<AccountTeamMember>();
        for (AccountTeamMember am : accountTeamList )
        {
            if(ObjMap.containsKey(am.userId)) //Validate Account userId and Userrecord Userid are equal
            {  
                User obj = ObjMap.get(am.userId);
                AccountTeamMember teamrole =new AccountTeamMember();
                teamrole.userId = obj.User_ID_18__c;
                teamrole.AccountId= am.AccountId;
                if (obj.unit != null && obj.function != null)
                {
                    teamrole.TeamMemberRole = obj.unit +' '+ obj.function;
                }
                else 
                {
                    teamrole.TeamMemberRole = 'Unspecified';
                }
                updatedaccountlist.add(teamrole);
            }
            
        }
        
        insert updatedaccountlist;
        
  • September 12, 2018
  • Like
  • 0
Hi Guys,

Anyone help me with test class for this trigger?


trigger TRG_Opportunity_AddAcctOwner on Opportunity (after insert, after update) {
            List<OpportunityTeamMember> opptyTeam = new  List<OpportunityTeamMember>();
            List<Opportunity> opptyInfo = new List<Opportunity>();
            List<Account> currAcctOwnerID = new List<Account>();
            Integer teamFlag = 0;               
            
            Set<Id> setOpptyID = new Set<Id>();
            Set<Id> setAcctID = new Set<Id>();
            Set<Id> setOwnerUserID = new Set<Id>();    
            for (Opportunity opp: Trigger.new){
                
                setOpptyID.add(opp.Id);
                setAcctID.add(opp.AccountId);
            }
            
            currAcctOwnerID = [Select a.OwnerId From Account a where a.Id in: setAcctID];
            opptyInfo = [Select opp.Id, opp.OwnerId, opp.StageName From Opportunity opp where opp.Id in: setOpptyID];
            opptyTeam = [Select o.UserId, o.OpportunityId From OpportunityTeamMember o where o.OpportunityId in: setOpptyID];
            for (OpportunityTeamMember otm: opptyTeam) {
                Integer index = 0;
                if (currAcctOwnerID[0].OwnerId == opptyTeam[index].UserId){
                    teamFlag += 1;
                }
                index +=1;
            }
            
            if (currAcctOwnerID.size() > 0 && opptyInfo[0].StageName != 'Closed Lost' && currAcctOwnerID[0].OwnerId != 'xxxxxxxxx')
            {
                User acctOwner = new User();
                acctOwner = [Select IsActive From User where Id = :currAcctOwnerID[0].OwnerId];
                if (acctOwner.IsActive == true){                
                OpportunityTeamMember otmAcctOwner = new OpportunityTeamMember();                        
                    
                    if (teamFlag < 1 && opptyTeam.size() > 0 && opptyInfo[0].OwnerId != currAcctOwnerID[0].OwnerId) {
                        // Add the Account Owner to the Sales Team
                        otmAcctOwner.OpportunityId = opptyTeam[0].OpportunityId;
                        otmAcctOwner.UserId = currAcctOwnerID[0].OwnerId;
                        otmAcctOwner.TeamMemberRole = 'Account Owner';
                        insert otmAcctOwner;
                       
                    }
                
                    
                    if (opptyTeam.size() == 0 && opptyInfo[0].OwnerId != currAcctOwnerID[0].OwnerId) {
                        otmAcctOwner.OpportunityId = opptyInfo[0].Id;
                        otmAcctOwner.UserId = currAcctOwnerID[0].OwnerId;
                        otmAcctOwner.TeamMemberRole = 'Account Owner';
                        insert otmAcctOwner;
                        
                    }
                    
                    
                    List<OpportunityShare> oppShares = new List<OpportunityShare>();
                    oppShares = [Select o.UserOrGroupId, o.OpportunityId, o.OpportunityAccessLevel From OpportunityShare o where o.OpportunityId = :otmAcctOwner.OpportunityId and RowCause = 'Team'];
                    for (OpportunityShare share : oppShares)
                        if (share.UserOrGroupID == otmAcctOwner.UserId) {
                        share.OpportunityAccessLevel = 'Edit';
                        }
                    update oppShares;
                }
            }
    }

 
  • August 27, 2018
  • Like
  • 0
Hi guys,


I'm getting "Dependent class in invalid and needs recompilation" error on my test class. Can you please tell me why I'm receving this error?
  • August 07, 2018
  • Like
  • 0
Hi Guys,

I'm trying to embed an external website in Salesforce via visualforce page.

Problem is the external site sets X-Frame-Options header to explicitly stop embedding the site in iframe. Also, I cant disable the clickjack property in org.

Any alternative way I can get the external site to Salesforce?

 
  • August 01, 2018
  • Like
  • 0
Hi All,

Any help in writting test class for the below trigger is appreciated.

trigger test on Mail__c (after update) {
            list<Duration__c> durations = new list<Duration__c>();
            set<string> trackedFields = new set<string> {'OwnerId', 'Status__c', 'Sub_Status__c'}; 
            STOWD.API.CalculateDurations(durations, trackedFields, 'Request__History', 'ParentId'); 
            database.insert(durations, false);
    }
  • July 26, 2018
  • Like
  • 0
Hi Guys,

I've written and executing the test class for below code and not getting a enough code coverage. Any idea what I am miising in the code?

I could see, the log is returning null values to the line (List<AccountTeamMember> accountTeamList = [select userId,AccountId from AccountTeamMember where userId IN :userIds ];) though I've enough records to satisfy the select querry.
Class

global class Accountteamroleupdate {
    @future
    public static void role(Set<Id> userIds) {
        system.debug('User Id is ' + userIds);
        List<AccountTeamMember> accountTeamList = [select userId,AccountId from AccountTeamMember where userId IN :userIds ];
        map<Id, user> ObjMap = new map<Id, user>([select User_ID_18__c,Taylor_Business_Unit__c, Function__c  from user where Id IN :userIds]);
        System.debug('AccountTeamList is ' + accountTeamList);
        List<AccountTeamMember> updatedaccountlist = new List<AccountTeamMember>();
        for (AccountTeamMember am : accountTeamList )
        {
            if(ObjMap.containsKey(am.userId))
            {  
                User obj = ObjMap.get(am.userId);
                AccountTeamMember teamrole =new AccountTeamMember();
                teamrole.userId = obj.User_ID_18__c;
                teamrole.AccountId= am.AccountId;
                if (obj.Taylor_Business_Unit__c != null && obj.Function__c != null)
                {
                    teamrole.TeamMemberRole = obj.Taylor_Business_Unit__c +' '+ obj.Function__c;
                }
                else 
                {
                    teamrole.TeamMemberRole = 'Unspecified';
                }
                updatedaccountlist.add(teamrole);
            }
            
        }
        insert updatedaccountlist;
    }
}

Test Class:

@isTest
public class Teamroleupdatetestcls {
    static testMethod void testAccountTrigger(){
        user ul = [select Id from user where User_ID_18__c='005Z0000003r5wMIAQ'];
        system.debug('UserId is ' + ul.Id);
        set<Id> setAccId = new Set<ID>();
        setAccId.add(ul.Id);
        
        Accountteamroleupdate.role(setAccId);
          
    }
}
  • July 24, 2018
  • Like
  • 0
Hi All,

I've written & executing the test class for below code and receiving " FATAL_ERROR System.LimitException: Apex CPU time limit exceeded" 
Any idea what I'm missing out in code?

Trigger code:

trigger Accountteamupdate on Account_Relationship__c (before insert) {
    List<AccountTeamMember> accountTeamList = new List<AccountTeamMember>();
    List<AccountTeamMember> finalaccountTeamList = new List<AccountTeamMember>();
    List<user> UserList = [select User_ID_18__c,Taylor_Business_Unit__c, Function__c  from user];
    
    if(Trigger.isInsert)
        
    {
        for(Account_Relationship__c ar:trigger.new) {
            ar.OwnerId=ar.Assigned_Sales_Rep__c;
            AccountTeamMember Teammemberadd=new AccountTeamMember();
            Teammemberadd.AccountId=ar.Account__c;
            Teammemberadd.UserId=ar.Assigned_Sales_Rep__c;
            accountTeamList.add(Teammemberadd);
        } 
        
        for (AccountTeamMember am : accountTeamList )
        {
            
            for (user ul : UserList)
            {
                
                if  (am.UserId == ul.User_ID_18__c)
                {
                    AccountTeamMember Teammember=new AccountTeamMember();
                    Teammember.AccountId=am.AccountId;
                    Teammember.UserId=am.UserId;
                    if (ul.Taylor_Business_Unit__c != null && ul.Function__c != null )
                    {
                    Teammember.TeamMemberRole=ul.Taylor_Business_Unit__c +' '+ ul.Function__c;
                    }
                    else 
                    {
                    Teammember.TeamMemberRole = 'Unspecified';
                    }
                    
                    finalaccountTeamList.add(Teammember);
                }
            }
        }
        
        insert finalaccountTeamList; 
    }
    
    }

Test Class code:

@isTest
public class sampleTestMethodCls {
    static testMethod void testAccountTrigger(){
        List<Account_Relationship__c> AR = new List<Account_Relationship__c>();
        for (integer i = 0 ; i<=200 ; i++)
        {
        Account_Relationship__c  ct = new Account_Relationship__c (Account__c='xxxxxxxx',Assigned_Sales_Rep__c='xxxxxxxx');
         AR.add(ct);   
        }
        Test.startTest();
        insert AR;
        Test.stopTest();
        
    }    
}
 
  • July 23, 2018
  • Like
  • 0
Hi Guys,

Has anyone got an idea to delete Account team member record?

I was asked to do to delete account team member when all related record to the member gets deleted.

Pls help me to sort this out.

Regards,
Pappu
  • July 04, 2018
  • Like
  • 0
Greeting,

I am looking for a flow which can auto delete Account team member record. When the member is no longer present in any of the account records.

Appreciate your help.
  • July 03, 2018
  • Like
  • 0
Hi guys,

I am trying to auto create the Account team based on user created the custom object record.

I am using flows and process builder to do the same. Below is the flow and PB I have written.

But it throwing me an error as "Error element myRule_1_A1 (FlowActionCall). An error occurred when executing a flow interview. "

Please help me out with this error.

User-added imageUser-added imageUser-added imageUser-added image
  • July 02, 2018
  • Like
  • 0
Hi Friends,

Is it possible to create Account team record automatically by using Flows and Process builder?
I have a requirement, when the user creates a custom object record with sales repname. Thesales rep name should be added to Account team automatically.
How it can be done?

Kindly help me out with this.
  • July 02, 2018
  • Like
  • 0
Hi Guys,

I have a custom object "Account_Team_Relationship__c" which is related to standard object Account.

Wheneever user is creating new Account_Team_Relationship__c object record, User details (Name, Account Access, Contact Access, Opportunity Access, Case Access and role) should be automaticaly saved to Account Team members, if the user details are not available in Account team members.

As of now Team role can be hardcoded.

Is it possible to do this with trigger?

Your thoughts are highly appreciated.
  • June 28, 2018
  • Like
  • 0
Hi Guys,

Is it possible to display multiple VF pages in one VF page by using dropdown list?

I have 10 seperate VF pages (all relate to same Sobject) and displaying them as dropdown in console app.
It is really difficult for user to go back and forth.

So I need to display a single field in console app dropdown list. When the user enters to it, they should have another dropdown in the page which holding the 10 visualforce page and any one of these VF must shown as default.
  • May 03, 2018
  • Like
  • 0
Hi Guys,

I am trying to update the owner name of multiple records using a button in custom VF page.

For this, my org is using the below code, which will take the user to another VF page for updating the owner name.But, it is written inside the button javascript.

srcUp('/apex/multiChangeOwner?ids={!Request__c.Id}' + selectedReqIDs.join(";") + '&isdtp=vw');

Now, I want to use the same functionality with javascript in my custom visual force page.

My bad luck I am not able to acces the "Request__c.Id" field inside the VF page javascript.

Is showing an error "Unknown property"

Please provide me any alternative/suggestions.
Also, kidnly let me know what join method will do in the URL.
Thanks!!
  • April 27, 2018
  • Like
  • 0
Hi Guys,

I am trying to update the owner name of multiple records using a button in custom VF page.

For this, my org is using the below code, which will take the user to another VF page for updating the owner name.But, it is written inside the button javascript.

srcUp('/apex/multiChangeOwner?ids={!Request__c.Id}' + selectedReqIDs.join(";") + '&isdtp=vw');

Now, I want to use the same functionality with javascript in my custom visual force page.

My bad luck I am not able to acces the "Request__c.Id" field inside the VF page javascript.

Is showing an error "Unknown property"

Please provide me any alternative/suggestions.

Thanks!!
  • April 26, 2018
  • Like
  • 0
Hi All,
Below is the javascript function in my Visualforce page. 

function ownerchange(){ 
var leadrec = sforce.connection.query('select Id fom Account');
                                alert(leadrec);
}
My goal is to retreive the Sobject Id during runtime in javascript using visualforce page.

I tried sforce.connection query, but there is no luck with that. If there is any alternatice, please let me know.

Thanks!!


 
  • April 26, 2018
  • Like
  • 0
Hi Guys,

I have created a VF page for a custom sobject list view.

A checkbox field is placed at every row and button (Change Owner) is kept at top of the VFpage (refere the attached)

Now, the user should able to select the record(s) using checkbox field and also change the owner name for selected records by clicking the change owner button.

If a user selects directly the button without select any check box field, a pop up should appear stating "Please select atleast one record".

Kindly suggest me  a code or any reference for this requirement.

Thanks!!!

User-added image
  • April 25, 2018
  • Like
  • 0
Hi All,

I have created a VF page for a custom sobject records with checkbox field.

Also, I do have a button (Change Owner) at top of the page, where user clicks the button, they should able to change the owner name for selected record(s).

If a user selects directly the button without select any check box field, a pop up should appear stating "Please select atleast one record".

Kindly suggest me  a code or where I can get the reference for this requirement.

Thanks!!!
  • April 25, 2018
  • Like
  • 0
Hi Guys,

How to display all the action on a data table in single line.
Currently, Follow button is appearing as new line (Please refer the attached), which needs to be displayed next to delete link.
Also, please let me know how I can remove the "Follow" text present next to the chatter feed (plus) icon.
I have posted my current code below.


<apex:outputLink title="" value="/{!contact.id}/e?retURL=/apex/{!$CurrentPage.Name}">Edit</apex:outputLink>&nbsp;|&nbsp;
<apex:commandLink value="Delete" action="{!deleteProduct}" reRender="form"> 
          <apex:param value="{!contact.id}" name="IDfordeletion" assignTo="{!contactId}"/>
</apex:commandLink>&nbsp;|&nbsp; <apex:commandLink><chatter:follow entityId="{!contact.id}"></chatter:follow></apex:commandLink>
User-added image
  • April 25, 2018
  • Like
  • 0
Hi Guys,

I have created a data table for custom sobject(test__c) list view.
I used SOQL query to get all the required fields (some are standard fields - Account and contact name) related to test__C.

But the issue here is, when the user clicks the standard fields, they should be able to navigate the Account and contact name pages respectively. For that, I need to make these as hyperlink fileds.

I am not sure how to proceed for this. Any help is appreciated.

Thanks!!
 
  • April 25, 2018
  • Like
  • 0
Hi All,

I need to get the account Id and return the same to Visualforce page. Below is the method I am using.

I am getting an empty array list instead of parrticular Account ID. Have provided the output below for reference.

Any help is appreciated.

Code:

 public List<Account> getaccount() {
        account = [SELECT id FROM Account where Name = :contactName Limit 1];
        return account;
                                    }

Output:

https://XXXXXX.my.salesforce.com/[]?IDforaccountname=ZZZZ
  • April 24, 2018
  • Like
  • 1
Hi All,

Any help in writting test class for the below trigger is appreciated.

trigger test on Mail__c (after update) {
            list<Duration__c> durations = new list<Duration__c>();
            set<string> trackedFields = new set<string> {'OwnerId', 'Status__c', 'Sub_Status__c'}; 
            STOWD.API.CalculateDurations(durations, trackedFields, 'Request__History', 'ParentId'); 
            database.insert(durations, false);
    }
  • July 26, 2018
  • Like
  • 0
Hi Guys,

I've written and executing the test class for below code and not getting a enough code coverage. Any idea what I am miising in the code?

I could see, the log is returning null values to the line (List<AccountTeamMember> accountTeamList = [select userId,AccountId from AccountTeamMember where userId IN :userIds ];) though I've enough records to satisfy the select querry.
Class

global class Accountteamroleupdate {
    @future
    public static void role(Set<Id> userIds) {
        system.debug('User Id is ' + userIds);
        List<AccountTeamMember> accountTeamList = [select userId,AccountId from AccountTeamMember where userId IN :userIds ];
        map<Id, user> ObjMap = new map<Id, user>([select User_ID_18__c,Taylor_Business_Unit__c, Function__c  from user where Id IN :userIds]);
        System.debug('AccountTeamList is ' + accountTeamList);
        List<AccountTeamMember> updatedaccountlist = new List<AccountTeamMember>();
        for (AccountTeamMember am : accountTeamList )
        {
            if(ObjMap.containsKey(am.userId))
            {  
                User obj = ObjMap.get(am.userId);
                AccountTeamMember teamrole =new AccountTeamMember();
                teamrole.userId = obj.User_ID_18__c;
                teamrole.AccountId= am.AccountId;
                if (obj.Taylor_Business_Unit__c != null && obj.Function__c != null)
                {
                    teamrole.TeamMemberRole = obj.Taylor_Business_Unit__c +' '+ obj.Function__c;
                }
                else 
                {
                    teamrole.TeamMemberRole = 'Unspecified';
                }
                updatedaccountlist.add(teamrole);
            }
            
        }
        insert updatedaccountlist;
    }
}

Test Class:

@isTest
public class Teamroleupdatetestcls {
    static testMethod void testAccountTrigger(){
        user ul = [select Id from user where User_ID_18__c='005Z0000003r5wMIAQ'];
        system.debug('UserId is ' + ul.Id);
        set<Id> setAccId = new Set<ID>();
        setAccId.add(ul.Id);
        
        Accountteamroleupdate.role(setAccId);
          
    }
}
  • July 24, 2018
  • Like
  • 0
Hi All,

I've written & executing the test class for below code and receiving " FATAL_ERROR System.LimitException: Apex CPU time limit exceeded" 
Any idea what I'm missing out in code?

Trigger code:

trigger Accountteamupdate on Account_Relationship__c (before insert) {
    List<AccountTeamMember> accountTeamList = new List<AccountTeamMember>();
    List<AccountTeamMember> finalaccountTeamList = new List<AccountTeamMember>();
    List<user> UserList = [select User_ID_18__c,Taylor_Business_Unit__c, Function__c  from user];
    
    if(Trigger.isInsert)
        
    {
        for(Account_Relationship__c ar:trigger.new) {
            ar.OwnerId=ar.Assigned_Sales_Rep__c;
            AccountTeamMember Teammemberadd=new AccountTeamMember();
            Teammemberadd.AccountId=ar.Account__c;
            Teammemberadd.UserId=ar.Assigned_Sales_Rep__c;
            accountTeamList.add(Teammemberadd);
        } 
        
        for (AccountTeamMember am : accountTeamList )
        {
            
            for (user ul : UserList)
            {
                
                if  (am.UserId == ul.User_ID_18__c)
                {
                    AccountTeamMember Teammember=new AccountTeamMember();
                    Teammember.AccountId=am.AccountId;
                    Teammember.UserId=am.UserId;
                    if (ul.Taylor_Business_Unit__c != null && ul.Function__c != null )
                    {
                    Teammember.TeamMemberRole=ul.Taylor_Business_Unit__c +' '+ ul.Function__c;
                    }
                    else 
                    {
                    Teammember.TeamMemberRole = 'Unspecified';
                    }
                    
                    finalaccountTeamList.add(Teammember);
                }
            }
        }
        
        insert finalaccountTeamList; 
    }
    
    }

Test Class code:

@isTest
public class sampleTestMethodCls {
    static testMethod void testAccountTrigger(){
        List<Account_Relationship__c> AR = new List<Account_Relationship__c>();
        for (integer i = 0 ; i<=200 ; i++)
        {
        Account_Relationship__c  ct = new Account_Relationship__c (Account__c='xxxxxxxx',Assigned_Sales_Rep__c='xxxxxxxx');
         AR.add(ct);   
        }
        Test.startTest();
        insert AR;
        Test.stopTest();
        
    }    
}
 
  • July 23, 2018
  • Like
  • 0
Greeting,

I am looking for a flow which can auto delete Account team member record. When the member is no longer present in any of the account records.

Appreciate your help.
  • July 03, 2018
  • Like
  • 0
Hi Guys,

I have a custom object "Account_Team_Relationship__c" which is related to standard object Account.

Wheneever user is creating new Account_Team_Relationship__c object record, User details (Name, Account Access, Contact Access, Opportunity Access, Case Access and role) should be automaticaly saved to Account Team members, if the user details are not available in Account team members.

As of now Team role can be hardcoded.

Is it possible to do this with trigger?

Your thoughts are highly appreciated.
  • June 28, 2018
  • Like
  • 0
Hi Guys,

Is it possible to display multiple VF pages in one VF page by using dropdown list?

I have 10 seperate VF pages (all relate to same Sobject) and displaying them as dropdown in console app.
It is really difficult for user to go back and forth.

So I need to display a single field in console app dropdown list. When the user enters to it, they should have another dropdown in the page which holding the 10 visualforce page and any one of these VF must shown as default.
  • May 03, 2018
  • Like
  • 0
Hi Guys,

I have created a data table for custom sobject(test__c) list view.
I used SOQL query to get all the required fields (some are standard fields - Account and contact name) related to test__C.

But the issue here is, when the user clicks the standard fields, they should be able to navigate the Account and contact name pages respectively. For that, I need to make these as hyperlink fileds.

I am not sure how to proceed for this. Any help is appreciated.

Thanks!!
 
  • April 25, 2018
  • Like
  • 0
Hi Guys,
 
I have added the Chatter follow button on a custom object Standard controller page with extension in a customer page block, but I was wondering how to get just the button, not the word Follow after the plus button?
 
Does any one has a Idea?

Thanks.
  • April 23, 2018
  • Like
  • 0
Hi, 
I am trying to view the listview in lightning component. 
I have created a lightning app & lightning componet and added the component to lightning app builder.
There is no error in developer console. But, when i am viewing the component in salesforce app, it throwing "You don't have access to this record. Ask your administrator for help or to request access." My profile is set to System administrator.
It only happens when i use LDS.
Please suggest me some workaround for this. Below is my code.

Lightning App:

<aura:application implements="force:appHostable">
    <ltng:require styles="/resource/SLDS100/styles/salesforce-lightning-design-system.min.css"/>
    <c:Listview_Newmethod1_1 />
</aura:application>

Lightning Component:

<aura:component controller="LGTN_AccountController" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
   <ltng:require styles="/resource/SLDS100/styles/salesforce-lightning-design-system.min.css"/>
   <aura:dependency resource="markup://force:navigateToList" type="EVENT"/>
   <aura:dependency resource="markup://force:navigateToSObject" type="EVENT"/>
     <ui:button label="List View" press="{!c.gotoList}"/>
</aura:component>

Controller:

({
gotoList : function (component, event, helper) {
    var action = component.get("c.getListViews");
    action.setCallback(this, function(response){
        var state = response.getState();
        console.log('clicked');
        if (state === "SUCCESS") {
            var listviews = response.getReturnValue();
            var navEvent = $A.get("e.force:navigateToList");
            navEvent.setParams({
                "listViewId": listviews.Id,
                "listViewName": null,
                "scope": "Request__C"
            });
            navEvent.fire();
        }
    });
    $A.enqueueAction(action);
},
})

Class:

public with sharing class LGTN_AccountController {

   @AuraEnabled 
   public static ListView getListViews(){
       return [SELECT Id, Name FROM ListView WHERE SobjectType = 'Request__C' LIMIT 1].get(0);
    }
}
  • March 29, 2018
  • Like
  • 0
Flow newbie here, need some guidance. I figure I've got the basics working, now I need to design it for various situations.

Goal: When opportunity ownership is transfered and the "Keep Opportuntiy Teams" box is selected, then I want the flow to automatically delete the opportunity team member for the previous owner. Because we have Splits enabled, the owner is always added as an opporutnity team member. And as soon as the owner becomes the previous owner, I want the corresponding team member to be automatically deleted. For example, Joe owns the opp, Joe and Mary are team members. The opp is transfered to Bob, and the desired result should be that Bob and Mary are the only team members.

So far, I've got a single step in my flow that deletes the team member nicely. But it only works when "Keep Opportunity Teams" is selected. If I don't select "Keep Opportunity Teams", then the flow throws an error. Presumably because the team member has already been deleted and the flow doesn't know what to do? I'm not sure how to modify my flow to deal with this.

After I get that sorted out, then I need to make sure it can delete any splits it needs to. 

User-added image
I have custom object named 'Top Account' that is related to the standard Account object.

When creating new 'Top Accounts', it requires a user to be specified and a role. When saved, I want that user to be added to the Account Team, and give specific Access Levels (i.e. edit access to contacts, and read access to opportunities).

Adding the user to the Account Team is straightforward, but setting the Access Levels has proven to be pretty complex.

Below is the AccountShare attempt. Again the first part works in that it correctly creates the AccountTeamMember, but all the access levels are set to private.

Thanks!

public static void updateAccountTeamFromTopAcct(List<Target_Account__c> ttAcctList) {

List<Target_Account__c> ttUpdateList = new List<Target_Account__c>(); // trigger list

List<String> assignedUserIdsList = new List<String>(); // Ids from Assigned Top Account users

List<String> accountList = new List<String>(); // accounts IDs affected by Top Account

Map<String,String> roleMap = new Map<String,String>();

for(Target_Account__c ttAcc : ttAcctList){

    assignedUserIdsList.add(ttAcc.Assigned_User__c);
    accountList.add(ttAcc.Account__c);
    roleMap.put(ttAcc.Assigned_User__c, ttAcc.User_Role__c);
    }

    List<Account> affectedAccounts = [select Id from Account where Id in : accountList]; // list of all accounts affected by top account
    List<AccountTeamMember> accountTeamList = new List<AccountTeamMember>(); // list of AccountTeamMembers to insert    

    for(Account acct : affectedAccounts){
        AccountTeamMember acctTM = new AccountTeamMember();
        acctTM.AccountId = acct.Id;

        for(String usrId: assignedUserIdsList){
            acctTM.userId = usrId;
            if(roleMap.get(usrId).equals('SpecialRole')){
                acctTM.TeamMemberRole = 'Sales Rep';
                accountTeamList.add(acctTM);
            }
        }
    }

    insert accountTeamList;

    List<AccountShare> affectedAcctShare = [select Id from AccountShare where AccountId in :affectedAccounts and UserOrGroupId in :assignedUserIdsList];

    for (AccountShare share : affectedAcctShare ) {

        // Give view access to opportunities and edit access to contacts
        share.ContactAccessLevel = 'Edit';
        share.OpportunityAccessLevel = 'Read';
    }

    update affectedAcctShare;