• samruddhi pode
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
What should i do to restrict users to select the date less than today's date?
Also there is a restriction of using any app in org. What is the solution for this kind of scenario?
Getting visualforce page error as List has no rows for assignment to SObject.  An unexpected error has occurred. Your development organization has been notified.
Here is my page controller.

Controller-
public class MyFirstController {


    private final Account account;

    public MyFirstController () {

        account = [SELECT Id, Name, Site FROM Account

                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

    }

 
    public Account getAccount() {

        return account;

    }

 
    public PageReference save() {

        update account;

        return null;

    }

}
 
My class:
/************************************
* Author: Techila Global Services
* Class/Trigger Name: GlobalApprovalPageExtension 
* Created Date: 10/18/2016
* Description: Updating the Status of Score to Regional Approved.
* Version: 1.0
************************************/



public with sharing class GlobalApprovalPageExtension {

    public GlobalApprovalPageExtension(ApexPages.StandardController controller) {

    }

      private ApexPages.StandardSetController standardController;
      public List<SCORE_Cost_Savings__c> ListSelectedScoreCost {get;set;} 
      public Integer TotalSubmittedValues {get;set;}
    
        public GlobalApprovalPageExtension(ApexPages.StandardSetController standardController) {
    
            this.standardController = standardController;
            ListSelectedScoreCost = new List<SCORE_Cost_Savings__c>();
            
           TotalSubmittedValues =  [SELECT count() FROM SCORE_Cost_Savings__c WHERE Status__c='Regional Approved'];
            
                system.debug('TotalSubmittedValues---------------->'+TotalSubmittedValues);
                
            List<SCORE_Cost_Savings__c> selectedSubmitted = new List<SCORE_Cost_Savings__c>();
            selectedSubmitted = (List<SCORE_Cost_Savings__c>) standardController.getSelected();
            SET<ID> SelectedID = new Set<ID>();
            system.debug('selectedSubmitted------------->'+selectedSubmitted);
            for(SCORE_Cost_Savings__c objScore:selectedSubmitted){
                        SelectedID.add(objScore.id);
            }
           
           ListSelectedScoreCost = [SELECT id,Name,Status__c FROM SCORE_Cost_Savings__c WHERE Status__c='Regional Approved' AND ID IN:SelectedID];
           
           if(ListSelectedScoreCost.size()==0){
           
               apexpages.addMessage(new Apexpages.Message(ApexPages.severity.Info, 'Kindly Select the Scores from List View'));
           } 
            
        }
        //This method is for Updating the Status of Score to Global Approved
        public void UpdateStatus(){
        
            try{
            
                   List<SCORE_Cost_Savings__c> ListUpdateStausScore = new List<SCORE_Cost_Savings__c>();
                   for(SCORE_Cost_Savings__c objScore:ListSelectedScoreCost){
                       objScore.Status__c = 'Global Approved';
                       ListUpdateStausScore.add(objScore);
                   } 
                  
                   if(ListUpdateStausScore.size()>0){
                   
                       Update ListUpdateStausScore;
                       apexpages.addMessage(new Apexpages.Message(ApexPages.severity.Confirm, 'Score Status Updated to Global Approved'));
    
                   }
         
            }catch(Exception e){
            
                apexpages.addMessage(new Apexpages.Message(ApexPages.severity.ERROR, 'Exception due to ----->'+e.getMessage()+e.getLineNumber()));
            }
     
        }
 
}


Test class:
/* ****************************************************************
* Author: Techila Global Services Pvt Ltd.
* Test Class Name: GlobalApprovalPageExtensionTest 
* Created Date: 19/10/2016
* Description: Test class for GlobalApprovalPageExtension. That is used for Updating the Status of Score to Regional Approved.
****************************************************************** */

@isTest
public class GlobalApprovalPageExtensionTest {
    
    //Global variables
    private static SCORE_Cost_Savings__c objSavings;
      public Integer TotalSubmittedValues;
   
    
    
    //test data setup method
    @testsetup public static void testData(){
    objSavings=new SCORE_Cost_Savings__c(Code__c='224883',
                                         Entry_Date__c=System.Today(),
                                         Score_Date__c=System.Today(),
                                         Event_Name__c='Test1',
                                         Event_Start__c=System.Today(),
                                         Negotiated_Cost_in_Local_Currency__c=800.00,
                                         Country__c='Africa',
                                         Currency_Type__c='AED',
                                         Description_of_Cost_Savings__c='This is test',
                                         Event_End__c=System.Today(),
                                         Starting_Cost_in_Local_Currency__c=1000.00,
                                         Status__c='Regional Approved');
        insert objSavings;
                                           
     }
     
