• Maxim Nikitin
  • NEWBIE
  • 35 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 4
    Replies
Dear All, I`m new to Apex and I`m stuck with this issue. I have a standardcontroller and below extension. What I want to do is override the standard Save button with save() method so that it redirects me to the Opportunity view page. Save works fine but it doesnt throw any error. It directly save the page. Can someone pls help? 
Thanks!
 
public with sharing class myclass {

    String oppId;
    String ownerId;
    private Opportunity Oppty;
 
    public myclass(ApexPages.StandardController stdController) {
        oppId = stdController.getId();
        Oppty = (Opportunity) stdController.getRecord();
        ownerId = oppty.OwnerId;
        oppty.StageName = 'Identified Opportunity';
         oppty.Probability = 0;
    }



public transient Map<String, Decimal> probabilityStageNameMap;

public PageReference changeStageName() {

if (probabilityStageNameMap == null) {
 probabilityStageNameMap = new Map<String, Decimal>();
for (OpportunityStage oppStage : [Select MasterLabel, DefaultProbability
                                    From OpportunityStage]) {
 probabilityStageNameMap.put(oppStage.MasterLabel, oppStage.DefaultProbability);
   }
  }

 if (probabilityStageNameMap.containsKey(Oppty.StageName)) {
   Oppty.Probability = probabilityStageNameMap.get(Oppty.StageName);
 
 }

  return null;
 }
 
  public PageReference doSave()
  {
  
      if (Oppty.LeadSource == 'Marketing Campaign' && Oppty.CampaignId == null )
      {
        system.debug('I m in'); 
        oppty.addError('Please select the Marketing Campaign which influenced this opportunity.');
          //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Error !!!'));    
      }
      
      if(oppty.Program_Length_in_months__c == 0){
          oppty.addError('The Contract Length Cant be "0".');
      }
      
      if(oppty.StageName != 'Awarded Business' &&  oppty.Probability > 99){
          oppty.addError('Probability of pipeline Opportunity cannot be 100%');
      }
      
      if(oppty.IsClosed != True  &&  oppty.Probability == 0){
          oppty.addError('The Probability of an Active opportunity cant be 0%');
      }
      
      
     upsert oppty;
     pagereference page=new pagereference('/apex/TPDynamicOppNEWLayout?id=' + oppty.id);
      return null;
  }
  
     public PageReference Save()
  {
  
      if (Oppty.LeadSource == 'Marketing Campaign' && Oppty.CampaignId == null )
      {
        system.debug('I m in'); 
        oppty.addError('Please select the Marketing Campaign which influenced this opportunity.');
          //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Error !!!'));    
      }
      
      if(oppty.Program_Length_in_months__c == 0){
          oppty.addError('The Contract Length Cant be "0".');
      }
      
      if(oppty.StageName != 'Awarded Business' &&  oppty.Probability > 99){
          oppty.addError('Probability of pipeline Opportunity cannot be 100%');
      }
      
      if(oppty.IsClosed != True  &&  oppty.Probability == 0){
          oppty.addError('The Probability of an Active opportunity cant be 0%');
      }
      
      
     upsert oppty;
     pagereference page2 =new pagereference('/' + oppty.id);
      return page2 ;
  }
  
}

 
Hi All,
Please help me

Have anybody idea how to create process that will start at the specified time.
I have a task to do some actions(send email notification to customer and other). It 
should occur 24/48 hours after some event. 

Are there any way to do this?

Cheers,
Max
Hi All,
Please help me

Have anybody idea how to create process that will start at the specified time.
I have a task to do some actions(send email notification to customer and other). It 
should occur 24/48 hours after some event. 

Are there any way to do this?

Cheers,
Max
Dear All, I`m new to Apex and I`m stuck with this issue. I have a standardcontroller and below extension. What I want to do is override the standard Save button with save() method so that it redirects me to the Opportunity view page. Save works fine but it doesnt throw any error. It directly save the page. Can someone pls help? 
Thanks!
 
