-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
9Questions
-
11Replies
My Biggest Challenge as a Beginning (and Self-Taught) Force.com Developer
I know this looks like a massive wall of text (mostly because it is), but there really is a point and an idea down there somewhere, I promise. I just wanted to takl about the single biggest factor that is inhibiting me from becoming a true Force.com programmer. (Note, my educational background is completely unrelated to programming, so I am self-taught and very limited in funds I can put towards this self-teaching).
I know this is somewhat random, but there has not been a topic in Force.com that I have not been able to teach myself once I got down to it, but wrapping my head around the meta-teaching, or the organization of the topics I need to know to accomplish a goal, has been the single biggest inhibitor for me.
My idea, or what I am looking for, is a sort of “prerequisite tree” for Force.com features. I am a self-taught developer, and in this capacity, I have learned things very much out of order from what I probably should have. However, I was often given tasks that needed to be accomplished, so I would set off on the task, figuring out along the way what I did not know, then backtrack and teach myself the missing topics. While backtracking, I would often find additional topics that I didn’t know well enough and would have to backtrack even further. With some of the advanced functionality that Force.com offers, this process can go on for a while. I am at a point where I am tired of learning based on tasks, and I would like to take a more pragmatic approach to my learning with respect to Force.com, however, starting from scratch would be a waste of time (because I am familiar with many, albeit randomly distributed, topics) and money.
I faced a similar challenge in another endeavor: learning Spanish. However, I came across a great (and free) tool that accomplished what I describe above. This tool is called DuoLingo.com, and it looks (basically) like this:
While I am not looking for the game-like or social aspect that DuoLingo provides (although this might appeal to Salesforce), I have benefitted greatly from its teaching style. As you can see, DuoLingo provides a ‘tree’ style approach to learning, showing that if you want to learn X, you should learn A, B and C first. It even goes as far as to lock certain topics from being started until you have completed its prerequisites (however it does allow you to instantly complete a topic by passing a topic-specific quiz).
Learning in this style would fit Force.com perfectly. Imagine that instead of learning numbers in Spanish, I could find “Creating a Visual Force Page with a Custom Controller,” then work backwards to make sure I understand all of the concepts that I would need to know leading up to this point. Or maybe I can search for a feature described in plain English, eg. “Update a Field in a Many-to-Many Relationship”, the tree can guide me to the right path that I would need to eventually be able to write the triggers necessary to do this.
Based on log-in information, you can track what you know so far, only having to unlock each topic once (because no one wants to take the ‘Creating Your First Field in Force.com’ quiz every time you start a new advanced topic), and this can even lead to the discovery of features that you may not have been aware of by unlocking them upon completing what had been a seemingly unrelated exercise.
As I mentioned above, there has not been a topic in Force.com that I have not been able to teach myself, but wrapping my head around the meta-teaching, or the organization of the topics I need to know, has been the single biggest inhibitor for me. I want to learn about REST API, but I have no idea where to start (I’m not sure I even really know what it does). I know that there is a workbook for REST API, but there are too many concepts in the workbook that are unfamiliar to me, and I eventually gave up in trying to work backwards to learn the necessary concepts to even approach the REST workbook. Sometimes I’ll even find myself with a slow day at the office thinking, “what can I learn next?” but not knowing where to turn. A ‘skill tree’ would help with this as well.
I know that the Dev Evangelist team is interested in helping new Devs get off the ground, and I truly believe that this would be the single most helpful way of doing this outside of the initial creation of the dev workbooks. Whether it is interactive (ie. Click on the VisualForce topic and get taken to an online/interactive HTML lesson and quiz b/c you have not passed this prerequisite yet), or whether it is static and simply points you to a paper/lecture/workbook on the prerequisite topic is not important (although the first option would be way cooler), simply helping beginners to wrap their heads around everything that is out there and approach it in an ordered fashion would be a massive step towards building an even bigger army of independent developers that really understand and love Force.com.
Thanks for hearing me out, and feel free to contact me with any questions or thoughts that this may have stirred up.
- JAckerman09
- September 12, 2012
- Like
- 0
Having case team members automatically follow the case on chatter...
Any thoughts or ideas on this one? I set up a workflow rule so that case comments are posted to the case's chatter feed, but that doesn't help too much if the case team members aren't following the case. Any thoughts on ways to have this done automatically?
My first thought was a trigger that, on insert/update:
- Queried the case team members
- Created an EntitySubscription for parentid=case.id and subscriberid=caseTeamMember.id
- Tests for existing EntitySubscription to prevent 'DUPLICATE_VALUE' error
- Tests to make sure it does not put the user over the 500 following limit
I have a trigger that I have not rolled out to production yet that has users automatically follow accounts if they are in any of 5 'account team member' fields (not a related list, just lookup fields), and I figure this would be similar, but I'd love to hear any ideas on a better/simpler way to accomplish this goal.
Thanks!
- JAckerman09
- July 20, 2012
- Like
- 0
Any way to accomplish this goal with less SOQL queries? Will hit limits during mass updates.
I am running this trigger that automatically adds users as followers anytime they are in the lookup fields Portfolio Manager, Trust Oficer, Wealth Advisor, Other Team Member 1 or Other Team Member 2 on an Account record.
I am using SOQL queries to:
- Check the records current followers to ensure that the user is not already following the record (which would cause a duplicate value error)
- To make sure that the user is not following more than 495 records/users to ensure that the trigger does not put the user too close to the 500 followed-records maximum
The first step uses one SOQL query and the second uses 5, one for each potential follower (5 team member fields).
I often update these accounts in batches of over 2,000 at a time (updating account values from an external system using the APEX Data Loader), and I want to be able to do this without hitting governor limits. Any suggestions?
What would happen right now if I ran a mass update and it exceeded the 100 SOQL limit? Would it stop the batch update, or just stop running the trigger?
Thanks!
Here's the trigger:
trigger teamMembersFollowRels on Account (after insert, after update) { for(Account acc: Trigger.new){ ////Find all of the records followers//// List <EntitySubscription> CurrentSubs = [ SELECT Id, subscriberid, subscriber.name FROM EntitySubscription Where parentid =: acc.id ]; ////Put the records followers in a map so that they can be checked vs. the potential followers later//// Map<Id,EntitySubscription> CurrentFollowersMap = new Map<Id,EntitySubscription>(); for(EntitySubscription Ent: CurrentSubs){ CurrentFollowersMap.put(Ent.subscriberid, Ent); } Integer FollowMax = 495; ////Check each potential followers # of records followed for comparison vs. the max later//// Integer PMFollowNum = [SELECT COUNT() FROM EntitySubscription WHERE subscriberid = :acc.Portfolio_Manager_Lookup__c]; Integer TOFollowNum = [SELECT COUNT() FROM EntitySubscription WHERE subscriberid = :acc.Trust_Officer__c]; Integer WAFollowNum = [SELECT COUNT() FROM EntitySubscription WHERE subscriberid = :acc.Wealth_Advisor__c]; Integer OTFollowNum = [SELECT COUNT() FROM EntitySubscription WHERE subscriberid = :acc.Other_Team_Member_1__c]; Integer OTTFollowNum = [SELECT COUNT() FROM EntitySubscription WHERE subscriberid = :acc.Other_Team_Member_2__c]; system.debug('PM ID: ' + acc.Portfolio_Manager_Lookup__c); system.debug('PMFollowNum: ' + PMFollowNum); //**** INSERT SECTION ****// if(Trigger.isInsert){ ////Create EntitySubscription for user in the PM field//// if(acc.Portfolio_Manager_Lookup__c != Null){ EntitySubscription followPM = new EntitySubscription( parentId = acc.id, subscriberid = acc.Portfolio_Manager_Lookup__c ); ////Make sure the user is not already a follower of the record AND is not following more than the max number of records allowed//// if(!CurrentFollowersMap.containsKey(acc.Portfolio_Manager_Lookup__c) && PMFollowNum<FollowMax){ insert followPM; } } if(acc.Trust_Officer__c != Null){ EntitySubscription followTO = new EntitySubscription( parentId = acc.id, subscriberid = acc.Trust_Officer__c ); if(!CurrentFollowersMap.containsKey(acc.Trust_Officer__c) && TOFollowNum<FollowMax){ insert followTO; } } if(acc.Wealth_Advisor__c != Null){ EntitySubscription followWA = new EntitySubscription( parentId = acc.id, subscriberid = acc.Wealth_Advisor__c ); if(!CurrentFollowersMap.containsKey(acc.Wealth_Advisor__c) && WAFollowNum<FollowMax){ insert followWA; } } if(acc.Other_Team_Member_1__c != Null){ EntitySubscription followOT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_1__c ); if(!CurrentFollowersMap.containsKey(acc.Other_Team_Member_1__c) && OTFollowNum<FollowMax){ insert followOT; } } if(acc.Other_Team_Member_2__c != Null){ EntitySubscription followOTT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_2__c ); if(!CurrentFollowersMap.containsKey(acc.Other_Team_Member_2__c) && OTTFollowNum<FollowMax){ insert followOTT; } } //**** UPDATE SECTION ****// } if (Trigger.isUpdate){ if(acc.Portfolio_Manager_Lookup__c != Null){ if(acc.Portfolio_Manager_Lookup__c != Trigger.oldMap.get(acc.ID).Portfolio_Manager_Lookup__c){ EntitySubscription followPM = new EntitySubscription( parentId = acc.id, subscriberid = acc.Portfolio_Manager_Lookup__c ); if(!CurrentFollowersMap.containsKey(acc.Portfolio_Manager_Lookup__c) && PMFollowNum<FollowMax){ insert followPM; } } } if(acc.Trust_Officer__c != Null){ if(acc.Trust_Officer__c != Trigger.oldMap.get(acc.ID).Trust_Officer__c){ EntitySubscription followTO = new EntitySubscription( parentId = acc.id, subscriberid = acc.Trust_Officer__c ); if(!CurrentFollowersMap.containsKey(acc.Trust_Officer__c) && TOFollowNum<FollowMax){ insert followTO; } } } if(acc.Wealth_Advisor__c != Null){ if(acc.Wealth_Advisor__c != Trigger.oldMap.get(acc.ID).Wealth_Advisor__c){ EntitySubscription followWA = new EntitySubscription( parentId = acc.id, subscriberid = acc.Wealth_Advisor__c ); if(!CurrentFollowersMap.containsKey(acc.Wealth_Advisor__c) && WAFollowNum<FollowMax){ insert followWA; } } } if(acc.Other_Team_Member_1__c != Null){ if(acc.Other_Team_Member_1__c != Trigger.oldMap.get(acc.ID).Other_Team_Member_1__c){ EntitySubscription followOT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_1__c ); if(!CurrentFollowersMap.containsKey(acc.Other_Team_Member_1__c) && OTFollowNum<FollowMax){ insert followOT; } } } if(acc.Other_Team_Member_2__c != Null){ if(acc.Other_Team_Member_2__c != Trigger.oldMap.get(acc.ID).Other_Team_Member_2__c){ EntitySubscription followOTT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_2__c ); if(!CurrentFollowersMap.containsKey(acc.Other_Team_Member_2__c) && OTTFollowNum<FollowMax){ insert followOTT; } } } } } }
Thanks again!
- JAckerman09
- July 19, 2012
- Like
- 0
Trigger is Failing Validation Rule, Can't Figure Out Why
My test class runs this code:
test.starttest(); insert Css; Css[1].Disbursement_Destination__c = Null; Css[3].Disbursement_Destination__c = Null; Css[5].Disbursement_Destination__c = Null; Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest();
which is causing this validation rule to fail:
AND( OR( ISPICKVAL( Existing_or_New_Disbursement_Destination__c , 'Leave Disbursement Destination Blank'), ISPICKVAL( Existing_or_New_Disbursement_Destination__c , 'Use/Create a New Disbursement Destination') ), Disbursement_Destination__c <> Null)
despite the fact that the code (attempts to) set the value of Disbursement_Desintation__c to Null.
Any insight as to why this validation rule is failing?
Thanks!
- JAckerman09
- July 19, 2012
- Like
- 0
Question About Chatter Within Apex (no code, just question)
I set up a trigger that has a user automatically follow the record based on a user-lookup-field on the record.
I often do batch updates of all of my accounts.
What happens if a user is already following 500 records? Will the record still update, but not add the follower? Will the record refuse to update? Will it stop the batch update (using APEX Data Loader)?
Can I use APEX to test the number of records that a user is following, and then wrap my code in an if-statement that tests that the number is less than 500?
Thanks!
- JAckerman09
- July 18, 2012
- Like
- 0
Required Field Missing, (Only When Running Test) But I Can't Figure Out Why...
I am running a test on a trigger that creates a new 'Distribution Destination' record whenever a Case is saved with a picklist set to 'Create New Distribution Destination'.
Here's the trigger, which works when I manually test it by saving a case with the picklist set to 'Create New Distribution Destination':
I also put a note in the middle starting with DEBUG LOGS SHOW, which points out another confusing point.
Here's the error I'm getting when I run the test:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateNewDistributionDestination: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Relationship__c]: [Relationship__c] Trigger.CreateNewDistributionDestination: line 126, column 1: []
Stack Trace:
Class.TestCreateNewDistributionDestination.testUpdateCaseToCreateNew: line 209, column 1
The line that is referenced is when the new Distribution Lists are inserted in the trigger. Again, this seems to work when I run it manually, so I am assuming that the error is in the test class' handling of the account id.
The test code is below the trigger, thanks for any assistance that could be offered!!
trigger CreateNewDistributionDestination on Case (after insert, after update) { List<Disbursement_Destination__c> DDList = new List<Disbursement_Destination__c> (); Id DDRT; List<Case> CasesToActOn = [ SELECT c.Receiving_Account_s_Number_Case__c, c.Receiving_Account_s_Name_Case__c, c.Payee_s_Name_Case__c, c.Payee_s_Street_Case__c, c.Payee_s_City_Case__c, c.Payee_s_State_Case__c, c.Payee_s_Zip_Code_Case__c, c.Payee_s_Country_Case__c, c.Receiving_Bank_s_Name_Case__c, c.Receiving_Bank_s_ABA_ACH_Case__c, c.Receiving_Bank_s_ABA_Wire_Case__c, c.Receiving_Bank_s_Street_Case__c, c.Receiving_Bank_s_City_Case__c, c.Receiving_Bank_s_State_Case__c, c.Receiving_Bank_s_Zip_Code_Case__c, c.Receiving_Bank_s_Country_Case__c, c.Account.Id, c.RecordType.name, c.RecordType.developername, c.Existing_or_New_Disbursement_Destination__c FROM Case c WHERE Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination' AND c.id IN :Trigger.new FOR UPDATE ];
///// DEBUG LOGS SHOW CasesToActOn.size()=1, YET IT DOES NOT RUN THE SYSTEM.DEBUG CODE WITHIN THE IF STATEMENT, ANY IDEA WHY??? When I ran it without the If statement, I got an error that the reference was out of range. Very confused on this point. /////
system.debug('Account ID: ' + CasesToActOn.size()); if(CasesToActOn.size()>0){ system.debug('Account ID: ' + CasesToActOn.get(0).account.id); } Map<String,Id> DDRTMap = new Map<String,Id>{}; List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Disbursement_Destination__c']; system.debug('LIST OF ALL DD RECORD TYPES:' + DDRTList); for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('MAPPED RECORD TYPES' + DDRTMap); for (Case ac: CasesToActOn){ system.debug('Now Im in the FOR LOOP'); IF(ac.Recordtype.developerName == 'Fund_Transfer_Wire'){ DDRT = DDRTMap.get('Disbursement_Destination_Wire'); system.debug('Wire Case RT:' + ac.recordtype.developername + ' -- DD RT:' + DDRTMap.get('Disbursement_Destination_Wire')); } Else IF(ac.Recordtype.developerName == 'Fund_Transfer_ACH'){ DDRT = DDRTMap.get('Disbursement_Destination_ACH'); system.debug('ACH Case RT:' + ac.recordtype.developername + ' -- DD RT:' + DDRTMap.get('Disbursement_Destination_ACH')); } Else IF(ac.Recordtype.developerName == 'Fund_Transfer_Check'){ DDRT = DDRTMap.get('Disbursement_Destination_Check'); system.debug('Check Case RT:' + ac.recordtype.developername + ' -- DD RT:' + DDRTMap.get('Disbursement_Destination_Check')); } if(Trigger.isUpdate){ if(ac.Existing_or_New_Disbursement_Destination__c != trigger.oldMap.get(ac.Id).Existing_or_New_Disbursement_Destination__c){ system.debug('Now Im in the ISUPDATE'); DDList.add(new Disbursement_Destination__c( Name = ac.Receiving_Account_s_Number_Case__c, Receiving_Account_s_Name__c = ac.Receiving_Account_s_Name_Case__c, Payee_s_Name__c = ac.Payee_s_Name_Case__c, Payee_s_Street__c = ac.Payee_s_Street_Case__c, Payee_s_City__c = ac.Payee_s_Street_Case__c, Payee_s_State__c = ac.Payee_s_State_Case__c, Payee_s_Zip_Code__c = ac.Payee_s_Zip_Code_Case__c, Payee_s_Country__c = ac.Payee_s_Country_Case__c, Receiving_Bank_s_Name__c = ac.Receiving_Bank_s_Name_Case__c, Receiving_Bank_s_ABA_Wire__c = ac.Receiving_Bank_s_ABA_Wire_Case__c, Receiving_Bank_s_ABA_ACH__c = ac.Receiving_Bank_s_ABA_ACH_Case__c, Receiving_Bank_s_Street__c = ac.Receiving_Bank_s_Street_Case__c, Receiving_Bank_s_City__c = ac.Receiving_Bank_s_City_Case__c, Receiving_Bank_s_State__c = ac.Receiving_Bank_s_State_Case__c, Receiving_Bank_s_Zip_Code__c = ac.Receiving_Bank_s_Zip_Code_Case__c, Receiving_Bank_s_Country__c = ac.Receiving_Bank_s_Country_Case__c, Relationship__c = ac.Account.Id, RecordTypeId = DDRT )); } ac.Existing_or_New_Disbursement_Destination__c = 'Disbursement Destination Already Populated'; } if(Trigger.isInsert){ system.debug('Now Im in the ISINSERT'); DDList.add(new Disbursement_Destination__c( Name = ac.Receiving_Account_s_Number_Case__c, Receiving_Account_s_Name__c = ac.Receiving_Account_s_Name_Case__c, Payee_s_Name__c = ac.Payee_s_Name_Case__c, Payee_s_Street__c = ac.Payee_s_Street_Case__c, Payee_s_City__c = ac.Payee_s_Street_Case__c, Payee_s_State__c = ac.Payee_s_State_Case__c, Payee_s_Zip_Code__c = ac.Payee_s_Zip_Code_Case__c, Payee_s_Country__c = ac.Payee_s_Country_Case__c, Receiving_Bank_s_Name__c = ac.Receiving_Bank_s_Name_Case__c, Receiving_Bank_s_ABA_Wire__c = ac.Receiving_Bank_s_ABA_Wire_Case__c, Receiving_Bank_s_ABA_ACH__c = ac.Receiving_Bank_s_ABA_ACH_Case__c, Receiving_Bank_s_Street__c = ac.Receiving_Bank_s_Street_Case__c, Receiving_Bank_s_City__c = ac.Receiving_Bank_s_City_Case__c, Receiving_Bank_s_State__c = ac.Receiving_Bank_s_State_Case__c, Receiving_Bank_s_Zip_Code__c = ac.Receiving_Bank_s_Zip_Code_Case__c, Receiving_Bank_s_Country__c = ac.Receiving_Bank_s_Country_Case__c, Relationship__c = ac.Account.Id, RecordTypeId = DDRT )); ac.Existing_or_New_Disbursement_Destination__c = 'Disbursement Destination Already Populated'; } } if(DDList.size()>0){ system.debug('Inserting DDList'); insert DDList; } integer i = 0; system.debug(DDList.size()); if(DDList.size()>0){ for(Case ac: CasesToActOn){ ac.Disbursement_Destination__c = DDList.get(i).id; i += 1; } system.debug('Updating CasesToActOn'); update CasesToActOn; } }
Here's the test code. I think that the account id is getting lost somewhere in the handoff from Case to Distribution Destination, but because it works when I run it manually, I am completely stumped as to what's causing the error.
Test class:
@isTest private class TestCreateNewDistributionDestination{ static testMethod void testUpdateCaseToCreateNew(){ ////Query RecordType Id to Create PersonAccounts for Test//// Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; system.debug('RecordId:' + RecId); //NEWWWWWW Id pmId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Jason Ackerman' ].Id; account[] accs = new account[]{ new account ( salutation = 'Mr.', firstname = 'John', lastname = 'Sandbox1', Portfolio_Manager_Lookup__c=pmId , recordtypeid = RecId ), new account( salutation = 'Mr.', firstname = 'John', lastname = 'Sandbox2', Portfolio_Manager_Lookup__c=pmId , recordtypeid = RecId )}; insert accs; //End NEWWWWWW system.debug('Accounts Have Been Created' + accs.get(0).id + ', ' + accs.get(1).id); Map<String,Id> DDRTMap = new Map<String,Id>{}; ////Generate a List of Disbursement Destination Record Types//// List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Case']; ////Put the List into a Map//// for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('<<<<ABOUT TO INSERT CASES>>>>'); ////Create 6 Cases for the Test; 2 of each of 3 record types; 1 insert, 1 update of each//// Case[] Css = new Case[]{ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Wire'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Wire'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), /*new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_ACH'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_ACH'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ),*/ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Check'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Check'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ) }; system.debug('Check:' + DDRTMap.get('Fund_Transfer_Check') + ', Wire:' + DDRTMap.get('Fund_Transfer_Wire') + ', APH:' + DDRTMap.get('Fund_Transfer_ACH')); system.debug('Case 1 Account Get: ' + css.get(0).account); system.debug('Cases Have Been Created, But Not Inserted'); ////Insert the cases, update the cases needed test.starttest(); insert Css; system.debug('Inserted Css'); Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; //Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest(); List<Case> insertedCases = [ SELECT Type, RecordTypeId FROM Case WHERE Id IN :Css]; system.debug(insertedCases.size() + ' Cases Have Been Created'); system.debug(insertedCases); System.AssertEquals(insertedCases.size(),6); for(Case Cs : insertedCases ){ System.AssertEquals('Disbursement Destination Already Populated',Cs.Existing_or_New_Disbursement_Destination__c); System.AssertNotEquals('',Cs.Disbursement_Destination__c); } List<Disbursement_Destination__c> TestDDs = [ SELECT name FROM Disbursement_Destination__c]; system.debug(TestDDs); //System.Assert(TestDDs.size(),2); } }
- JAckerman09
- July 17, 2012
- Like
- 0
Unit Tests When Creating Person Accounts
This is the trigger that the test is being run on:
trigger teamMembersFollowRels on Account (after insert, after update) { for(Account acc: Trigger.new){ //**** INSERT SECTION ****// if(Trigger.isInsert){ if(acc.Portfolio_Manager_Lookup__c != Null){ EntitySubscription followPM = new EntitySubscription( parentId = acc.id, subscriberid = acc.Portfolio_Manager_Lookup__c ); insert followPM; } if(acc.Trust_Officer__c != Null){ EntitySubscription followTO = new EntitySubscription( parentId = acc.id, subscriberid = acc.Trust_Officer__c ); insert followTO; } if(acc.Wealth_Advisor__c != Null){ EntitySubscription followWA = new EntitySubscription( parentId = acc.id, subscriberid = acc.Wealth_Advisor__c ); insert followWA; } if(acc.Other_Team_Member_1__c != Null){ EntitySubscription followOT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_1__c ); insert followOT; } if(acc.Other_Team_Member_2__c != Null){ EntitySubscription followOTT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_2__c ); insert followOTT; } //**** UPDATE SECTION ****// } if (Trigger.isUpdate){ if(acc.Portfolio_Manager_Lookup__c != Null){ if(acc.Portfolio_Manager_Lookup__c != Trigger.oldMap.get(acc.ID).Portfolio_Manager_Lookup__c){ EntitySubscription followPM = new EntitySubscription( parentId = acc.id, subscriberid = acc.Portfolio_Manager_Lookup__c ); insert followPM; } } if(acc.Trust_Officer__c != Null){ if(acc.Trust_Officer__c != Trigger.oldMap.get(acc.ID).Trust_Officer__c){ EntitySubscription followTO = new EntitySubscription( parentId = acc.id, subscriberid = acc.Trust_Officer__c ); insert followTO; } } if(acc.Wealth_Advisor__c != Null){ if(acc.Wealth_Advisor__c != Trigger.oldMap.get(acc.ID).Wealth_Advisor__c){ EntitySubscription followWA = new EntitySubscription( parentId = acc.id, subscriberid = acc.Wealth_Advisor__c ); insert followWA; } } if(acc.Other_Team_Member_1__c != Null){ if(acc.Other_Team_Member_1__c != Trigger.oldMap.get(acc.ID).Other_Team_Member_1__c){ EntitySubscription followOT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_1__c ); insert followOT; } } if(acc.Other_Team_Member_2__c != Null){ if(acc.Other_Team_Member_2__c != Trigger.oldMap.get(acc.ID).Other_Team_Member_2__c){ EntitySubscription followOTT = new EntitySubscription( parentId = acc.id, subscriberid = acc.Other_Team_Member_2__c ); insert followOTT; } } } } }
Here's the unit test:
@isTest private class testTeamMembersFollowRels{ static testMethod void insertAccountWithFollowers(){ system.debug('Start...'); Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; Id pmId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Jason Ackerman' ].Id; Id toId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Linell Bigelow' ].Id; Id waId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Zoie Flaks' ].Id; Id otId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Aneta Bijak' ].Id; Id ottId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Marianne Noonan' ].Id; account accs = new account( //Name='', salutation = 'Mr.', firstname = 'John', lastname = 'Sandbox1', Portfolio_Manager_Lookup__c=pmId , Trust_Officer__c=toId, Wealth_Advisor__c=waId, Other_Team_Member_1__c=otId, Other_Team_Member_2__c=ottId, recordtypeid = RecId ); insert accs; //accs.recordtypeid = RecId; //update accs; //contact cons = new contact(accountid=accs.id, salutation='Mr.',firstname='John',lastname='Sandbox1'); //insert cons; //Find New Chatter Entity// EntitySubscription followedPM = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accs.Portfolio_Manager_Lookup__c AND parentid = :accs.id ]; EntitySubscription followedTO = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accs.Trust_Officer__c AND parentid = :accs.id ]; EntitySubscription followedWA = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accs.Wealth_Advisor__c AND parentid = :accs.id ]; EntitySubscription followedOT = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accs.Other_Team_Member_1__c AND parentid = :accs.id ]; EntitySubscription followedOTT = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accs.Other_Team_Member_2__c AND parentid = :accs.id ]; system.debug('BEFORE SYSTEM ASSERTS:: PM: ' + pmId + ', TO: ' + toId + ', WA: ' + waId + ', OT: ' + otId + ', OTT: ' + ottId); system.assertequals(followedPM.parentid, accs.id); system.assertequals(followedPM.subscriberid, accs.Portfolio_Manager_Lookup__c); system.assertequals(followedTO.parentid, accs.id); system.assertequals(followedTO.subscriberid, accs.Trust_Officer__c); system.assertequals(followedWA.parentid, accs.id); system.assertequals(followedWA.subscriberid, accs.Wealth_Advisor__c); system.assertequals(followedOT.parentid, accs.id); system.assertequals(followedOT.subscriberid, accs.Other_Team_Member_1__c); system.assertequals(followedOTT.parentid, accs.id); system.assertequals(followedOTT.subscriberid, accs.Other_Team_Member_2__c); //TEST UPDATE// account accsUp = new account( //Name='Mr. John Sandbox2', salutation = 'Mr.', firstname = 'John', lastname = 'Sandbox1', recordtypeid = RecId ); insert accsUp; //contact consUp = new contact(accountid=accsUp.id,salutation='Mr.',firstname='John',lastname='Sandbox2'); //insert consUp; //accsUp.recordtypeid = RecId; //update accsUp; system.debug('AFTER SYSTEM ASSERTS:: PM: ' + pmId + ', TO: ' + toId + ', WA: ' + waId + ', OT: ' + otId + ', OTT: ' + ottId); accsUp.Portfolio_Manager_Lookup__c=pmId; accsUp.Trust_Officer__c=toId; accsUp.Wealth_Advisor__c=waId; accsUp.Other_Team_Member_1__c=otId; accsUp.Other_Team_Member_2__c=ottId; update accsUp; EntitySubscription followedPMUP = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accsUp.Portfolio_Manager_Lookup__c AND parentid = :accsUp.id ]; EntitySubscription followedTOUP = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accsUp.Trust_Officer__c AND parentid = :accsUp.id ]; EntitySubscription followedWAUP = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accsUp.Wealth_Advisor__c AND parentid = :accsUp.id ]; EntitySubscription followedOTUP = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accsUp.Other_Team_Member_1__c AND parentid = :accsUp.id ]; EntitySubscription followedOTTUP = [ SELECT id, parentid, subscriberid, parent.name FROM EntitySubscription WHERE subscriberid = :accsUp.Other_Team_Member_2__c AND parentid = :accsUp.id ]; system.assertequals(followedPMUP.parentid, accsUP.id); system.assertequals(followedPMUP.subscriberid, accsUP.Portfolio_Manager_Lookup__c); system.assertequals(followedTOUP.parentid, accsUP.id); system.assertequals(followedTOUP.subscriberid, accsUP.Trust_Officer__c); system.assertequals(followedWAUP.parentid, accsUP.id); system.assertequals(followedWAUP.subscriberid, accsUP.Wealth_Advisor__c); system.assertequals(followedOTUP.parentid, accsUP.id); system.assertequals(followedOTUP.subscriberid, accsUP.Other_Team_Member_1__c); system.assertequals(followedOTTUP.parentid, accsUP.id); system.assertequals(followedOTTUP.subscriberid, accsUP.Other_Team_Member_2__c); } }
- JAckerman09
- July 11, 2012
- Like
- 0
Test Class Question: Business Relationship may not use Relationship field : Mailing Street:
I am getting the following error message:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Relationship may not use Relationship field : Mailing Street: [Mailing Street]
Stack Trace:
Class.TestCreateNewDistributionDestination.testUpdateCaseToCreateNew: line 24, column 1
The organization that this class is in uses person accounts, and I updated the code to address this from another poster's suggestion (creating accounts, then contacts, then merging them), however I am now running into this error.
Here's the code, any help would be much appreciated! This is my first test class attempt, and I am very stuck.
@isTest private class TestCreateNewDistributionDestination{ static testMethod void testUpdateCaseToCreateNew(){ ////Query RecordType Id to Create PersonAccounts for Test//// Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; system.debug('RecordId:' + RecId); ////Create PersonAccounts for Test by Creating Accounts, Then Contacts, Then Merging Them//// account[] accs = new account[] { new account(Name='Mr. John Sandbox1'), new account(name='Mr. John Sandbox2') };
////****THIS LINE IS LINE 24 AND CAUSES THE ERROR****////
insert accs; contact[] cons = new contact[] { new contact(accountid=accs[0].id,salutation='Mr.',firstname='John',lastname='Sandbox1'), new contact(accountid=accs[1].id,salutation='Mr.',firstname='John',lastname='Sandbox2') }; insert cons; accs[0].recordtypeid = accs[1].recordtypeid = RecId; update accs; system.debug('Accounts Have Been Created'); Map<String,Id> DDRTMap = new Map<String,Id>{}; ////Generate a List of Disbursement Destination Record Types//// List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Disbursement_Destination__c']; ////Put the List into a Map//// for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('<<<<ABOUT TO INSERT CASES>>>>'); ////Create 6 Cases for the Test; 2 of each of 3 record types; 1 insert, 1 update of each//// Case[] Css = new Case[]{ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ) }; system.debug('Cases Have Been Created, But Not Inserted'); ////Insert the cases, update the cases needed test.starttest(); insert Css; system.debug('Inserted Css'); Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest(); List<Case> insertedCases = [ SELECT Type, RecordTypeId FROM Case WHERE Id IN :Css]; system.debug(insertedCases.size() + ' Cases Have Been Created'); system.debug(insertedCases); System.AssertEquals(insertedCases.size(),6); for(Case Cs : insertedCases ){ System.AssertEquals('Disbursement Destination Already Populated',Cs.Existing_or_New_Disbursement_Destination__c); System.AssertNotEquals('',Cs.Disbursement_Destination__c); } List<Disbursement_Destination__c> TestDDs = [ SELECT name FROM Disbursement_Destination__c]; system.debug(TestDDs); //System.Assert(TestDDs.size(),2); } }
Thanks again!
- JAckerman09
- July 09, 2012
- Like
- 0
Test Class Question: Record Type ID not valid the for users profile: it is enabled for the profile
The test below tests a trigger that inserts a record for a custom object called 'Disbursement Destination' that has a Master-Detail relationship with Account and a LookUp relationship with Case. I think my error is coming when I insert the accounts for the test. I am getting the following message:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 012C0000000BqFyIAK: [RecordTypeId]
The record type is turned on for my profile.
The only clue that I've found is that sometimes in order to use a person account record type, you must have at least one Business record created. However, when I tried to create a business account record I got this error:
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Business Relationship may not use Relationship field : Mailing Street".
I do not have any validation rule with that or a similar name.
Any thoughts on this?? This is my first attempt at writing a trigger/test and I am completely stumped. It is also my first post to the board, so please let me know if I did anything wrong or can provide any more information on this question. Thanks!
@isTest private class TestCreateNewDistributionDestination{ static testMethod void testUpdateCaseToCreateNew(){ ////Query RecordType Id to Create PersonAccounts for Test//// Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; system.debug('RecordId:' + RecId); ////Create PersonAccounts for Test//// Account[] accs = new Account[]{ new Account(Salutation = 'Mr.', FirstName = 'John', LastName= 'Sandbox1', Relationship_Type__c = 'Current',BT_or_BGAM__c = 'Beacon Trust', RecordTypeId=RecId), new Account(Salutation = 'Mr.', FirstName = 'John', LastName= 'Sandbox2', Relationship_Type__c = 'Current',BT_or_BGAM__c = 'Beacon Trust', RecordTypeId=RecId) }; insert accs; system.debug('Accounts Have Been Created'); Map<String,Id> DDRTMap = new Map<String,Id>{}; ////Generate a List of Disbursement Destination Record Types//// List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Disbursement_Destination__c']; ////Put the List into a Map//// for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('<<<<ABOUT TO INSERT CASES>>>>'); ////Create 6 Cases for the Test; 2 of each of 3 record types; 1 insert, 1 update of each//// Case[] Css = new Case[]{ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ) }; system.debug('Cases Have Been Created, But Not Inserted'); ////Insert the cases, update the cases needed test.starttest(); insert Css; system.debug('Inserted Css'); Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest(); List<Case> insertedCases = [ SELECT Type, RecordTypeId FROM Case WHERE Id IN :Css]; system.debug(insertedCases.size() + ' Cases Have Been Created'); system.debug(insertedCases); System.AssertEquals(insertedCases.size(),6); for(Case Cs : insertedCases ){ System.AssertEquals('Disbursement Destination Already Populated',Cs.Existing_or_New_Disbursement_Destination__c); System.AssertNotEquals('',Cs.Disbursement_Destination__c); } List<Disbursement_Destination__c> TestDDs = [ SELECT name FROM Disbursement_Destination__c]; system.debug(TestDDs); } }
}
}
- JAckerman09
- June 28, 2012
- Like
- 0
Having case team members automatically follow the case on chatter...
Any thoughts or ideas on this one? I set up a workflow rule so that case comments are posted to the case's chatter feed, but that doesn't help too much if the case team members aren't following the case. Any thoughts on ways to have this done automatically?
My first thought was a trigger that, on insert/update:
- Queried the case team members
- Created an EntitySubscription for parentid=case.id and subscriberid=caseTeamMember.id
- Tests for existing EntitySubscription to prevent 'DUPLICATE_VALUE' error
- Tests to make sure it does not put the user over the 500 following limit
I have a trigger that I have not rolled out to production yet that has users automatically follow accounts if they are in any of 5 'account team member' fields (not a related list, just lookup fields), and I figure this would be similar, but I'd love to hear any ideas on a better/simpler way to accomplish this goal.
Thanks!
- JAckerman09
- July 20, 2012
- Like
- 0
Trigger is Failing Validation Rule, Can't Figure Out Why
My test class runs this code:
test.starttest(); insert Css; Css[1].Disbursement_Destination__c = Null; Css[3].Disbursement_Destination__c = Null; Css[5].Disbursement_Destination__c = Null; Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest();
which is causing this validation rule to fail:
AND( OR( ISPICKVAL( Existing_or_New_Disbursement_Destination__c , 'Leave Disbursement Destination Blank'), ISPICKVAL( Existing_or_New_Disbursement_Destination__c , 'Use/Create a New Disbursement Destination') ), Disbursement_Destination__c <> Null)
despite the fact that the code (attempts to) set the value of Disbursement_Desintation__c to Null.
Any insight as to why this validation rule is failing?
Thanks!
- JAckerman09
- July 19, 2012
- Like
- 0
Required Field Missing, (Only When Running Test) But I Can't Figure Out Why...
I am running a test on a trigger that creates a new 'Distribution Destination' record whenever a Case is saved with a picklist set to 'Create New Distribution Destination'.
Here's the trigger, which works when I manually test it by saving a case with the picklist set to 'Create New Distribution Destination':
I also put a note in the middle starting with DEBUG LOGS SHOW, which points out another confusing point.
Here's the error I'm getting when I run the test:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateNewDistributionDestination: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Relationship__c]: [Relationship__c] Trigger.CreateNewDistributionDestination: line 126, column 1: []
Stack Trace:
Class.TestCreateNewDistributionDestination.testUpdateCaseToCreateNew: line 209, column 1
The line that is referenced is when the new Distribution Lists are inserted in the trigger. Again, this seems to work when I run it manually, so I am assuming that the error is in the test class' handling of the account id.
The test code is below the trigger, thanks for any assistance that could be offered!!
trigger CreateNewDistributionDestination on Case (after insert, after update) { List<Disbursement_Destination__c> DDList = new List<Disbursement_Destination__c> (); Id DDRT; List<Case> CasesToActOn = [ SELECT c.Receiving_Account_s_Number_Case__c, c.Receiving_Account_s_Name_Case__c, c.Payee_s_Name_Case__c, c.Payee_s_Street_Case__c, c.Payee_s_City_Case__c, c.Payee_s_State_Case__c, c.Payee_s_Zip_Code_Case__c, c.Payee_s_Country_Case__c, c.Receiving_Bank_s_Name_Case__c, c.Receiving_Bank_s_ABA_ACH_Case__c, c.Receiving_Bank_s_ABA_Wire_Case__c, c.Receiving_Bank_s_Street_Case__c, c.Receiving_Bank_s_City_Case__c, c.Receiving_Bank_s_State_Case__c, c.Receiving_Bank_s_Zip_Code_Case__c, c.Receiving_Bank_s_Country_Case__c, c.Account.Id, c.RecordType.name, c.RecordType.developername, c.Existing_or_New_Disbursement_Destination__c FROM Case c WHERE Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination' AND c.id IN :Trigger.new FOR UPDATE ];
///// DEBUG LOGS SHOW CasesToActOn.size()=1, YET IT DOES NOT RUN THE SYSTEM.DEBUG CODE WITHIN THE IF STATEMENT, ANY IDEA WHY??? When I ran it without the If statement, I got an error that the reference was out of range. Very confused on this point. /////
system.debug('Account ID: ' + CasesToActOn.size()); if(CasesToActOn.size()>0){ system.debug('Account ID: ' + CasesToActOn.get(0).account.id); } Map<String,Id> DDRTMap = new Map<String,Id>{}; List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Disbursement_Destination__c']; system.debug('LIST OF ALL DD RECORD TYPES:' + DDRTList); for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('MAPPED RECORD TYPES' + DDRTMap); for (Case ac: CasesToActOn){ system.debug('Now Im in the FOR LOOP'); IF(ac.Recordtype.developerName == 'Fund_Transfer_Wire'){ DDRT = DDRTMap.get('Disbursement_Destination_Wire'); system.debug('Wire Case RT:' + ac.recordtype.developername + ' -- DD RT:' + DDRTMap.get('Disbursement_Destination_Wire')); } Else IF(ac.Recordtype.developerName == 'Fund_Transfer_ACH'){ DDRT = DDRTMap.get('Disbursement_Destination_ACH'); system.debug('ACH Case RT:' + ac.recordtype.developername + ' -- DD RT:' + DDRTMap.get('Disbursement_Destination_ACH')); } Else IF(ac.Recordtype.developerName == 'Fund_Transfer_Check'){ DDRT = DDRTMap.get('Disbursement_Destination_Check'); system.debug('Check Case RT:' + ac.recordtype.developername + ' -- DD RT:' + DDRTMap.get('Disbursement_Destination_Check')); } if(Trigger.isUpdate){ if(ac.Existing_or_New_Disbursement_Destination__c != trigger.oldMap.get(ac.Id).Existing_or_New_Disbursement_Destination__c){ system.debug('Now Im in the ISUPDATE'); DDList.add(new Disbursement_Destination__c( Name = ac.Receiving_Account_s_Number_Case__c, Receiving_Account_s_Name__c = ac.Receiving_Account_s_Name_Case__c, Payee_s_Name__c = ac.Payee_s_Name_Case__c, Payee_s_Street__c = ac.Payee_s_Street_Case__c, Payee_s_City__c = ac.Payee_s_Street_Case__c, Payee_s_State__c = ac.Payee_s_State_Case__c, Payee_s_Zip_Code__c = ac.Payee_s_Zip_Code_Case__c, Payee_s_Country__c = ac.Payee_s_Country_Case__c, Receiving_Bank_s_Name__c = ac.Receiving_Bank_s_Name_Case__c, Receiving_Bank_s_ABA_Wire__c = ac.Receiving_Bank_s_ABA_Wire_Case__c, Receiving_Bank_s_ABA_ACH__c = ac.Receiving_Bank_s_ABA_ACH_Case__c, Receiving_Bank_s_Street__c = ac.Receiving_Bank_s_Street_Case__c, Receiving_Bank_s_City__c = ac.Receiving_Bank_s_City_Case__c, Receiving_Bank_s_State__c = ac.Receiving_Bank_s_State_Case__c, Receiving_Bank_s_Zip_Code__c = ac.Receiving_Bank_s_Zip_Code_Case__c, Receiving_Bank_s_Country__c = ac.Receiving_Bank_s_Country_Case__c, Relationship__c = ac.Account.Id, RecordTypeId = DDRT )); } ac.Existing_or_New_Disbursement_Destination__c = 'Disbursement Destination Already Populated'; } if(Trigger.isInsert){ system.debug('Now Im in the ISINSERT'); DDList.add(new Disbursement_Destination__c( Name = ac.Receiving_Account_s_Number_Case__c, Receiving_Account_s_Name__c = ac.Receiving_Account_s_Name_Case__c, Payee_s_Name__c = ac.Payee_s_Name_Case__c, Payee_s_Street__c = ac.Payee_s_Street_Case__c, Payee_s_City__c = ac.Payee_s_Street_Case__c, Payee_s_State__c = ac.Payee_s_State_Case__c, Payee_s_Zip_Code__c = ac.Payee_s_Zip_Code_Case__c, Payee_s_Country__c = ac.Payee_s_Country_Case__c, Receiving_Bank_s_Name__c = ac.Receiving_Bank_s_Name_Case__c, Receiving_Bank_s_ABA_Wire__c = ac.Receiving_Bank_s_ABA_Wire_Case__c, Receiving_Bank_s_ABA_ACH__c = ac.Receiving_Bank_s_ABA_ACH_Case__c, Receiving_Bank_s_Street__c = ac.Receiving_Bank_s_Street_Case__c, Receiving_Bank_s_City__c = ac.Receiving_Bank_s_City_Case__c, Receiving_Bank_s_State__c = ac.Receiving_Bank_s_State_Case__c, Receiving_Bank_s_Zip_Code__c = ac.Receiving_Bank_s_Zip_Code_Case__c, Receiving_Bank_s_Country__c = ac.Receiving_Bank_s_Country_Case__c, Relationship__c = ac.Account.Id, RecordTypeId = DDRT )); ac.Existing_or_New_Disbursement_Destination__c = 'Disbursement Destination Already Populated'; } } if(DDList.size()>0){ system.debug('Inserting DDList'); insert DDList; } integer i = 0; system.debug(DDList.size()); if(DDList.size()>0){ for(Case ac: CasesToActOn){ ac.Disbursement_Destination__c = DDList.get(i).id; i += 1; } system.debug('Updating CasesToActOn'); update CasesToActOn; } }
Here's the test code. I think that the account id is getting lost somewhere in the handoff from Case to Distribution Destination, but because it works when I run it manually, I am completely stumped as to what's causing the error.
Test class:
@isTest private class TestCreateNewDistributionDestination{ static testMethod void testUpdateCaseToCreateNew(){ ////Query RecordType Id to Create PersonAccounts for Test//// Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; system.debug('RecordId:' + RecId); //NEWWWWWW Id pmId = [ SELECT u.Id, u.Name FROM User u WHERE name = 'Jason Ackerman' ].Id; account[] accs = new account[]{ new account ( salutation = 'Mr.', firstname = 'John', lastname = 'Sandbox1', Portfolio_Manager_Lookup__c=pmId , recordtypeid = RecId ), new account( salutation = 'Mr.', firstname = 'John', lastname = 'Sandbox2', Portfolio_Manager_Lookup__c=pmId , recordtypeid = RecId )}; insert accs; //End NEWWWWWW system.debug('Accounts Have Been Created' + accs.get(0).id + ', ' + accs.get(1).id); Map<String,Id> DDRTMap = new Map<String,Id>{}; ////Generate a List of Disbursement Destination Record Types//// List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Case']; ////Put the List into a Map//// for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('<<<<ABOUT TO INSERT CASES>>>>'); ////Create 6 Cases for the Test; 2 of each of 3 record types; 1 insert, 1 update of each//// Case[] Css = new Case[]{ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Wire'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Wire'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), /*new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_ACH'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_ACH'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ),*/ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Check'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Fund_Transfer_Check'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ) }; system.debug('Check:' + DDRTMap.get('Fund_Transfer_Check') + ', Wire:' + DDRTMap.get('Fund_Transfer_Wire') + ', APH:' + DDRTMap.get('Fund_Transfer_ACH')); system.debug('Case 1 Account Get: ' + css.get(0).account); system.debug('Cases Have Been Created, But Not Inserted'); ////Insert the cases, update the cases needed test.starttest(); insert Css; system.debug('Inserted Css'); Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; //Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest(); List<Case> insertedCases = [ SELECT Type, RecordTypeId FROM Case WHERE Id IN :Css]; system.debug(insertedCases.size() + ' Cases Have Been Created'); system.debug(insertedCases); System.AssertEquals(insertedCases.size(),6); for(Case Cs : insertedCases ){ System.AssertEquals('Disbursement Destination Already Populated',Cs.Existing_or_New_Disbursement_Destination__c); System.AssertNotEquals('',Cs.Disbursement_Destination__c); } List<Disbursement_Destination__c> TestDDs = [ SELECT name FROM Disbursement_Destination__c]; system.debug(TestDDs); //System.Assert(TestDDs.size(),2); } }
- JAckerman09
- July 17, 2012
- Like
- 0
Test Class Question: Record Type ID not valid the for users profile: it is enabled for the profile
The test below tests a trigger that inserts a record for a custom object called 'Disbursement Destination' that has a Master-Detail relationship with Account and a LookUp relationship with Case. I think my error is coming when I insert the accounts for the test. I am getting the following message:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 012C0000000BqFyIAK: [RecordTypeId]
The record type is turned on for my profile.
The only clue that I've found is that sometimes in order to use a person account record type, you must have at least one Business record created. However, when I tried to create a business account record I got this error:
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Business Relationship may not use Relationship field : Mailing Street".
I do not have any validation rule with that or a similar name.
Any thoughts on this?? This is my first attempt at writing a trigger/test and I am completely stumped. It is also my first post to the board, so please let me know if I did anything wrong or can provide any more information on this question. Thanks!
@isTest private class TestCreateNewDistributionDestination{ static testMethod void testUpdateCaseToCreateNew(){ ////Query RecordType Id to Create PersonAccounts for Test//// Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; system.debug('RecordId:' + RecId); ////Create PersonAccounts for Test//// Account[] accs = new Account[]{ new Account(Salutation = 'Mr.', FirstName = 'John', LastName= 'Sandbox1', Relationship_Type__c = 'Current',BT_or_BGAM__c = 'Beacon Trust', RecordTypeId=RecId), new Account(Salutation = 'Mr.', FirstName = 'John', LastName= 'Sandbox2', Relationship_Type__c = 'Current',BT_or_BGAM__c = 'Beacon Trust', RecordTypeId=RecId) }; insert accs; system.debug('Accounts Have Been Created'); Map<String,Id> DDRTMap = new Map<String,Id>{}; ////Generate a List of Disbursement Destination Record Types//// List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Disbursement_Destination__c']; ////Put the List into a Map//// for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('<<<<ABOUT TO INSERT CASES>>>>'); ////Create 6 Cases for the Test; 2 of each of 3 record types; 1 insert, 1 update of each//// Case[] Css = new Case[]{ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ) }; system.debug('Cases Have Been Created, But Not Inserted'); ////Insert the cases, update the cases needed test.starttest(); insert Css; system.debug('Inserted Css'); Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest(); List<Case> insertedCases = [ SELECT Type, RecordTypeId FROM Case WHERE Id IN :Css]; system.debug(insertedCases.size() + ' Cases Have Been Created'); system.debug(insertedCases); System.AssertEquals(insertedCases.size(),6); for(Case Cs : insertedCases ){ System.AssertEquals('Disbursement Destination Already Populated',Cs.Existing_or_New_Disbursement_Destination__c); System.AssertNotEquals('',Cs.Disbursement_Destination__c); } List<Disbursement_Destination__c> TestDDs = [ SELECT name FROM Disbursement_Destination__c]; system.debug(TestDDs); } }
}
}
- JAckerman09
- June 28, 2012
- Like
- 0
Solved - Create Chatter Notifications in Salesforce on Case Comment (no coding needed)
"Case Comment Chatter-er"
- Create a field on your case page titled "Last Case Comment Date/Time" of type "Date/Time". Don't add it to your page layouts so it is basically hidden.
- Create workflow rule named something useful such as "Note Last Case Comment Date/Time"
- Object: Case Comment
- Evaluation Criterea: When a record is created, or when a record is edited...
- Rule Criterea: "Case Comment: Body not equal to null
- Create field update on the Case Comment object that set the value to "NOW()"
Sweet.
Thanks,
Josh Lipton
Advantix Solutions Group
- JoshAdvantix
- June 21, 2010
- Like
- 1
System.StringException: Invalid id:
:smileysad: Hi all,
I am facing a problem regarding storing id in a lookup field.
I have to store contact ids in to lookup fields (via customised lookup) , my code is as follows :
Constructor is as follows : Public class class1{ public FinalCustomContact(Id acc) { newContact = ''; Id id = ApexPages.currentpage().getParameters().get('id'); rObj = (id == null) ? new caps__c():[SELECT accountname__c,name,central_contact__c from caps__c]; num = ApexPages.currentPage().getParameters().get('num'); contact = new List<contact>(); this.accname = acc; contact = [Select id,Name,LastName,Email from contact where contact.Account.id = :acc]; this.varname = null; this.idid = null; if(contact.size()==0){ msg1='No records were found based on your criteria'; } else{ } system.debug('--------------'+rObj.Central_Contact__c); //here the contact lookup displays null. } } My class from where im calling the above method which belongs to Class1: public class clss2{ ------- some code ----- Public class1 fObj{get; set;} public PageReference accountsel() { this.accname = cObj.accountname__c; system.debug('Account Name---:'+ cObj.accountname__c); fObj = new FinalCustomContact(cObj.accountname__c); return null; } if(fObj!=null && fObj.rObj != null){ system.debug('-------------'+'InsideCONTS'+fObj.rObj.Central_Contact__c); //here it displays empty. if(fObj.rObj.Central_Contact__c!='' ){ cObj.Central_Contact__c = fObj.rObj.Central_Contact__c; //here error is thrown saying Id is invalid. } } }
Urgent help is needed please help us on this issue. I have tried many workarounds but couldnt succeed
- Sushupsi
- February 15, 2010
- Like
- 0