Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- saveOpportunity : function(component,event,helper){
- var action = component.get("c.getNewOppId");
- action.setCallback(this, function(response){
- alert('Inside Callback method');
- if (state == "SUCCESS") {
- var optyId = response.getReturnValue();
- alert(optyId);
- var urlEvent = $A.get("e.force:navigateToURL");
- urlEvent.setParams({
- "url": "/006/o" + optyId
- });
- urlEvent.fire();
- }
- });
- $A.enqueueAction(action);
- public pageReference saveOpp(){
- try{
- Id OpptyOwnerId = [SELECT Id FROM User WHERE Id =: userInfo.getUserId() and IsActive = True LIMIT 1].Id;
- system.debug('++OpptyOwnerId+'+OpptyOwnerId);
- Id RTId = [SELECT Id FROM RecordType WHERE sObjectType ='Opportunity' LIMIT 1].Id;
- Boolean isRegional = false;
- acc= NEW account();
- acc= [select name,id,Sales_Region__c from Account where id =:oppty.Accountid];
- if(oppty.SMB_OPP_Must_Win_level__c == null)oppty.SMB_OPP_Must_Win_level__c='None';
- if(isRegional )
- oppty.SMB_Opp_Must_Win__c = 'Yes';
- else
- oppty.SMB_Opp_Must_Win__c = 'No';
- oppty.OwnerId = OpptyOwnerId;
- if(REC.name == System.Label.OAB_Opportunity_Record_Type){
- oppty.StageName = '2 Qualification';
- }else{
- oppty.StageName = '1 Pre-qualification';
- }
- if(REC.name ==System.Label.OAB_Opportunity_Record_Type && acc.Sales_Region__c !='DEF'){
- system.debug('----------'+REC.name);
- 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.'));
- return null;
- }
- if(REC.name ==System.Label.OAB_Opportunity_Record_Type && (oppty.Order_Type__c =='New Customer' || oppty.Order_Type__c =='New Business/GET')){
- oppty.Contract_Type__c= 'New';
- }else if(REC.name ==System.Label.OAB_Opportunity_Record_Type &&(oppty.Order_Type__c =='Renewal/KEEP' || oppty.Order_Type__c =='Organic/KEEP')){
- oppty.Contract_Type__c= 'Existing';
- }
- insert oppty;
- //partner management evolution
- if(REC.name == System.Label.OAB_Opportunity_Record_Type){
- SMB_Partner__c insertNoPartner = new SMB_Partner__c(SMB_Opportunity__c=oppty.Id,
- SMB_Name__c=Label.SMB_CL001_No_Partner_ID,
- SMB_Amount__c=0,SMB_Percentage__c=0,
- SMB_Primary__c=true);
- insert insertNoPartner;
- }
- //assign a contact to a new opportunity
- if(conId!=null){
- OpportunityContactRole oppContact = new OpportunityContactRole(ContactId=conId,IsPrimary=true,
- OpportunityId=oppty.Id,Role=Label.Contact_Role);
- insert oppContact;
- }
- PageReference pageRef = new PageReference('/' + oppty.Id + '?retURL=%2F' + oppty.Id);
- return pageRef;
- }
- catch(exception ex){
- if(!ex.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'))
- Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.ERROR, 'Exception Error: ' + ex));
- return null;
- }
- return null;
- }
- public PageReference saveOpp(){
- Id returnedId = getNewOppId();
- return new PageReference('/'+returnedId);
- }
- // Method to get the opportunity Id
- @AuraEnabled
- public static Id getNewOppId(){
- try{
- Id OpptyOwnerId = [SELECT Id FROM User WHERE Id =: userInfo.getUserId() and IsActive = True LIMIT 1].Id;
- system.debug('++OpptyOwnerId+'+OpptyOwnerId);
- Id RTId = [SELECT Id FROM RecordType WHERE sObjectType ='Opportunity' LIMIT 1].Id;
- Boolean isRegional = false;
- acc= NEW account();
- acc= [select name,id,Sales_Region__c from Account where id =:oppty.Accountid];
- if(oppty.SMB_OPP_Must_Win_level__c == null)oppty.SMB_OPP_Must_Win_level__c='None';
- if(isRegional )
- oppty.SMB_Opp_Must_Win__c = 'Yes';
- else
- oppty.SMB_Opp_Must_Win__c = 'No';
- oppty.OwnerId = OpptyOwnerId;
- if(REC.name == System.Label.OAB_Opportunity_Record_Type){
- system.debug('========'+REC.name);
- oppty.StageName = '2 Qualification';
- }else{
- oppty.StageName = '1 Pre-qualification';
- }
- if(REC.name ==System.Label.OAB_Opportunity_Record_Type && acc.Sales_Region__c !='DEF'){
- system.debug('----------'+REC.name);
- 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.'));
- return null;
- }
- if(REC.name ==System.Label.OAB_Opportunity_Record_Type && (oppty.Order_Type__c =='New Customer' || oppty.Order_Type__c =='New Business/GET')){
- oppty.Contract_Type__c= 'New';
- }else if(REC.name ==System.Label.OAB_Opportunity_Record_Type &&(oppty.Order_Type__c =='Renewal/KEEP' || oppty.Order_Type__c =='Organic/KEEP')){
- oppty.Contract_Type__c= 'Existing';
- }
- insert oppty;
- //partner management evolution--START
- if(REC.name == System.Label.OAB_Opportunity_Record_Type){
- SMB_Partner__c insertNoPartner = new SMB_Partner__c(SMB_Opportunity__c=oppty.Id,
- SMB_Name__c=Label.SMB_CL001_No_Partner_ID,
- SMB_Amount__c=0,SMB_Percentage__c=0,
- SMB_Primary__c=true);
- insert insertNoPartner;
- }
- //partner management evolution--END
- //assign a contact to a new opportunity
- if(conId!=null){
- OpportunityContactRole oppContact = new OpportunityContactRole(ContactId=conId,IsPrimary=true,
- OpportunityId=oppty.Id,Role=Label.Contact_Role);
- insert oppContact;
- }
- return oppty.Id;
- }
- catch(exception ex){
- if(!ex.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION'))
- Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.ERROR, 'Exception Error: ' + ex));
- return null;
- }
- }
- Error in $A.getCallback() ['state' is undefined]
- Callback failed: apex://NewOpportunityController/ACTION$getNewOppId
Add Comment
Please, Sign In to add comment