       //First method to validate the Extension class to Update the Status of Score to Regional Approved.
    public static testmethod void validateGlobalApprovalPageExtensionOne(){
        testData();
        // Set Id of score cost saving to current page
         ApexPages.currentPage().getParameters().put('id',objSavings.Id);
        //Instance of class
         ApexPages.StandardSetController standardController;
        GlobalApprovalPageExtension objController=new GlobalApprovalPageExtension(new ApexPages.StandardController(objSavings));
       
       GlobalApprovalPageExtension objStdController=new GlobalApprovalPageExtension(standardController);

        objController.UpdateStatus();
        //objSavings.Status__c='Regional Approved';
        System.assertEquals('Global Approved',objSavings.Status__c); 
     }
     
      //Second method when Status of Score is not Update to  Regional Approved.
    public static testmethod void validateGlobalApprovalPageExtensionTwo(){
        testData();  
         // Set Id of score cost saving to current page
         //Instance of class
         GlobalApprovalPageExtension objController = new GlobalApprovalPageExtension(new ApexPages.StandardController(objSavings));
        objController.UpdateStatus();
         System.assertEquals('Regional Approved',objSavings.Status__c);  
      }
 }
Batch class:

public class MyBatchable implements Database.Batchable<SObject> {

    public Database.QueryLocator start(Database.BatchableContext context) {
        return Database.getQueryLocator([select Id from Account order by Name]);
    }

    public void execute(Database.BatchableContext context, List<Account> scope) {
        Account[] updates = new Account[] {};
        for (AggregateResult ar : [
                select AccountId a, count(Id) c
                from Contact
                where AccountId in :scope
                group by AccountId
                ]) {
            updates.add(new Account(
                    Id = (Id) ar.get('a'),
                    No_of_Contacts__c = (Decimal) ar.get('c')
                    ));
        }
                update updates;
               
              }
             
   public void finish(Database.BatchableContext context) {
   
           Account[] updates = new Account[] {};
     Database.SaveResult[] srList = Database.update(updates,false);
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  String[] toAddresses=new String[]{'123podesamruddhi@gmail.com'};
                for( Database.SaveResult r:srList)
                {
                if (r.isSuccess()) {
              
               
                 mail.setToAddresses(toAddresses);
                 mail.setSubject('Batch class run and field updated');
                 mail.setPlainTextBody('The field Number of contacts on object Account is updated successfully');
                // lstEmail.add(mail);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
                 }
                 else{
                 for(Database.Error re:r.getErrors())
                 {
                 system.debug(re);
                     mail.setToAddresses(toAddresses);
                     mail.setSubject('Batch class run but field not updated');
                        mail.setPlainTextBody('The field Number of contacts on object Account is failed to update');
                     Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});

                 }
                 }
    }
    }

}


What should i do?
<apex:page standardController="Employee__c" extensions="Chbox_ShowHide_Controller">

  <apex:form >
      <apex:pageBlock id="cpBlock" rendered="true" >
      <apex:pageBlockButtons >
          <apex:commandButton value="save" action="{!save}"/>
           <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
      
          <apex:pageBlockSection title="Personal Details" id="Block">
              <apex:inputField value="{!Employee__c.First_Name__c}"/>
              <apex:inputField value="{!Employee__c.Last_Name__c}"/>
              <apex:inputField value="{!Employee__c.DOB__c}"/>
              <apex:inputField value="{!Employee__c.Email__c}"/>
              <apex:inputField value="{!Employee__c.Address__c}"/>
          </apex:pageBlockSection>
               <apex:outputText value="Employed"/>
          <apex:inputCheckbox id="val" value="{!optSelected}" label="Employed"> 
                   <apex:actionSupport event="onchange" reRender="cpBlock" action="{!display}"/>
                </apex:inputCheckbox> 
         
                
            <apex:outputPanel id="r" rendered="{!optSelected }">
            <apex:pageBlockSection title="Employment Details" rendered="{!if(ShowHide==true,true,false)}">
              <apex:inputField value="{!Employee__c.Company_Name__c}"/>
              <apex:inputField value="{!Employee__c.Company_Address__c}"/>
              <apex:inputField value="{!Employee__c.Date_of_Joining__c}"/>
              <apex:inputField value="{!Employee__c.Notice_Period__c}"/>
              <apex:inputField value="{!Employee__c.Designation__c}"/>
              <apex:inputField value="{!Employee__c.Department__c}"/>
          </apex:pageBlockSection>
          </apex:outputPanel>
         
          <apex:outputPanel id="re">
           {!showHide}
          <apex:pageBlockSection title="Skill Sets" rendered="{!if(ShowHide==false,true,false)}">
              <apex:inputField value="{!Employee__c.Graduation__c}"/>
              <apex:inputField value="{!Employee__c.Post_Graduation__c}"/>
              <apex:inputField value="{!Employee__c.University__c}"/>
              <apex:inputField value="{!Employee__c.College_Name__c}"/>
              <apex:inputField value="{!Employee__c.Programming_Languages__c}"/>
          </apex:pageBlockSection>
          </apex:outputPanel>
      </apex:pageBlock>
  </apex:form>
</apex:page>

after saving record it do not get saved.
Hi All, 

I am having some issues with a list button that I want to create on the Opportunity object. Basically, I have a custom object that related to the standard opportunity object. My original goal was to query fields from the related Opportunity and Account object to auto-populate the custom "Escalations" object. 

I continue to get an error saying "invalid or unexpected token". At this point, I have continued to simplify the code to try and find the answer. I would be happy at this point, if someone could tell me the problem with the code below. (Which is much more simplified and doesn't even create anything, it just redirects the user to www.google.com). 
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var OppDetail = sforce.connection.query("SELECT id,Name,AccountId,Account.Name
from Opportunity WHERE id = '{!Opportunity.Id}' LIMIT 1");


var records = OppDetail.getArray("records"); 

var OppName = records[0].name;


if(OppName==null){alert ("PROBLEM")} 


else { 

window.location="www.google.com";
}

Any help would be greatly appreciated. For info purposes, my original code was: 

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var OppDetail = sforce.connection.query("SELECT id,Name,AccountId,Account.Name,
Expiring_Order_Total_del__c,Quote_Amount__c,
Account.Dont_Use_of_Customers_in_District_del__c,Account.Dont_Use_of_schools_in_disctrict_del__c from Opportunity WHERE id ='{!Opportunity.Id}' LIMIT 1");

var records = OppDetail.getArray("records"); 

var oppName = records[0].Name;
var oppid = records[0].id;
var AcctId = records[0].AccountId;
var AcctName = records[0].Account.Name;
var Ordertotal= records[0].Expiring_Order_Total_del__c;
var QuoteAmount= records[0].Quote_Amount__c;
var custindist = records[0].Account.Dont_Use_of_Customers_in_District_del__c;
var schoolsindist= records[0].Account.Dont_Use_of_schools_in_disctrict_del__c;


if(Name==null){alert ("PROBLEM")} 


else { 

window.location="/setup/ui/recordtypeselect.jsp?ent=01Ia00000026qDI&retURL=%2F"+Id+"& 
save_new_url=%2Fa0G%2Fe%3FCF00Na000000Arrzp="+name+
"&CF00Na000000Arrzp_lkid="+id+
"&CF00Na000000ArYAt="+AcctName+
"&CF00Na000000ArYAt_lkid="+AcctId+
"&00Na000000Ars4f="+custindist+
"&00Na000000ArYD9="+schoolsindist+
"&00Na000000ArYD4="+Ordertotal+
"&00Na000000Ars04="+QuoteAmount
}
<apex:page standardController="Employee__c" extensions="Chbox_ShowHide_Controller">

  <apex:form >
      <apex:pageBlock id="cpBlock" rendered="true" >
      <apex:pageBlockButtons >
          <apex:commandButton value="save" action="{!save}"/>
           <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
      
          <apex:pageBlockSection title="Personal Details" id="Block">
              <apex:inputField value="{!Employee__c.First_Name__c}"/>
              <apex:inputField value="{!Employee__c.Last_Name__c}"/>
              <apex:inputField value="{!Employee__c.DOB__c}"/>
              <apex:inputField value="{!Employee__c.Email__c}"/>
              <apex:inputField value="{!Employee__c.Address__c}"/>
          </apex:pageBlockSection>
               <apex:outputText value="Employed"/>
          <apex:inputCheckbox id="val" value="{!optSelected}" label="Employed"> 
                   <apex:actionSupport event="onchange" reRender="cpBlock" action="{!display}"/>
                </apex:inputCheckbox> 
         
                
            <apex:outputPanel id="r" rendered="{!optSelected }">
            <apex:pageBlockSection title="Employment Details" rendered="{!if(ShowHide==true,true,false)}">
              <apex:inputField value="{!Employee__c.Company_Name__c}"/>
              <apex:inputField value="{!Employee__c.Company_Address__c}"/>
              <apex:inputField value="{!Employee__c.Date_of_Joining__c}"/>
              <apex:inputField value="{!Employee__c.Notice_Period__c}"/>
              <apex:inputField value="{!Employee__c.Designation__c}"/>
              <apex:inputField value="{!Employee__c.Department__c}"/>
          </apex:pageBlockSection>
          </apex:outputPanel>
         
          <apex:outputPanel id="re">
           {!showHide}
          <apex:pageBlockSection title="Skill Sets" rendered="{!if(ShowHide==false,true,false)}">
              <apex:inputField value="{!Employee__c.Graduation__c}"/>
              <apex:inputField value="{!Employee__c.Post_Graduation__c}"/>
              <apex:inputField value="{!Employee__c.University__c}"/>
              <apex:inputField value="{!Employee__c.College_Name__c}"/>
              <apex:inputField value="{!Employee__c.Programming_Languages__c}"/>
          </apex:pageBlockSection>
          </apex:outputPanel>
      </apex:pageBlock>
  </apex:form>
</apex:page>

after saving record it do not get saved.