public with sharing class myclass {

    String oppId;
    String ownerId;
    private Opportunity Oppty;
 
    public myclass(ApexPages.StandardController stdController) {
        oppId = stdController.getId();
        Oppty = (Opportunity) stdController.getRecord();
        ownerId = oppty.OwnerId;
        oppty.StageName = 'Identified Opportunity';
         oppty.Probability = 0;
    }



public transient Map<String, Decimal> probabilityStageNameMap;

public PageReference changeStageName() {

if (probabilityStageNameMap == null) {
 probabilityStageNameMap = new Map<String, Decimal>();
for (OpportunityStage oppStage : [Select MasterLabel, DefaultProbability
                                    From OpportunityStage]) {
 probabilityStageNameMap.put(oppStage.MasterLabel, oppStage.DefaultProbability);
   }
  }

 if (probabilityStageNameMap.containsKey(Oppty.StageName)) {
   Oppty.Probability = probabilityStageNameMap.get(Oppty.StageName);
 
 }

  return null;
 }
 
  public PageReference doSave()
  {
  
      if (Oppty.LeadSource == 'Marketing Campaign' && Oppty.CampaignId == null )
      {
        system.debug('I m in'); 
        oppty.addError('Please select the Marketing Campaign which influenced this opportunity.');
          //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Error !!!'));    
      }
      
      if(oppty.Program_Length_in_months__c == 0){
          oppty.addError('The Contract Length Cant be "0".');
      }
      
      if(oppty.StageName != 'Awarded Business' &&  oppty.Probability > 99){
          oppty.addError('Probability of pipeline Opportunity cannot be 100%');
      }
      
      if(oppty.IsClosed != True  &&  oppty.Probability == 0){
          oppty.addError('The Probability of an Active opportunity cant be 0%');
      }
      
      
     upsert oppty;
     pagereference page=new pagereference('/apex/TPDynamicOppNEWLayout?id=' + oppty.id);
      return null;
  }
  
     public PageReference Save()
  {
  
      if (Oppty.LeadSource == 'Marketing Campaign' && Oppty.CampaignId == null )
      {
        system.debug('I m in'); 
        oppty.addError('Please select the Marketing Campaign which influenced this opportunity.');
          //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Error !!!'));    
      }
      
      if(oppty.Program_Length_in_months__c == 0){
          oppty.addError('The Contract Length Cant be "0".');
      }
      
      if(oppty.StageName != 'Awarded Business' &&  oppty.Probability > 99){
          oppty.addError('Probability of pipeline Opportunity cannot be 100%');
      }
      
      if(oppty.IsClosed != True  &&  oppty.Probability == 0){
          oppty.addError('The Probability of an Active opportunity cant be 0%');
      }
      
      
     upsert oppty;
     pagereference page2 =new pagereference('/' + oppty.id);
      return page2 ;
  }
  
}

 
Dear All, I`m new to Apex and I`m stuck with this issue. I have a standardcontroller and below extension. What I want to do is override the standard Save button with save() method so that it redirects me to the Opportunity view page. Save works fine but it doesnt throw any error. It directly save the page. Can someone pls help? 
Thanks!
 
public with sharing class myclass {

    String oppId;
    String ownerId;
    private Opportunity Oppty;
 
    public myclass(ApexPages.StandardController stdController) {
        oppId = stdController.getId();
        Oppty = (Opportunity) stdController.getRecord();
        ownerId = oppty.OwnerId;
        oppty.StageName = 'Identified Opportunity';
         oppty.Probability = 0;
    }



public transient Map<String, Decimal> probabilityStageNameMap;

public PageReference changeStageName() {

if (probabilityStageNameMap == null) {
 probabilityStageNameMap = new Map<String, Decimal>();
for (OpportunityStage oppStage : [Select MasterLabel, DefaultProbability
                                    From OpportunityStage]) {
 probabilityStageNameMap.put(oppStage.MasterLabel, oppStage.DefaultProbability);
   }
  }

 if (probabilityStageNameMap.containsKey(Oppty.StageName)) {
   Oppty.Probability = probabilityStageNameMap.get(Oppty.StageName);
 
 }

  return null;
 }
 
  public PageReference doSave()
  {
  
      if (Oppty.LeadSource == 'Marketing Campaign' && Oppty.CampaignId == null )
      {
        system.debug('I m in'); 
        oppty.addError('Please select the Marketing Campaign which influenced this opportunity.');
          //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Error !!!'));    
      }
      
      if(oppty.Program_Length_in_months__c == 0){
          oppty.addError('The Contract Length Cant be "0".');
      }
      
      if(oppty.StageName != 'Awarded Business' &&  oppty.Probability > 99){
          oppty.addError('Probability of pipeline Opportunity cannot be 100%');
      }
      
      if(oppty.IsClosed != True  &&  oppty.Probability == 0){
          oppty.addError('The Probability of an Active opportunity cant be 0%');
      }
      
      
     upsert oppty;
     pagereference page=new pagereference('/apex/TPDynamicOppNEWLayout?id=' + oppty.id);
      return null;
  }
  
     public PageReference Save()
  {
  
      if (Oppty.LeadSource == 'Marketing Campaign' && Oppty.CampaignId == null )
      {
        system.debug('I m in'); 
        oppty.addError('Please select the Marketing Campaign which influenced this opportunity.');
          //ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Error !!!'));    
      }
      
      if(oppty.Program_Length_in_months__c == 0){
          oppty.addError('The Contract Length Cant be "0".');
      }
      
      if(oppty.StageName != 'Awarded Business' &&  oppty.Probability > 99){
          oppty.addError('Probability of pipeline Opportunity cannot be 100%');
      }
      
      if(oppty.IsClosed != True  &&  oppty.Probability == 0){
          oppty.addError('The Probability of an Active opportunity cant be 0%');
      }
      
      
     upsert oppty;
     pagereference page2 =new pagereference('/' + oppty.id);
      return page2 ;
  }
  
}