Guest User

Untitled

a guest
Apr 26th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. saveOpportunity : function(component,event,helper){
  2. var action = component.get("c.getNewOppId");
  3. action.setCallback(this, function(response){
  4. alert('Inside Callback method');
  5. if (state == "SUCCESS") {
  6. var optyId = response.getReturnValue();
  7. alert(optyId);
  8. var urlEvent = $A.get("e.force:navigateToURL");
  9. urlEvent.setParams({
  10. "url": "/006/o" + optyId
  11. });
  12. urlEvent.fire();
  13. }
  14. });
  15. $A.enqueueAction(action);
  16.  
  17. public pageReference saveOpp(){
  18. try{
  19. Id OpptyOwnerId = [SELECT Id FROM User WHERE Id =: userInfo.getUserId() and IsActive = True LIMIT 1].Id;
  20. system.debug('++OpptyOwnerId+'+OpptyOwnerId);
  21. Id RTId = [SELECT Id FROM RecordType WHERE sObjectType ='Opportunity' LIMIT 1].Id;
  22. Boolean isRegional = false;
  23. acc= NEW account();
  24. acc= [select name,id,Sales_Region__c from Account where id =:oppty.Accountid];
  25. if(oppty.SMB_OPP_Must_Win_level__c == null)oppty.SMB_OPP_Must_Win_level__c='None';
  26. if(isRegional )
  27. oppty.SMB_Opp_Must_Win__c = 'Yes';
  28. else
  29. oppty.SMB_Opp_Must_Win__c = 'No';
  30. oppty.OwnerId = OpptyOwnerId;
  31.  
  32. if(REC.name == System.Label.OAB_Opportunity_Record_Type){
  33. oppty.StageName = '2 Qualification';
  34. }else{
  35. oppty.StageName = '1 Pre-qualification';
  36. }
  37. if(REC.name ==System.Label.OAB_Opportunity_Record_Type && acc.Sales_Region__c !='DEF'){
  38. system.debug('----------'+REC.name);
  39. ApexPages.addmessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'With a Simple DEF record type the account related to the opportunity must be a DEF account.'));
  40. return null;
  41. }
  42.  
  43. if(REC.name ==System.Label.OAB_Opportunity_Record_Type && (oppty.Order_Type__c =='New Customer' || oppty.Order_Type__c =='New Business/GET')){
  44. oppty.Contract_Type__c= 'New';
  45. }else if(REC.name ==System.Label.OAB_Opportunity_Record_Type &&(oppty.Order_Type__c =='Renewal/KEEP' || oppty.Order_Type__c =='Organic/KEEP')){
  46. oppty.Contract_Type__c= 'Existing';
  47. }
  48.  
  49. insert oppty;
  50.  
  51. //partner management evolution
  52. if(REC.name == System.Label.OAB_Opportunity_Record_Type){
  53. SMB_Partner__c insertNoPartner = new SMB_Partner__c(SMB_Opportunity__c=oppty.Id,
  54. SMB_Name__c=Label.SMB_CL001_No_Partner_ID,
  55. SMB_Amount__c=0,SMB_Percentage__c=0,
  56. SMB_Primary__c=true);
  57. insert insertNoPartner;
  58. }
  59. //assign a contact to a new opportunity
  60. if(conId!=null){
  61. OpportunityContactRole oppContact = new OpportunityContactRole(ContactId=conId,IsPrimary=true,
  62. OpportunityId=oppty.Id,Role=Label.Contact_Role);
  63. insert oppContact;
  64. }
  65. PageReference pageRef = new PageReference('/' + oppty.Id + '?retURL=%2F' + oppty.Id);
  66. return pageRef;
  67.  
  68. }
  69. catch(exception ex){
  70. if(!ex.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'))
  71. Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.ERROR, 'Exception Error: ' + ex));
  72. return null;
  73. }
  74. return null;
  75. }
  76.  
  77. public PageReference saveOpp(){
  78. Id returnedId = getNewOppId();
  79. return new PageReference('/'+returnedId);
  80. }
  81.  
  82. // Method to get the opportunity Id
  83. @AuraEnabled
  84. public static Id getNewOppId(){
  85. try{
  86. Id OpptyOwnerId = [SELECT Id FROM User WHERE Id =: userInfo.getUserId() and IsActive = True LIMIT 1].Id;
  87. system.debug('++OpptyOwnerId+'+OpptyOwnerId);
  88. Id RTId = [SELECT Id FROM RecordType WHERE sObjectType ='Opportunity' LIMIT 1].Id;
  89. Boolean isRegional = false;
  90. acc= NEW account();
  91. acc= [select name,id,Sales_Region__c from Account where id =:oppty.Accountid];
  92. if(oppty.SMB_OPP_Must_Win_level__c == null)oppty.SMB_OPP_Must_Win_level__c='None';
  93. if(isRegional )
  94. oppty.SMB_Opp_Must_Win__c = 'Yes';
  95. else
  96. oppty.SMB_Opp_Must_Win__c = 'No';
  97.  
  98. oppty.OwnerId = OpptyOwnerId;
  99.  
  100. if(REC.name == System.Label.OAB_Opportunity_Record_Type){
  101. system.debug('========'+REC.name);
  102. oppty.StageName = '2 Qualification';
  103. }else{
  104. oppty.StageName = '1 Pre-qualification';
  105. }
  106.  
  107.  
  108. if(REC.name ==System.Label.OAB_Opportunity_Record_Type && acc.Sales_Region__c !='DEF'){
  109. system.debug('----------'+REC.name);
  110. ApexPages.addmessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'With a Simple DEF record type the account related to the opportunity must be a DEF account.'));
  111. return null;
  112. }
  113.  
  114.  
  115. if(REC.name ==System.Label.OAB_Opportunity_Record_Type && (oppty.Order_Type__c =='New Customer' || oppty.Order_Type__c =='New Business/GET')){
  116. oppty.Contract_Type__c= 'New';
  117. }else if(REC.name ==System.Label.OAB_Opportunity_Record_Type &&(oppty.Order_Type__c =='Renewal/KEEP' || oppty.Order_Type__c =='Organic/KEEP')){
  118. oppty.Contract_Type__c= 'Existing';
  119. }
  120.  
  121. insert oppty;
  122.  
  123. //partner management evolution--START
  124. if(REC.name == System.Label.OAB_Opportunity_Record_Type){
  125. SMB_Partner__c insertNoPartner = new SMB_Partner__c(SMB_Opportunity__c=oppty.Id,
  126. SMB_Name__c=Label.SMB_CL001_No_Partner_ID,
  127. SMB_Amount__c=0,SMB_Percentage__c=0,
  128. SMB_Primary__c=true);
  129. insert insertNoPartner;
  130. }
  131. //partner management evolution--END
  132.  
  133. //assign a contact to a new opportunity
  134. if(conId!=null){
  135. OpportunityContactRole oppContact = new OpportunityContactRole(ContactId=conId,IsPrimary=true,
  136. OpportunityId=oppty.Id,Role=Label.Contact_Role);
  137. insert oppContact;
  138. }
  139.  
  140. return oppty.Id;
  141. }
  142. catch(exception ex){
  143. if(!ex.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'))
  144. Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.ERROR, 'Exception Error: ' + ex));
  145. return null;
  146. }
  147. }
  148.  
  149. Error in $A.getCallback() ['state' is undefined]
  150. Callback failed: apex://NewOpportunityController/ACTION$getNewOppId
Add Comment
Please, Sign In to add comment