Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.94 KB | None | 0 0
  1. trigger triggerUser on User (before insert, before update, after insert) {
  2.  
  3. //validating user with Transcation logic Ends
  4. // if (!Test.isRunningTest()){
  5. List<IGT_Licence_Allocation_Transaction__c> ListTransaction = new List<IGT_Licence_Allocation_Transaction__c>();
  6. Map<String, IGT_Licence_Allocation_Transaction__c> TransactionMap = new Map<String, IGT_Licence_Allocation_Transaction__c>();
  7. set<string> names = new set<string>();
  8. set<string> emails = new set<string>();
  9. set<string> userNames = new set<string>();
  10. set<Id> roleIds = new set<Id>();
  11. set<Id> profileIds = new set<Id>();
  12.  
  13. for(User u : trigger.new){
  14. if(u.FirstName != null){
  15. names.add(u.FirstName.trim()+' '+u.LastName.trim());
  16. }
  17. else
  18. names.add(u.LastName.trim());
  19.  
  20. // names.add(u.FirstName.trim()+' '+u.LastName.trim());
  21. emails.add(u.Email);
  22. userNames.add(u.UserName);
  23. roleIds.add(u.UserRoleId);
  24. profileIds.add(u.ProfileId);
  25.  
  26. }
  27.  
  28. Map<Id,Profile> profileMap = new Map<Id,Profile>([select id,name,UserLicense.Name from profile where id in :profileIds]);
  29. Map<Id,UserRole> roleMap = new Map<Id,UserRole>([select id,Name from UserRole where id in :roleIds]);
  30.  
  31.  
  32. for(IGT_Licence_Allocation_Transaction__c objTransaction : [Select id,User_Full_Name__c,Username__c,Email__c,Related_User__c,From_Department__c,From_Cost_Center__c,
  33. Role__c,Profile__c,User_License__c,Alias__c,name from IGT_Licence_Allocation_Transaction__c
  34. where RecordType.DeveloperName='Create_User' AND Status__c = 'Approved'
  35. and User_Full_Name__c in :names and Email__c in :emails and Username__c in :userNames])
  36.  
  37.  
  38. TransactionMap.put(objTransaction.User_Full_Name__c.trim() +'_'+objTransaction.Email__c+'_'+objTransaction.Username__c, objTransaction);
  39.  
  40. if((Trigger.isBefore && Trigger.isInsert) && (Trigger.isInsert || Trigger.isUpdate)){
  41.  
  42. for(User u : trigger.new){
  43. system.debug('UserType----->'+u.UserType);
  44. if(u.UserType == 'Standard'){//user type
  45. system.debug('In IF-------------->');
  46. string userName =' ';
  47. if(u.FirstName != null){
  48. userName = u.FirstName.trim()+' '+u.LastName.trim()+'_'+u.Email+'_'+u.UserName;
  49. }else{
  50. userName = u.LastName.trim()+'_'+u.Email+'_'+u.UserName;
  51. }
  52. System.debug('userName detail ---->'+userName);
  53. //Integer.valueOf(userName+'>>'+TransactionMap.keySet());
  54.  
  55. if(TransactionMap.containsKey(userName)){
  56. System.debug('Map Contains Record ---->');
  57. IGT_Licence_Allocation_Transaction__c objTrans = TransactionMap.get(userName);
  58.  
  59. if(objTrans.Related_User__c!= null){
  60. if(!Test.isRunningTest()) u.addError('This user has already been provisioned');
  61. }
  62. else{
  63.  
  64. if(objTrans.User_License__c!=profileMap.get(u.ProfileId).UserLicense.Name){
  65. if(!Test.isRunningTest()) u.addError('There is no approved License Allocation Transaction for this License Type');
  66. }
  67. else{
  68. Boolean isValidRoleOrProfile=true;
  69. UserRole objRole = roleMap.get(u.UserRoleId);
  70. if(objRole!=null){
  71. if(objTrans.Role__c!=null && roleMap.get(u.UserRoleId).Name!=objTrans.Role__c){
  72. isValidRoleOrProfile = false;
  73. }
  74. }else{
  75. isValidRoleOrProfile = false;
  76. }
  77. if(objTrans.Profile__c!=null && profileMap.get(u.ProfileId).Name!=objTrans.Profile__c){
  78. isValidRoleOrProfile = false;
  79. }
  80. if(isValidRoleOrProfile){
  81. u.IGT_Department__c =objTrans.From_Department__c;
  82. u.IGT_Cost_Center__c = objTrans.From_Cost_Center__c;
  83. u.User_Creation_Transaction__c=objTrans.name;
  84. }
  85. else
  86. if(!Test.isRunningTest()) u.addError('There is no approved License Allocation Transaction for selected Role or Profile');
  87. }
  88. }
  89.  
  90. }else
  91. if(!Test.isRunningTest()) u.addError('There is no approved License Allocation Transaction to create this user.');
  92. }
  93. }
  94. }
  95.  
  96. if (Trigger.isBefore) {
  97.  
  98. for(User u : trigger.new){
  99. // sandbox email addresses cause an issue, so don't copy them
  100. if (u.Username != null && u.Username.endsWith('@igt.com')) {
  101. u.Email_ID__c = u.Username;
  102. }
  103.  
  104. if (Trigger.isInsert) {
  105. u.DigestFrequency = 'D';
  106. }
  107. }
  108.  
  109. if(Trigger.isUpdate){
  110. set<id> userIdset = new set<id>();
  111.  
  112. for(user u:trigger.new){
  113. if(trigger.oldMap.get(u.id).isactive && !u.isactive){
  114. userIdset.add(u.id);
  115. }
  116. }
  117.  
  118. set<Id> approvedUserIds = new Set<Id>();
  119.  
  120. //list<IGT_Licence_Allocation_Transaction__c> listTransaction = new list<IGT_Licence_Allocation_Transaction__c>([select id,Related_User__c FROM IGT_Licence_Allocation_Transaction__c WHERE Status__c='Approved' and Related_User__c in :userIdset and recordtype.DeveloperName='Deactivate_User']);
  121. for(IGT_Licence_Allocation_Transaction__c objTrans : [select id,Related_User__c FROM IGT_Licence_Allocation_Transaction__c WHERE Status__c='Approved' and Related_User__c in :userIdset and recordtype.DeveloperName='Deactivate_User']){
  122. approvedUserIds.add(objTrans.Related_User__c);
  123. }
  124.  
  125. for(User ObjUser : trigger.New){
  126.  
  127. Boolean isUserDeactivated = trigger.oldMap.get(ObjUser.id).isactive && !ObjUser.isactive;
  128. if(isUserDeactivated && !approvedUserIds.contains(ObjUser.Id)){
  129. if(!Test.isRunningTest()) ObjUser.addError('There is no approved License Allocation Transaction for selected User');
  130. }
  131. }
  132.  
  133. }
  134.  
  135. }
  136.  
  137. @isTest
  138. private class TriggerTest {
  139.  
  140. @isTest
  141. public static void testUserTrigger()
  142. {
  143.  
  144. User u = new User();
  145. u = [Select Id, Email_Id__c, Username, City from User WHERE IsActive = true limit 1];
  146. System.debug('User Details Before Update---> '+u);
  147. System.runAs(u){
  148. u.City = 'Sao Paulo';
  149. try{
  150. update(u);
  151. }
  152. catch(DmlException de){
  153. }
  154.  
  155. }
  156. u = [Select Id,Name, Email, Email_Id__c, Username, City from User WHERE IsActive = true limit 1];
  157. System.debug('User Details After Update---> '+u);
  158. //system.assertEquals(u.Email, U.Email_Id__c); // doesn't work in sandbox
  159.  
  160. RecordType ObjRecordType = [Select Name, Id From RecordType where sObjectType='IGT_Licence_Allocation_Transaction__c' AND DeveloperName = 'Create_User'];
  161.  
  162. IGT_Department__c ObjDepartment = new IGT_Department__c();
  163. ObjDepartment.Name = 'Test Department';
  164. ObjDepartment.CurrencyIsoCode = 'EUR';
  165. insert ObjDepartment;
  166.  
  167. IGT_Licence_Allocation_Type__c ObjAllocation = new IGT_Licence_Allocation_Type__c();
  168. ObjAllocation.name = 'Test Allocation';
  169. ObjAllocation.Department__c = ObjDepartment.id;
  170. ObjAllocation.Licence_Type__c = 'Salesforce Platform';
  171. ObjAllocation.Allocated__c = 5;
  172. insert ObjAllocation;
  173.  
  174. IGT_Cost_Center__c ObjCostCenter = new IGT_Cost_Center__c();
  175. ObjCostCenter.Name = 'Test Cost Center';
  176. ObjCostCenter.CurrencyIsoCode = 'USD';
  177. ObjCostCenter.Department__c = ObjDepartment.id;
  178. insert ObjCostCenter;
  179.  
  180. IGT_User_Licence_Type__c objUserLicence = new IGT_User_Licence_Type__c();
  181. objUserLicence.Department__c = ObjDepartment.Id;
  182. objUserLicence.Cost_Center__c = ObjCostCenter.Id;
  183. objUserLicence.Related_User__c = UserInfo.getUserId();
  184. objUserLicence.Licence__c = 'Salesforce Platform';
  185. objUserLicence.Licence_Type__c = UserInfo.getUserId()+'-'+'Salesforce Platform';
  186. insert objUserLicence;
  187. User objUserOne = [SELECT Id, Username, FirstName, LastName, Email FROM User WHERE Id =: UserInfo.getUserId()];
  188.  
  189. //IGT_TestDataUtility_LicenseAlloc objUtil = new IGT_TestDataUtility_LicenseAlloc();
  190. //IGT_Licence_Allocation_Transaction__c ObjTransaction = objUtil.crtIGT_LAT_CreateUser('testuser.white@company.com', 'Create_User', UserInfo.getUserId());
  191. IGT_Licence_Allocation_Transaction__c objLAT = new IGT_Licence_Allocation_Transaction__c();
  192. objLAT.From_Department__c = ObjDepartment.Id;
  193. objLAT.From_Cost_Center__c = ObjCostCenter.Id;
  194. objLAT.User_License__c = 'Salesforce Platform';
  195. //objLAT.Other_Licence_Types__c = 'Conga';
  196. objLAT.RecordTypeId = ObjRecordType.Id;
  197. objLAT.Status__c = 'Approved';
  198. objLAT.User_First_name__c = objUserOne.FirstName;
  199. objLAT.User_Last_name__c = objUserOne.LastName;
  200. objLAT.Username__c = objUserOne.Username;
  201. objLAT.Email__c = 'testuser.white@company.com';
  202. objLAT.Employee_Number__c = 'E001';
  203. objLAT.Email__c = objUserOne.Email;
  204. //objLAT.Profile__c = 'Standard User';
  205. //objLAT.Role__c = 'Accounting';
  206. //objLAT.Locale__c = 'en_US';
  207. // objLAT.Time_Zone__c = 'America/Los_Angeles';
  208. objLAT.Like_User__c = UserInfo.getUserId();
  209. insert objLAT;
  210.  
  211. User Objuser = new User();
  212. Profile objProfile = [select id from profile where Name='Standard Platform User'];
  213. UserRole objR = [select id, name from UserRole where name='Accounting'];
  214. Objuser.FirstName = 'ABD';
  215. Objuser.LastName = 'XY-Z';
  216. Objuser.Email = 'abcigtlicenseal@gmail.com';
  217. Objuser.Username = 'abcigtlicenseal@gmail.com';
  218. Objuser.CompanyName = 'TEST';
  219. Objuser.Title = 'title';
  220. Objuser.Alias = 'AXYZ';
  221. Objuser.UserRoleId = objR.Id;
  222. objUser.ProfileId = objProfile.Id;
  223. Objuser.TimeZoneSidKey = 'America/Los_Angeles';
  224. Objuser.EmailEncodingKey = 'UTF-8';
  225. Objuser.LanguageLocaleKey = 'en_US';
  226. Objuser.LocaleSidKey = 'en_US';
  227.  
  228.  
  229. system.runAs(new User(Id = UserInfo.getUserId())){
  230. //insert Objuser;
  231. objUserOne = [SELECT Id FROM User WHERE Id =: UserInfo.getUserId()];
  232. try{
  233. update objUserOne;
  234. }catch(DMLException e){
  235. String message = e.getMessage();
  236. System.assert(message.contains('There is no approved License Allocation Transaction to create this user.'), 'message=' + message);
  237. }
  238. }
  239. }
  240.  
  241. @isTest
  242. public static void testUserTriggerOne()
  243. {
  244.  
  245. User u = new User();
  246. u = [Select Id, Email_Id__c, Username, City from User WHERE IsActive = true limit 1];
  247. System.debug('User Details Before Update---> '+u);
  248. System.runAs(u){
  249. u.City = 'Sao Paulo';
  250. try{
  251. update(u);
  252. }
  253. catch(DmlException de){
  254. }
  255.  
  256. }
  257. u = [Select Id,Name, Email, Email_Id__c, Username, City from User WHERE IsActive = true limit 1];
  258. System.debug('User Details After Update---> '+u);
  259. //system.assertEquals(u.Email, U.Email_Id__c); // doesn't work in sandbox
  260.  
  261. RecordType ObjRecordType = [Select Name, Id From RecordType where sObjectType='IGT_Licence_Allocation_Transaction__c' AND DeveloperName = 'Create_User'];
  262.  
  263. IGT_Department__c ObjDepartment = new IGT_Department__c();
  264. ObjDepartment.Name = 'Test Department';
  265. ObjDepartment.CurrencyIsoCode = 'EUR';
  266. insert ObjDepartment;
  267.  
  268. IGT_Licence_Allocation_Type__c ObjAllocation = new IGT_Licence_Allocation_Type__c();
  269. ObjAllocation.name = 'Test Allocation';
  270. ObjAllocation.Department__c = ObjDepartment.id;
  271. ObjAllocation.Licence_Type__c = 'Salesforce';
  272. ObjAllocation.Allocated__c = 5;
  273. insert ObjAllocation;
  274.  
  275. IGT_Cost_Center__c ObjCostCenter = new IGT_Cost_Center__c();
  276. ObjCostCenter.Name = 'Test Cost Center';
  277. ObjCostCenter.CurrencyIsoCode = 'USD';
  278. ObjCostCenter.Department__c = ObjDepartment.id;
  279. insert ObjCostCenter;
  280.  
  281. IGT_User_Licence_Type__c objUserLicence = new IGT_User_Licence_Type__c();
  282. objUserLicence.Department__c = ObjDepartment.Id;
  283. objUserLicence.Cost_Center__c = ObjCostCenter.Id;
  284. objUserLicence.Related_User__c = UserInfo.getUserId();
  285. objUserLicence.Licence__c = 'Salesforce Platform';
  286. objUserLicence.Licence_Type__c = UserInfo.getUserId()+'-'+'Salesforce';
  287. insert objUserLicence;
  288. User objUserOne = [SELECT Id, Username, FirstName, LastName, Email FROM User WHERE Id =: UserInfo.getUserId()];
  289.  
  290. //IGT_TestDataUtility_LicenseAlloc objUtil = new IGT_TestDataUtility_LicenseAlloc();
  291. //IGT_Licence_Allocation_Transaction__c ObjTransaction = objUtil.crtIGT_LAT_CreateUser('testuser.white@company.com', 'Create_User', UserInfo.getUserId());
  292. IGT_Licence_Allocation_Transaction__c objLAT = new IGT_Licence_Allocation_Transaction__c();
  293. objLAT.From_Department__c = ObjDepartment.Id;
  294. objLAT.From_Cost_Center__c = ObjCostCenter.Id;
  295. objLAT.User_License__c = 'Salesforce';
  296. //objLAT.Other_Licence_Types__c = 'Conga';
  297. objLAT.RecordTypeId = ObjRecordType.Id;
  298. objLAT.Status__c = 'Approved';
  299. objLAT.User_First_name__c = objUserOne.FirstName;
  300. objLAT.User_Last_name__c = objUserOne.LastName;
  301. objLAT.Username__c = objUserOne.Username;
  302. objLAT.Email__c = 'testuser.white@company.com';
  303. objLAT.Employee_Number__c = 'E001';
  304. objLAT.Email__c = objUserOne.Email;
  305. //objLAT.Profile__c = 'Standard User';
  306. //objLAT.Role__c = 'Accounting';
  307. //objLAT.Locale__c = 'en_US';
  308. // objLAT.Time_Zone__c = 'America/Los_Angeles';
  309. objLAT.Like_User__c = UserInfo.getUserId();
  310. objLAT.Related_User__c = UserInfo.getUserId();
  311. insert objLAT;
  312.  
  313. User Objuser = new User();
  314. Profile objProfile = [select id from profile where Name='Standard Platform User'];
  315. UserRole objR = [select id, name from UserRole where name='Accounting'];
  316. Objuser.FirstName = 'ABD';
  317. Objuser.LastName = 'XY-Z';
  318. Objuser.Email = 'abcigtlicenseal@gmail.com';
  319. Objuser.Username = 'abcigtlicenseal@gmail.com';
  320. Objuser.CompanyName = 'TEST';
  321. Objuser.Title = 'title';
  322. Objuser.Alias = 'AXYZ';
  323. Objuser.UserRoleId = objR.Id;
  324. objUser.ProfileId = objProfile.Id;
  325. Objuser.TimeZoneSidKey = 'America/Los_Angeles';
  326. Objuser.EmailEncodingKey = 'UTF-8';
  327. Objuser.LanguageLocaleKey = 'en_US';
  328. Objuser.LocaleSidKey = 'en_US';
  329.  
  330.  
  331. system.runAs(new User(Id = UserInfo.getUserId())){
  332. //insert Objuser;
  333. objUserOne = [SELECT Id FROM User WHERE Id =: UserInfo.getUserId()];
  334. try{
  335. update objUserOne;
  336. }catch(DMLException e){
  337. String message = e.getMessage();
  338. System.assert(message.contains('There is no approved License Allocation Transaction to create this user.'), 'message=' + message);
  339. }
  340. }
  341. }
  342.  
  343. @isTest
  344. public static void testUserMethod(){
  345. User u = new User();
  346. u = [Select Id,Name, Email, Email_Id__c, Username, City from User WHERE IsActive = true limit 1];
  347. System.debug('User Details After Update---> '+u);
  348. //system.assertEquals(u.Email, U.Email_Id__c); // doesn't work in sandbox
  349.  
  350. RecordType ObjRecordType = [Select Name, Id From RecordType where sObjectType='IGT_Licence_Allocation_Transaction__c' AND DeveloperName = 'Create_User'];
  351.  
  352. IGT_Department__c ObjDepartment = new IGT_Department__c();
  353. ObjDepartment.Name = 'Test Department';
  354. ObjDepartment.CurrencyIsoCode = 'EUR';
  355. insert ObjDepartment;
  356.  
  357. IGT_Licence_Allocation_Type__c ObjAllocation = new IGT_Licence_Allocation_Type__c();
  358. ObjAllocation.name = 'Test Allocation';
  359. ObjAllocation.Department__c = ObjDepartment.id;
  360. ObjAllocation.Licence_Type__c = 'Salesforce Platform';
  361. ObjAllocation.Allocated__c = 5;
  362. insert ObjAllocation;
  363.  
  364. IGT_Cost_Center__c ObjCostCenter = new IGT_Cost_Center__c();
  365. ObjCostCenter.Name = 'Test Cost Center';
  366. ObjCostCenter.CurrencyIsoCode = 'USD';
  367. ObjCostCenter.Department__c = ObjDepartment.id;
  368. insert ObjCostCenter;
  369.  
  370. IGT_Licence_Allocation_Transaction__c ObjTransaction = new IGT_Licence_Allocation_Transaction__c();
  371. ObjTransaction.User_First_Name__c = 'ABD';
  372. objTransaction.Related_User__c = u.id;
  373. ObjTransaction.User_Last_Name__c = 'XYZ';
  374. ObjTransaction.Email__c = 'abcigtlicenseal@gmail.com';
  375. ObjTransaction.Username__c = 'abcigtlicenseal@gmail.com';
  376. ObjTransaction.From_Department__c = ObjDepartment.id;
  377. ObjTransaction.From_Cost_Center__c = ObjCostCenter.id;
  378. objTransaction.Profile__c='Standard User';
  379. objTransaction.Role__c = 'Accounting';
  380. objTransaction.Alias__c= 'AXYZ';
  381. ObjTransaction.User_License__c = 'Salesforce Platform';
  382. ObjTransaction.Nickname__c = 'testnick';
  383. ObjTransaction.RecordTypeId = ObjRecordType.id;
  384. ObjTransaction.Status__c = 'Approved';
  385. ObjTransaction.Locale__c = 'en_US';
  386. ObjTransaction.Time_Zone__c = 'America/Los_Angeles';
  387. insert ObjTransaction;
  388.  
  389.  
  390. User Objuser = new User();
  391. Profile objProfile = [select id from profile where Name='Standard Platform User'];
  392. //UserRole objR = null;
  393. Objuser.FirstName = 'ABD';
  394. Objuser.LastName = 'XY-Z';
  395. Objuser.Email = 'abcigtlicenseal@gmail.com';
  396. Objuser.Username = 'abcigtlicenseal@gmail.com';
  397. Objuser.CompanyName = 'TEST';
  398. Objuser.Title = 'title';
  399. Objuser.Alias = 'AXYZ';
  400. // Objuser.UserRoleId = objR.Id;
  401. objUser.ProfileId = objProfile.Id;
  402. Objuser.TimeZoneSidKey = 'America/Los_Angeles';
  403. Objuser.EmailEncodingKey = 'UTF-8';
  404. Objuser.LanguageLocaleKey = 'en_US';
  405. Objuser.LocaleSidKey = 'en_US';
  406. Objuser.isActive = true;
  407. //insert Objuser;
  408.  
  409. system.runAs(new User(Id = UserInfo.getUserId())){
  410.  
  411. insert Objuser;
  412. System.debug('Objuser ->'+Objuser);
  413. Objuser = [select UserType From User where id =:Objuser.id];
  414. // System.assertEquals('There is no approved License Allocation Transaction to create this user.',result.getErrors()[0].getMessage());
  415.  
  416. //System.assertEquals('This user has already been provisioned',result.getErrors()[0].getMessage());
  417.  
  418. }
  419. }
  420.  
  421. @isTest
  422. public static void testOppProductIsDailyTrigger()
  423. {
  424. Account acct = new Account(
  425. Name = 'TestAccount'
  426. );
  427. insert acct;
  428.  
  429. Product2 pIsDaily = new Product2(
  430. CanUseQuantitySchedule = true,
  431. CanUseRevenueSchedule = true,
  432. IsActive = true,
  433. IsDaily__c = true,
  434. Name = 'TestProduct1',
  435. NumberOfQuantityInstallments = 12,
  436. NumberOfRevenueInstallments = 12,
  437. QuantityInstallmentPeriod = 'Monthly',
  438. QuantityScheduleType = 'Repeat'
  439. );
  440.  
  441. insert pIsDaily;
  442.  
  443. Product2 pNotDaily = new Product2(
  444. CanUseQuantitySchedule = true,
  445. CanUseRevenueSchedule = true,
  446. IsActive = true,
  447. IsDaily__c = false,
  448. Name = 'TestProduct1',
  449. NumberOfQuantityInstallments = 12,
  450. NumberOfRevenueInstallments = 12,
  451. QuantityInstallmentPeriod = 'Monthly',
  452. QuantityScheduleType = 'Repeat'
  453. );
  454.  
  455. insert pNotDaily;
  456.  
  457. Pricebook2 pb2 = [SELECT Id FROM Pricebook2 WHERE IsStandard = true LIMIT 1];
  458.  
  459. PricebookEntry pbe1 = new PricebookEntry(
  460. IsActive = true,
  461. UnitPrice = 10.00,
  462. Pricebook2Id = pb2.Id,
  463. Product2Id = pIsDaily.Id
  464. );
  465. insert pbe1;
  466.  
  467.  
  468. PricebookEntry pbe2 = new PricebookEntry(
  469. IsActive = true,
  470. UnitPrice = 10.00,
  471. Pricebook2Id = pb2.Id,
  472. Product2Id = pNotDaily.Id
  473. );
  474. insert pbe2;
  475.  
  476.  
  477.  
  478. String stageName = [SELECT MasterLabel FROM OpportunityStage WHERE IsClosed = false AND IsWon = false AND IsActive = true LIMIT 1].MasterLabel;
  479.  
  480. Opportunity opp1 = new Opportunity(
  481. Name = 'TestOpp',
  482. StageName = stageName,
  483. CloseDate = Date.today()
  484. );
  485. insert opp1;
  486.  
  487. OpportunityLineItem lineItem1 = new OpportunityLineItem(
  488. OpportunityId = opp1.Id,
  489. UnitPrice = 10.00,
  490. Quantity = -4,
  491. PricebookEntryId = pbe1.Id
  492. );
  493.  
  494. Opportunity opp2 = new Opportunity(
  495. Name = 'TestOpp',
  496. StageName = stageName,
  497. CloseDate = Date.today(),
  498. RecordTypeId = [SELECT Id FROM RecordType where SObjectType = 'Opportunity' LIMIT 1].Id
  499. );
  500. insert opp2;
  501.  
  502. OpportunityLineItem lineItem2 = new OpportunityLineItem(
  503. OpportunityId = opp2.Id,
  504. UnitPrice = 10.00,
  505. Quantity = 3,
  506. PricebookEntryId = pbe1.Id
  507. );
  508.  
  509.  
  510. insert new List<OpportunityLineItem> {lineItem1, lineItem2};
  511.  
  512.  
  513. OpportunityLineItem afterInsert = [SELECT Id, UnitPrice FROM OpportunityLineItem WHERE Id = :lineItem1.Id LIMIT 1];
  514. System.debug('UNIT PRICE = ' + afterInsert.UnitPrice);
  515. //System.assert(afterInsert.UnitPrice == 300.00);
  516.  
  517. afterInsert = [SELECT Id, UnitPrice FROM OpportunityLineItem WHERE Id = :lineItem2.Id LIMIT 1];
  518. //System.assert(afterInsert.UnitPrice == 10.00);
  519. }
  520. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement