Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- This class contains Opportunity button actions
- 12.10.2018 - CR 00042620 - Circuit ID within manual creation cross connect details - DEPLOYED 12.10.2018
- 18.08.2015 - CR 00010393 - COF Changes - Manage default value for Stage/Sub-Stage - DEPLOYED 29.09.2015
- 12.08.2015 - CR 00009832 - Sales Support Workshop - 1.2 MSA defaults - DEPLOYED 23.09.2015
- 24.07.2015 - CR 00010389 - Opportunity date defaults - UK - DEPLOYED 27.07.2015
- 07.07.2015 - CR 00009845 - Change opp naming protocol - DEPLOYED 27.07.2015
- 02.06.2015 - CR 00009982 - Update Effective Contract Date and Close Date - upon creation UK - DEPLOYED
- 17.04.2015 - CR 00009276 - Default Opportunity Currency - DEPLOYED 27.07.2015
- 20.11.2014 - CR 00008191 - Generate Opportunity URL with default value. - DEPLOYED
- 02.06.2015 - CR 00009982 - Update Effective Contract Date and Close Date - upon creation UK - DEPLOYED
- **/
- public with sharing class OpportunityButtonActionsController{
- public Account acc {get;private set;}
- public Opportunity opp {get;set;}
- //Pull out Opportunity Record type info
- public static Map<Id,Schema.RecordTypeInfo> rtInfoMapById = Schema.SObjectType.Opportunity.getRecordTypeInfosById();
- public List<RecordType> availableRTs{get;private set;}
- public static Id cCRecTypeId = cache.RecordTypeId('Opportunity.Cross Connect Opportunity');
- public static Id cOFRecTypeId = cache.RecordTypeId('Opportunity.Customer Order Form Opportunity');
- public static Map<String,String> countryIsoCodeMapping = new Map<String,String>{'UK' => 'UK',
- 'Austria' => 'AT',
- 'Belgium' => 'BE',
- 'Denmark' => 'DK',
- 'France' => 'FR',
- 'Germany' => 'DE',
- 'Ireland' => 'IE',
- 'Netherlands' => 'NL',
- 'Spain' => 'ES',
- 'Sweden' => 'SE',
- 'Switzerland' => 'CH',
- 'UK' => 'UK',
- 'Science Park' => 'NL'};
- /**Getters**/
- public static String getDefaultSubStage(){
- return 'Qualify';
- }
- public static String getDefaultStageName(){
- return 'Qualification';
- }
- public static String getDefaultCampaignId(){
- return '701D00000004XQp';
- }
- public static String getRecordTypeParamURL(){
- return 'RecordType';
- }
- public static String getIXCountryParamURL(){
- return 'CF00ND0000003Cjyk';
- }
- public static String getSubStageParamURL(){
- return '00ND0000003CjzQ';
- }
- public static String getSvCountryParamURL(){
- return '00ND0000003CjzE';
- }
- public static String getSvSite(){
- return '00ND0000003CjzD';
- }
- public static String getOppCurrencyParamURL(){
- return 'opp16';
- }
- public static String getSvCampusParamURL(){
- return '00ND0000003CjzB';
- }
- public static String getOppNameParamURL(){
- return 'opp3';
- }
- public static String getOppClosedDateParamURL(){
- return 'opp9';
- }
- public static String getOppEffContractDateParamURL(){
- return '00ND00000042k4j';
- }
- public static String getCommencementDateParamURL(){
- return '00ND0000003CjyR';
- }
- public static String getSafetyDepositParamURL(){
- return '00ND00000041CeR';
- }
- public static String getCPIClauseParamURL (){
- return '00ND00000041CeS';
- }
- public static String getPowerUsagePriceClauseParamURL (){
- return '00ND00000041CeT';
- }
- public static String getServiceCreditLimitationParamURL (){
- return '00ND00000041CeU';
- }
- public static String getPaymentTermParamURL(){
- return '00ND00000041CeV';
- }
- //CR 00042620
- public static String getAccountCountryCode(){
- return '00N5700000686IG';
- }
- public OpportunityButtonActionsController(){
- this.opp = new Opportunity();
- this.opp.AccountId = ApexPages.currentPage().getParameters().get('accId');
- this.availableRTs = new List<RecordType>();
- }
- //Redirect users to the Opportunity creation page
- public PageReference goToNextPage(){
- if(this.opp.RecordTypeId !=null ){
- try{
- PageReference pageRef = new Pagereference('/006/e');
- pageRef.getParameters().put('retURL','/'+this.opp.AccountId);
- pageRef.getParameters().put('campid', getDefaultCampaignId());
- pageRef.getParameters().put('opp11',getDefaultStageName());
- pageRef.getParameters().put('save_new_url','/006/e?retURL='+this.opp.AccountId);
- pageRef.getParameters().put('ent','Opportunity');
- pageRef.getParameters().put(getRecordTypeParamURL(),this.opp.RecordTypeId);
- pageRef.getParameters().put(getSubStageParamURL(),getDefaultSubStage());
- //Start - CR 00010393 - default sub-stage
- if(Cache.RecordTypeId('Opportunity.Cross Connect Opportunity').contains(this.opp.RecordTypeId)
- || Cache.RecordTypeId('Opportunity.Customer Order Form Opportunity').contains(this.opp.RecordTypeId))
- pageRef.getParameters().put(getSubStageParamURL(),'Create Product Items');
- else
- pageRef.getParameters().put(getSubStageParamURL(),getDefaultSubStage());
- //End - CR 00010393 - default sub-stage
- List<Account> currentAccount = [SELECT Id,
- Name,
- Industry,
- Account_Country__c,
- ParentId, // CR 00009832
- CurrencyIsoCode
- FROM Account
- WHERE Id =:this.opp.AccountId LIMIT 1 ];
- //Start 00009832 G.B
- if(!currentAccount.isEmpty() && currentAccount.get(0).ParentId !=null){
- List<Apttus__APTS_Agreement__c> mSAAgreement = [Select Id,
- Finance_Security_Clause__c,
- CPI_Clause__c,
- Power_Usage_Price_Clause__c,
- Service_Credit_Limitation__c,
- Payment_Term__c
- FROM Apttus__APTS_Agreement__c
- WHERE Apttus__Status_Category__c = 'In Effect'
- AND Apttus__Account__c =:currentAccount.get(0).ParentId
- AND RecordTypeId =: Cache.RecordTypeId('Apttus__APTS_Agreement__c.Master Services Agreement')
- LIMIT 1];
- //Default Commercial Matrix
- if(!mSAAgreement.isEmpty()){
- //pageRef.getParameters().put('AgrmtId',mSAAgreement.get(0).Id);
- pageRef.getParameters().put(getSafetyDepositParamURL(),mSAAgreement.get(0).Finance_Security_Clause__c);
- pageRef.getParameters().put(getCPIClauseParamURL(),mSAAgreement.get(0).CPI_Clause__c);
- pageRef.getParameters().put(getPowerUsagePriceClauseParamURL (),mSAAgreement.get(0).Power_Usage_Price_Clause__c);
- pageRef.getParameters().put(getServiceCreditLimitationParamURL (),mSAAgreement.get(0).Service_Credit_Limitation__c);
- pageRef.getParameters().put(getPaymentTermParamURL(),mSAAgreement.get(0).Payment_Term__c);
- }
- }
- //End 00009832 G.B
- String accName = !currentAccount.isEmpty() ? currentAccount.get(0).Name:'';
- //Set account name
- pageRef.getParameters().put('opp4',accName);
- //Set account Id
- pageRef.getParameters().put('opp4_lkid',this.opp.AccountId);
- //Set Opportunity Currency - Start CR 00009276
- pageRef.getParameters().put(getOppCurrencyParamURL(),currentAccount.get(0).CurrencyIsoCode);
- // End CR 00009276
- //Pulls out current user IX country
- List<User> currentUser = [SELECT Country_IX__c,Profile.Name FROM User WHERE Id =:UserInfo.getUserId() LIMIT 1];
- String currentCountry = 'Netherlands';
- if(!currentAccount.isEmpty() && currentAccount.get(0).Account_Country__c != null && currentAccount.get(0).Account_Country__c != 'Unknown')
- currentCountry = currentAccount.get(0).Account_Country__c;
- else if(!currentUser.isEmpty() && currentUser.get(0).Country_IX__c != null && currentUser.get(0).Country_IX__c != 'HQ'){
- currentCountry = currentUser.get(0).Country_IX__c;
- }
- //Pull out Interxion entity details
- List<Account> interxionEntitySub = [SELECT Id,
- Name,
- Default_Service_Campus__c,
- Subsidiary_country__c,
- Default_Service_Site__c
- FROM Account
- WHERE Subsidiary_country__c =: currentCountry
- OR Default_IX_Subsidiary__c = true
- order by Default_IX_Subsidiary__c asc LIMIT 2];
- //Default Opportunity Name
- String oppName = '';
- //Pulls out the country 2 characters iso code
- String countryIsoCode = (currentCountry !=null && countryIsoCodeMapping.containsKey(currentCountry))?
- countryIsoCodeMapping.get(currentCountry): 'NL';
- // Account Country Code - CR 00042620
- pageRef.getParameters().put(getAccountCountryCode(),countryIsoCode);
- //Set Opp Commencement Date
- pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(1).format());
- //Set CC Opps
- if(String.valueOf(this.opp.RecordTypeId).contains(cCRecTypeId)){
- oppName = 'CC-'+ countryIsoCode + '-' + accName;
- //Set UK CC Commencement Date
- if(currentCountry == 'UK')
- // Start - CR 00009982 - G.B
- //pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(3).format());
- // End - CR 00009982 - G.B
- // Start - CR 00010389 - G.B
- pageRef.getParameters().put(getCommencementDateParamURL(),getCommencementDate('UK').format());
- // End - CR 00010389 - G.B
- }
- // Set COF Opps
- else if(String.valueOf(this.opp.RecordTypeId).contains(cOFRecTypeId)){
- oppName = 'COF-'+ countryIsoCode + '-' + accName;
- //Set UK COF Commencement Date
- if(currentCountry == 'UK')
- // Start - CR 00009982 - G.B
- //pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(3).format());
- // End - CR 00009982 - G.B
- // Start - CR 00010389 - G.B
- pageRef.getParameters().put(getCommencementDateParamURL(),Date.today().addMonths(1).format());
- // End - CR 00010389 - G.B
- }
- if(!interxionEntitySub.isEmpty()){
- //Set Opp Interxion Contracting Entity
- pageRef.getParameters().put(getIXCountryParamURL(),interxionEntitySub.get(0).Name);
- //Set Opp Service Country
- pageRef.getParameters().put(getSvCountryParamURL(),interxionEntitySub.get(0).Subsidiary_country__c);
- //Set Opp Service Campus
- pageRef.getParameters().put(getSvCampusParamURL(),interxionEntitySub.get(0).Default_Service_Campus__c);
- //Set Default name
- //CR 00009845 - G.B - 07.07.2015
- oppName = oppName == ''?accName +' - '+ interxionEntitySub.get(0).Default_Service_Site__c:oppName;
- //CR 00009845 - G.B - 07.07.2015
- //Set Opp Service Site
- pageRef.getParameters().put(getSvSite(),interxionEntitySub.get(0).Default_Service_Site__c);
- }
- //Start - CR 00009982 - G.B
- //Set Opp Closed Date
- if(currentCountry == 'UK'
- && String.valueOf(this.opp.RecordTypeId).contains(cOFRecTypeId)){
- // Start - CR 00010389
- pageRef.getParameters().put(getOppClosedDateParamURL(),Date.today().addMonths(1).format());
- //Set Opp Effective Contract Date
- pageRef.getParameters().put(getOppEffContractDateParamURL(),Date.today().addMonths(1).format());
- //End - CR 00010389
- }else if(currentCountry == 'UK'
- && String.valueOf(this.opp.RecordTypeId).contains(cCRecTypeId)){
- // Start - CR 00010389
- pageRef.getParameters().put(getOppClosedDateParamURL(),Date.today().format());
- //Set Opp Effective Contract Date
- pageRef.getParameters().put(getOppEffContractDateParamURL(),Date.today().format());
- //End - CR 00010389
- }else{
- pageRef.getParameters().put(getOppClosedDateParamURL(),Date.today().format());
- //Set Opp Effective Contract Date
- pageRef.getParameters().put(getOppEffContractDateParamURL(),Date.today().format());
- }
- //End - CR 00009982 - G.B
- if(oppName!=null && oppName!='')
- //Set Opp Name
- pageRef.getParameters().put(getOppNameParamURL(),oppName);
- return pageRef.setRedirect(true);
- }catch (Exception e){
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage()));
- return null;
- }
- }else{
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Missing URL Parameter'));
- return null;
- }
- return null;
- }
- //Go back to the related account
- public PageReference goToCancel(){
- return new PageReference ('/'+this.opp.AccountId);
- }
- //Load list of RT
- public PageReference loadOppAvailableRTTypes(){
- //Populate available Recordt Type info based on user access
- for(RecordType rt:[SELECT Id,Name,Description FROM RecordType WHERE SobjectType = 'Opportunity']){
- if(rtInfoMapById !=null && rtInfoMapById.containsKey(rt.Id) && rtInfoMapById.get(rt.Id).isAvailable())
- availableRTs.add(rt);
- }
- //User has acces to only one RT
- if(availableRTs.size() == 1){
- this.opp.RecordTypeId = availableRTs.get(0).Id;
- return goToNextPage();
- }
- return null;
- }
- //Calcluate Commencement Date(today + SLA (10 working days))
- private Date getCommencementDate(String country){
- return Utility.getBusinessEndDate(Date.today(),3,country);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement