• amruta_dhumal
  • NEWBIE
  • 55 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 18
    Replies

Hi There,

 

While doing deployment,I got an error.

here is my trigger code:

 

 

trigger FrameworkOptyTrigger on Opportunity(after delete, after insert,after update) {
Opportunity[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of opty
Set<ID> optyIds = new Set<ID>();

for (Opportunity con : cons) {
optyIds.add(con.Framework_Agreement__c);
}
try{

List<Opportunity> childopty= new List<Opportunity>([select Id,Framework_Agreement__c from Opportunity where Framework_Agreement__c in :optyIds]);

List<Opportunity> parentToUpdate= new List<Opportunity>([select Id,Number_of_Opportunities__c,Total_Sales__c,Total_Opportunity_Sum__c from Opportunity where Id in :optyIds]);

//Use aggregate soql to get total sum of all opportunity
AggregateResult[] groupedResults=[select Framework_Agreement__c ,sum(Amount)fm from Opportunity where Framework_Agreement__c in :optyIds group by Framework_Agreement__c];

//Use aggregate soql to get total sum of all Won opportunity

AggregateResult[] groupedResults1=[select Framework_Agreement__c ,sum(Amount)ar from Opportunity where Framework_Agreement__c in :optyIds and StageName='Closed Won' group by Framework_Agreement__c];

for (Opportunity o: parentToUpdate) {
Set<ID> opId= new Set<ID>();
for (Opportunity con : childopty) {
if (con.Framework_Agreement__c== o.Id)
opId.add(con.Id);
}

if (o.Number_of_Opportunities__c != opId.size())
o.Number_of_Opportunities__c = opId.size();

for(integer i=0;i<groupedResults.size();i++){
o.Total_Opportunity_Sum__c =(Decimal)groupedResults[i].get('fm');}

for(integer j=0;j<groupedResults1.size();j++){
o.Total_Sales__c = (Decimal)groupedResults1[j].get('ar');}
}

//update parent opportunity
update parentToUpdate;
}catch(Exception e){}

}

 

getting error on line :- List<Opportunity> childopty= new List<Opportunity>([select Id,Framework_Agreement__c from Opportunity where Framework_Agreement__c in :optyIds]);

 

any help would be appreciated,I've to deploy it on prod in urgent basis.

 

Amruta

 

 

Hi

 

I've Account & opty object.opty shared 22 recordtypes.when opty recordtype status is 'xxx' then it's updating Account field value to 'xxx' through trigger.

 

Now when I change recordtype to another [thru Change Link option beside recordtype] then it should set 'None' value on previous recordtype related Acct field.

 

Any suggestions how this can be achievable?

 

Amruta

Hi

 

I've one wf rule,and also written trigger on after insert,after update event.Now I am worrying about when this wf rule execute ,it will update status field of custom object and purpose of trigger is when any status changes of that custom object,then update the status field for another object.

 

 

Amruta

Hi

 

I want to write code for SUM() of all opportunity and SUM() of all WON opty.

 

here is my code but getting error:

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

 

trigger OptyTrigger on Opportunity(after delete, after insert, after undelete,after update) {
Opportunity[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of opty
Set<ID> acctIds = new Set<ID>();
for (Opportunity con : cons) {
acctIds.add(con.Framework_Agreement__c);
}

Map<ID, Opportunity> contactsForAccounts = new Map<ID, Opportunity>([select Id
,Framework_Agreement__c
from Opportunity
where Framework_Agreement__c in :acctIds]);

Map<ID, Opportunity> acctsToUpdate = new Map<ID, Opportunity>([select Id
,Number_of_Opportunities__c
from Opportunity
where Id in :acctIds]);

for (Opportunity acct : acctsToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Opportunity con : contactsForAccounts.values()) {
if (con.Framework_Agreement__c== acct.Id)
conIds.add(con.Id);
}
if (acct.Number_of_Opportunities__c != conIds.size())
acct.Number_of_Opportunities__c = conIds.size();
}

update acctsToUpdate.values();


LIST<AggregateResult> ChildCMRRList = [select Framework_Agreement__c fm,sum(Amount)childsum
from Opportunity where Framework_Agreement__c in :acctIds group by Framework_Agreement__c];
System.debug('ChildCMRR: ' + ChildCMRRList );

list<Opportunity> AccToUpdate = new list<Opportunity >();
for(AggregateResult ChildCMRR : ChildCMRRList){
ID Opportunity = (ID)ChildCMRR.get('fm');
Opportunity acc = new Opportunity (ID = Opportunity);

Decimal D = (Decimal)ChildCMRR.get('childsum');
acc.Total_Opportunity_Sum__c = D;

AccToUpdate.add(acc);
}
if(!AccToUpdate.isEmpty())
update AccToUpdate;

}

 

 

pls help how to resolve this.

 

Amruta

 

Hi There,

 

My req. is,I've Account obj as a master and Contract(custom obj)as detail.I've created 2 custom fields on Account eg.Asset Management Calculated Status,Built Environment Calculated Status with picklist values 'Customer' and 'Ex-Customer'.and Contract have 2 recordtypes say,'Asset Management','Built Environment'.Now whenever user select Contract recordtype as 'Asset Management' with Status 'Active' then it's corresponding Account 'Asset Management Calculated Status' field should get updated as 'Customer' value. and in other case, if user select Status as 'Terminated' then it's corresponding Account 'Asset Management Calculated Status' field should be updated as 'Ex-Customer'.

 

Business wants to write trigger on Contract and call apex class from there and class will hold all the logic......

 

plus I've to use custom setting for this scenario.in future if more Contract recordtype added then no need to touch code it should run dynamically......here are details:

 

Created custom setting named Record Maping added 2 custom fields and thru manage button inserted 2 records.

Custom Setting : Record Mapping

 

Record Type Name: Asset Management

Field Name :Asset Management Calculated Status

 

Record Type Name: Built Environment

Field Name :Built Environment Calculated Status

 

here is my code:

Trigger:

trigger ContractUpdate on MITIE_Contract__c (after insert,after update) {


// Creating an object named 'obj' of class "AccountUpdate"
    AccountUpdate obj = new AccountUpdate();
    system.debug('object calling 1');
  // Calling the 'CheckCondition' function of class "AccountUpdate"
    obj.CheckCondition(Trigger.new);
}

Class:

 

Public with sharing class AccountUpdate{


List<ID> accid= New List<ID>();

public void CheckCondition(MITIE_Contract__c[] m){

List<Record_Mapping__c> mcs = Record_Mapping__c.getAll().values();
system.debug('mcs..'+mcs);


//For Asset Management recordtpe on Contract
for(integer j=0;j<mcs.size();j++){
if(m[0].Status__c =='Active' && mcs[j].RecordType_Name__c=='Asset Management' &&m[0].Organisation_Name__c != null){

accid.add(m[0].Organisation_Name__c);
List<Account> oppList = [SELECT id, Asset_Management_Calculated_Status__c FROM Account WHERE id in :accid]; 

for(integer i = 0 ; i < oppList.size(); i++){
oppList[i].Asset_Management_Calculated_Status__c ='Customer';
}
update oppList;


}
}

 

 

Amruta

 

Hi There,

 

I am new to custom settings concept, I've created 1 custom setting with 3 custom fields and added 22 records.

Now I've to write trigger which will call apex class and thru class Account object custom fields should be updated.

 

I've to use custom settings in my class to run in dynamic manner

 

Require suggetions here how to use custom setting in apex class and how to implement.

 

 

Amruta

Hi There,

 

I'm only getting 42% code coverage with error msg :

 

System.NullPointerException: Attempt to de-reference a null object.

Class.PrewiredSearch.runSearch: line 282, column 1 Class.PrewiredSearch.Beginning: line 472, column 1 Class.testSearch.testSearch: line 71, column 1

 

Any advise?

 

Class:

 

public with sharing class PrewiredSearch{
private ApexPages.StandardController controller;
public String retURL {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}
public String cancelURL {get; set;}
public String ent {get; set;}
public String confirmationToken {get; set;}
String recordId;
String oppName;
public String accntName {get; set;}

 private integer counter=0;  //keeps track of the offset
   private integer list_size=20; //sets the page size or number of rows
   public integer total_size; //used to show user the total size of the list

String country1 = null;
Public String selection = '';
public Boolean shouldRender= false;
  private String soqlWhereClause {get;set;}

public String country {get; set;}

  public List<Site_Address__c> sites{get;set;}
  public Site_Address__c site{get;set;}

  Public String province {get; set;}
  Public String city {get; set;}
  Public String street {get; set;}
  Public String suburb {get; set;}
   Public Boolean flagNoRecordFound  {get; set;}
   Public Boolean flagNoApplicable {get; set;}


 public PrewiredSearch(ApexPages.StandardController  controller) {
 ///this.controller = controller;
  this.site= (Site_Address__c)controller.getRecord();

 recordId=ApexPages.currentPage().getParameters().get('Id');
 oppName=ApexPages.currentPage().getParameters().get('Name');
retURL = ApexPages.currentPage().getParameters().get('retURL');
rType = ApexPages.currentPage().getParameters().get('RecordType');
 cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');
ent = ApexPages.currentPage().getParameters().get('ent');
confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
accntName = ApexPages.currentPage().getParameters().get('CF00N20000002wMtX'); //lkid
system.debug('accntName :'+accntName );
       soql = 'select Country_Name__c, id,Name,Province__c, Pre_Wired_Site_Name__c,Pre_Wired_Site_Name__r.Name,City_Name__c,ignoredhidden__c,Ignored_Records__c, Street_Name__c,Suburb_Name__c from Site_Address__c where Establishment_Type__c in(\'Pre-Ducted Building\',\'Pre-Wired Building\')';
       soql += ' and Country_Name__c LIKE \'%South Africa%\'';       
       soqlWhereClause =' Country_Name__c LIKE \'%South Africa%\'';       
       runQuery();

 flagNoRecordFound=false;
flagNoApplicable =true;
    }
   public boolean getShouldRender() {
return shouldRender;
}

public void setBoolean(Boolean shouldRender) {
this.shouldRender= shouldRender;
}

 public boolean getFlagNoRecordFound() {

return this.flagNoRecordFound;
}

public void setFlagNoRecordFound(Boolean flagNoRecordFound) {
this.flagNoRecordFound= flagNoRecordFound;
}

 public boolean getFlagNoApplicable() {
return this.flagNoApplicable;
}

public void setFlagNoApplicable(Boolean flagNoApplicable) {
this.flagNoApplicable= flagNoApplicable;
}

 public String getString() {
return selection ;
}

public void setString(String selection ) {
this.selection = selection ;
}

public void Disable() {

if (selection.equals('Select')) {
shouldRender= true;
} else {
shouldRender= false;
}
}

PageReference pageRef ;
    private String soql {get;set;}
 

public PageReference redirect(){
PageReference pageRef ;
PageReference returnURL ;
 if(rType=='01220000000JJaz') {
 
            if ((accntName==null)){ 
           
 
              returnURL = new PageReference('/apex/PrewiredSearchVFPage');
             
              }
           else      
           {
             returnURL = new PageReference('/apex/PrewiredSearchVFPage?CF00N20000002wMtX='+accntName+'');

             }
            returnURL.setRedirect(true);
      }      
      return returnURL;
      If(rType=='012P00000000Hcj'){
  returnURL = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk');
   returnURL.setRedirect(true);
  
  }return returnURL;
 if(rType=='012P00000000HrW'){
  returnURL = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk');
   returnURL.setRedirect(true);
  
  }return returnURL;
  if(rType=='01220000000JJb4'){
  returnURL = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk');
   returnURL.setRedirect(true);
  
  }
  return returnURL;
  }
   public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
  public String sortField {
    get  { if (sortField == null) {sortField = 'Pre_Wired_Site_Name__c'; } return sortField;  }
    set;
  }
   public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
    public PrewiredSearch() {
   
  }
   public void toggleSort() {
        sortDir = sortDir.equals // run the query again
    runQuery();
  }
 List<Site_Address__c> totalSiteAddr{get;set;}

     public void runQuery() {
     try {
    String soqlTot='select id from Site_Address__c where '+ soqlWhereClause ;
     System.debug('soqlTot:'+ soqlTot);

    totalSiteAddr =Database.query(soqlTot); //[select id  from Site_Address__c where  soqlWhereClause];
     total_size=totalSiteAddr.size();
     sites= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit :list_size  offset :counter');
               System.debug('sites :'+sites.size()+' ::counter :'+counter +':: total_size :'+total_size);
                         If (sites.isEmpty())
         {
         flagNoRecordFound=true;
           flagNoApplicable=false;
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Pre-Wired Name not found  or the search does not contain any name,Please select No Records Found Section'));
   
        }
        else
           {
              flagNoRecordFound=false;
              flagNoApplicable=true;
        }
   } catch (NullPointerException npe) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Pre-Wired Name not found  or the search does not contain any name'));
    }
   
    catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops! Please try your search again'));
    }
 
 }
     public PageReference runSearch() {
  
     
     String suburb= Apexpages.currentPage().getParameters().get('suburb');
    String street= Apexpages.currentPage().getParameters().get('street');
    
    soql = 'select Country_Name__c, id,Name,Province__c, Pre_Wired_Site_Name__c,Pre_Wired_Site_Name__r.Name,City_Name__c,ignoredhidden__c,Ignored_Records__c, Street_Name__c,Suburb_Name__c from Site_Address__c where Establishment_Type__c in(\'Pre-Ducted Building\',\'Pre-Wired Building\')';
   
    if (site.Country_Name__c!=null) 
    { 
      if(site.Country_Name__c.length() > 0)
      {
           soql += ' and Country_Name__c LIKE \'%'+ String.escapeSingleQuotes(site.Country_Name__c)+'%\'';
           }
       
       if (site.Province__c!=null ) 
        if(site.Province__c.length() > 0) 
        {
           soql += ' and Province__c LIKE \'%'+ String.escapeSingleQuotes(site.Province__c)+'%\'';
         
          soqlWhereClause  +=' and Province__c LIKE \'%'+ String.escapeSingleQuotes(site.Province__c)+'%\'';


                   }
          
       if (site.City_Name__c!=null)
         if(site.City_Name__c.length() > 0)    {
           soql += ' and City_Name__c LIKE \'%'+String.escapeSingleQuotes(site.City_Name__c)+'%\'';
            soqlWhereClause  += ' and City_Name__c LIKE \'%'+String.escapeSingleQuotes(site.City_Name__c)+'%\'';

          
          
           }
          
        if (street!=null)   
         if(street.length() > 0)  
         {
           soql += ' and Street_Name__c LIKE \'%'+String.escapeSingleQuotes(street)+'%\'';
             soqlWhereClause  += ' and Street_Name__c LIKE \'%'+String.escapeSingleQuotes(street)+'%\'';

           }
          
        if (suburb!=null)  
           if(suburb.length() > 0) 
           {  
           soql += ' and Suburb_Name__c LIKE \'%'+String.escapeSingleQuotes(suburb)+'%\'';
            soqlWhereClause  += ' and Suburb_Name__c LIKE \'%'+String.escapeSingleQuotes(suburb)+'%\'';

          
           }


       runQuery();
   }
  else
  {
       soql += ' and Country_Name__c LIKE \'%'+String.escapeSingleQuotes('null')+'%\''; 
  
   runQuery();
  }
     return null;
  }
 

 public PageReference Clickhere(){
if(accntName==null)
  pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00NW0000000ILAe=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c+'');
else
   pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00NW0000000ILAe=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c +'&CF00N20000002wMtX='+accntName);
  
    PageRef.setRedirect(true);
   PageRef.getParameters().put('nooverride', '1');
       

Return PageRef;
  }
public PageReference Clickhere1(){
       if(accntName==null)
          pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c );
     else    
       pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c +'&CF00N20000002wMtX='+accntName);

   PageRef.setRedirect(true);
   PageRef.getParameters().put('nooverride', '1');
       

Return PageRef;
  }
 public PageReference cancel() {
          PageReference pr = new PageReference('a0v/o');
          pr.setRedirect(true);
          return pr;
     }
    
 public PageReference test() {
 
      String siteId= Apexpages.currentPage().getParameters().get('siteId');
         return null;
    }
    public PageReference runSearch2() {
 PageReference pageRef ;
     String siteId= Apexpages.currentPage().getParameters().get('siteId');
      String street= Apexpages.currentPage().getParameters().get('street');
       String suburb= Apexpages.currentPage().getParameters().get('suburb');
     List<Site_Address__c> site = [select Country_Name__c,Name, id,Province__c, Pre_Wired_Site_Name__c,Pre_Wired_Site_Name__r.Name,City_Name__c,ignoredhidden__c,Ignored_Records__c, Street_Name__c,Suburb_Name__c from Site_Address__c where id=:siteId ];
        for(Site_Address__c siteObj : site )    
             { 
             
                 if ((suburb!='') && (street=='')){
         system.debug('inside runSearch2');
          if(accntName==null)
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF000N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuL='+suburb+'&00NW0000000ILAj=No');
          else
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&CF00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuL='+suburb+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');
       
         PageRef.setRedirect(true);
         PageRef.getParameters().put('nooverride', '1');
   }
   else if ((suburb=='') && (street!='')){
         system.debug('inside runSearch2');
          if(accntName==null)
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&00NW0000000ILAj=No');       
           else
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');

         PageRef.setRedirect(true);
         PageRef.getParameters().put('nooverride', '1');
   }
   else if ((suburb!='') && (street!='')){
         system.debug('inside runSearch2');
            if(accntName==null)
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&00N20000002wMuL='+suburb+'&00NW0000000ILAj=No');
        else
         pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&00N20000002wMuL='+suburb+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');
       
         PageRef.setRedirect(true);
         PageRef.getParameters().put('nooverride', '1');
   }
    else{        
         if(accntName==null)
                pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00NW0000000ILAj=No');
          else
          pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');

         
        PageRef.setRedirect(true);
   PageRef.getParameters().put('nooverride', '1');
        }
                                    
        }
        return pageRef ;

        }

        public void StatesSelectList() {
String country= Apexpages.currentPage().getParameters().get('country');
  }
       public PageReference Beginning() { //user clicked beginning
      counter = 0;
      runSearch();
      return null;
   }

   public PageReference Previous() { //user clicked previous button
      counter -= list_size;
            runSearch();
      return null;
   }

   public PageReference Next() { //user clicked next button
      counter += list_size;
            runSearch();
      return null;
   }

   public PageReference End() { //user clicked end
      counter = total_size - math.mod(total_size, list_size);
            runSearch();
      return null;
   }

   public Boolean getDisablePrevious() { 
           if (counter>0) return false; else return true;
   }

   public Boolean getDisableNext() { //this will disable the next and end buttons
      if (counter + list_size < total_size) return false; else return true;
   }

   public Integer getTotal_size() {
   System.debug('total_size:'+total_size);
      return total_size;
   }

   public Integer getPageNumber() {
      return counter/list_size + 1;
   }

   public Integer getTotalPages() {
   System.debug('total_size:'+total_size  +':: list_size :'+list_size );

      if (math.mod(total_size, list_size) > 0) {
         return total_size/list_size + 1;
      } else {
         return (total_size/list_size);
      }
   }

   }

 

 

 

 

Amruta

 

Hi

 

My req. is based on Quantity field ,Additional SIP Channels Quantity field should always be in ratio of 1:3. can anyone help me on this how to achieve this using validation rule?

 

Amruta Dhumal

Hi There,

 

I want to know how to take a sandbox backup before it get refreshed.

 

Amruta

Hi There,

 

I've a req. like based on opportunity level if Product Type field is 'ABC' then it's corresponding product manager,i.e.manager of that 'ABC' Product should get notification for approval.

 

is there any approach for this??

 

Amruta

Hi

 

Is there any version control functionality in sfdc??

 

Amruta

Hi

 

I want to redirect vf page values to particular object's edit layout fields. and on edit layout user should not be able to edit/change any of the fields which are auto-populate from vf page.

 

How I can restrict user for this..is it possible?any help would be appreciated...

 

Amruta

 

I developed this code:

 

VF page:

<apex:page standardController="Contact" extensions="ContactSearchController1" showHeader="false">
 
 <script>var cId = "{!Contact.Id}";</script>
   <apex:form >
  <apex:pageMessages id="errors" />
 
  <apex:pageBlock title="Find A Pre-Wired Site Address!" mode="edit">
 
  <table width="100%" border="0">
  <tr> 
    <td width="300" valign="top">
 
      <apex:pageBlock title="Parameters" mode="edit" id="criteria">
 
      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("firstName").value,
          document.getElementById("lastName").value,
          document.getElementById("accountName").value,
          document.getElementById("technology").options[document.getElementById("technology").selectedIndex].value
          );
      }
      </script>
 
      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="firstName" value="" />
          <apex:param name="lastName" value="" />
          <apex:param name="accountName" value="" />
          <apex:param name="technology" value="" />
      </apex:actionFunction>
 
      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">First Name<br/>
        <input type="text" id="firstName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Last Name<br/>
        <input type="text" id="lastName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;"><font color ="red">Account</font><br/>
        <input type="text" id="accountName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Interested Technologies<br/>
          <select id="technology" onchange="doSearch();">
            <option value=""></option>
            <apex:repeat value="{!technologies}" var="tech">
              <option value="{!tech}">{!tech}</option>
            </apex:repeat>
          </select>
        </td>
      </tr>
      </table>
 
      </apex:pageBlock>
 
    </td>
    <td valign="top">
 
    <apex:pageBlock mode="edit" id="results">
 
        <apex:pageBlockTable value="{!contacts}" var="contact">
 
        <apex:column headerValue="Action">
        <apex:commandLink action="{!next}"> Select</apex:commandLink>


       <!-- <apex:outputLink value="/apex/openlookup?firstName={!contact.firstName}&lastName={!contact.lastName}&account.name={!contact.account.name}&interested_technologies__c={!contact.Interested_technologies__c}" target="_blank" id="one">Select</apex:outputLink>-->
         </apex:column>
        <apex:outputField label="FirstName" value="{!contact.firstName}"/>
                   <apex:column >             
             <apex:facet name="header">
             

                   <apex:commandLink value="First Name" action="{!toggleSort}" rerender="results,debug">&nbsp;&nbsp;&nbsp;&nbsp;
               

                                       <apex:param name="sortField" value="firstName" assignTo="{!sortField}"/>
                   </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.firstName}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Last Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="lastName" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.lastName}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Account" action="{!toggleSort}" rerender="results,debug">
                                            <apex:param name="sortField" value="account.name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.account.name}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Technologies" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="interested_technologies__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.Interested_technologies__c}"/>
            </apex:column>
 
 
        </apex:pageBlockTable>
 
    </apex:pageBlock>
       </td>
  </tr>
    <apex:pageBlock title="Not Found Any Matching Records">
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <apex:commandLink value="Next" action="{!next}"/>
  </apex:pageBlock>
  </table>
    
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />          
  </apex:pageBlock>   
 
  </apex:pageBlock>
 
  </apex:form>
 
</apex:page>

 

++++++++++++++++++++++++++++

 

Controller class:

 

public with sharing class ContactSearchController1 {
    public ContactSearchController1(ApexPages.StandardController controller) {
    }

PageReference pageRef ;

 
 
  private String soql {get;set;}
 
  public List<Contact> contacts {get;set;}
   // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'lastName'; } return sortField;  }
    set;
  }
 
  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
 
  // init the controller and display some sample data when the page loads
  public ContactSearchController1() {
    soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
    runQuery();
  }
 
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
 
  // runs the actual query
  public void runQuery() {
 
    try {
      contacts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }
 
  }
 
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
 String firstName = Apexpages.currentPage().getParameters().get('firstname');
    String lastName = Apexpages.currentPage().getParameters().get('lastname');
    String accountName = Apexpages.currentPage().getParameters().get('accountName');
    String technology = Apexpages.currentPage().getParameters().get('technology');

    
    soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
    if (!firstName.equals(''))
      soql += ' and firstname LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';
    if (!lastName.equals(''))
      soql += ' and lastname LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';
    if (!accountName.equals(''))
      soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\''; 
    if (!technology.equals(''))
      soql += ' and interested_technologies__c includes (\''+technology+'\')';
 
    // run the query again
    runQuery();
 
    return null;
  }
 
  // use apex describe to build the picklist values
  public List<String> technologies {
    get {
      if (technologies == null) {
 
        technologies = new List<String>();
        Schema.DescribeFieldResult field = Contact.interested_technologies__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          technologies.add(f.getLabel());
 
      }
      return technologies;         
    }
    set;
  }
 
 public PageReference Next(){
   
     
   pageRef = new PageReference('/003/e?');
    PageRef.setRedirect(true);
       PageRef.getParameters().put('nooverride', '1');
    
 

Return PageRef;
  }

 
}

Hi

 

I want to redirect vf page values to particular object's edit layout fields. and on edit layout user should not be able to edit/change any of the fields which are auto-populate from vf page.

 

How I can restrict user for this..is it possible?any help would be appreciated...

 

Amruta

 

I developed this code:

 

VF page:

<apex:page standardController="Contact" extensions="ContactSearchController1" showHeader="false">
 
 <script>var cId = "{!Contact.Id}";</script>
   <apex:form >
  <apex:pageMessages id="errors" />
 
  <apex:pageBlock title="Find A Pre-Wired Site Address!" mode="edit">
 
  <table width="100%" border="0">
  <tr> 
    <td width="300" valign="top">
 
      <apex:pageBlock title="Parameters" mode="edit" id="criteria">
 
      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("firstName").value,
          document.getElementById("lastName").value,
          document.getElementById("accountName").value,
          document.getElementById("technology").options[document.getElementById("technology").selectedIndex].value
          );
      }
      </script>
 
      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="firstName" value="" />
          <apex:param name="lastName" value="" />
          <apex:param name="accountName" value="" />
          <apex:param name="technology" value="" />
      </apex:actionFunction>
 
      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">First Name<br/>
        <input type="text" id="firstName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Last Name<br/>
        <input type="text" id="lastName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;"><font color ="red">Account</font><br/>
        <input type="text" id="accountName" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Interested Technologies<br/>
          <select id="technology" onchange="doSearch();">
            <option value=""></option>
            <apex:repeat value="{!technologies}" var="tech">
              <option value="{!tech}">{!tech}</option>
            </apex:repeat>
          </select>
        </td>
      </tr>
      </table>
 
      </apex:pageBlock>
 
    </td>
    <td valign="top">
 
    <apex:pageBlock mode="edit" id="results">
 
        <apex:pageBlockTable value="{!contacts}" var="contact">
 
        <apex:column headerValue="Action">
        <apex:commandLink action="{!next}"> Select</apex:commandLink>


       <!-- <apex:outputLink value="/apex/openlookup?firstName={!contact.firstName}&lastName={!contact.lastName}&account.name={!contact.account.name}&interested_technologies__c={!contact.Interested_technologies__c}" target="_blank" id="one">Select</apex:outputLink>-->
         </apex:column>
        <apex:outputField label="FirstName" value="{!contact.firstName}"/>
                   <apex:column >             
             <apex:facet name="header">
             

                   <apex:commandLink value="First Name" action="{!toggleSort}" rerender="results,debug">&nbsp;&nbsp;&nbsp;&nbsp;
               

                                       <apex:param name="sortField" value="firstName" assignTo="{!sortField}"/>
                   </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.firstName}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Last Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="lastName" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.lastName}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Account" action="{!toggleSort}" rerender="results,debug">
                                            <apex:param name="sortField" value="account.name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.account.name}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Technologies" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="interested_technologies__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.Interested_technologies__c}"/>
            </apex:column>
 
 
        </apex:pageBlockTable>
 
    </apex:pageBlock>
       </td>
  </tr>
    <apex:pageBlock title="Not Found Any Matching Records">
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <apex:commandLink value="Next" action="{!next}"/>
  </apex:pageBlock>
  </table>
    
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />          
  </apex:pageBlock>   
 
  </apex:pageBlock>
 
  </apex:form>
 
</apex:page>

 

++++++++++++++++++++++++++++

 

Controller class:

 

public with sharing class ContactSearchController1 {
    public ContactSearchController1(ApexPages.StandardController controller) {
    }

PageReference pageRef ;

 
 
  private String soql {get;set;}
 
  public List<Contact> contacts {get;set;}
   // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'lastName'; } return sortField;  }
    set;
  }
 
  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
 
  // init the controller and display some sample data when the page loads
  public ContactSearchController1() {
    soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
    runQuery();
  }
 
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
 
  // runs the actual query
  public void runQuery() {
 
    try {
      contacts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }
 
  }
 
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
 String firstName = Apexpages.currentPage().getParameters().get('firstname');
    String lastName = Apexpages.currentPage().getParameters().get('lastname');
    String accountName = Apexpages.currentPage().getParameters().get('accountName');
    String technology = Apexpages.currentPage().getParameters().get('technology');

    
    soql = 'select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null';
    if (!firstName.equals(''))
      soql += ' and firstname LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';
    if (!lastName.equals(''))
      soql += ' and lastname LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';
    if (!accountName.equals(''))
      soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\''; 
    if (!technology.equals(''))
      soql += ' and interested_technologies__c includes (\''+technology+'\')';
 
    // run the query again
    runQuery();
 
    return null;
  }
 
  // use apex describe to build the picklist values
  public List<String> technologies {
    get {
      if (technologies == null) {
 
        technologies = new List<String>();
        Schema.DescribeFieldResult field = Contact.interested_technologies__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          technologies.add(f.getLabel());
 
      }
      return technologies;         
    }
    set;
  }
 
 public PageReference Next(){
   
     
   pageRef = new PageReference('/003/e?');
    PageRef.setRedirect(true);
       PageRef.getParameters().put('nooverride', '1');
    
 

Return PageRef;
  }

 
}

Hi There,

 

While doing deployment,I got an error.

here is my trigger code:

 

 

trigger FrameworkOptyTrigger on Opportunity(after delete, after insert,after update) {
Opportunity[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of opty
Set<ID> optyIds = new Set<ID>();

for (Opportunity con : cons) {
optyIds.add(con.Framework_Agreement__c);
}
try{

List<Opportunity> childopty= new List<Opportunity>([select Id,Framework_Agreement__c from Opportunity where Framework_Agreement__c in :optyIds]);

List<Opportunity> parentToUpdate= new List<Opportunity>([select Id,Number_of_Opportunities__c,Total_Sales__c,Total_Opportunity_Sum__c from Opportunity where Id in :optyIds]);

//Use aggregate soql to get total sum of all opportunity
AggregateResult[] groupedResults=[select Framework_Agreement__c ,sum(Amount)fm from Opportunity where Framework_Agreement__c in :optyIds group by Framework_Agreement__c];

//Use aggregate soql to get total sum of all Won opportunity

AggregateResult[] groupedResults1=[select Framework_Agreement__c ,sum(Amount)ar from Opportunity where Framework_Agreement__c in :optyIds and StageName='Closed Won' group by Framework_Agreement__c];

for (Opportunity o: parentToUpdate) {
Set<ID> opId= new Set<ID>();
for (Opportunity con : childopty) {
if (con.Framework_Agreement__c== o.Id)
opId.add(con.Id);
}

if (o.Number_of_Opportunities__c != opId.size())
o.Number_of_Opportunities__c = opId.size();

for(integer i=0;i<groupedResults.size();i++){
o.Total_Opportunity_Sum__c =(Decimal)groupedResults[i].get('fm');}

for(integer j=0;j<groupedResults1.size();j++){
o.Total_Sales__c = (Decimal)groupedResults1[j].get('ar');}
}

//update parent opportunity
update parentToUpdate;
}catch(Exception e){}

}

 

getting error on line :- List<Opportunity> childopty= new List<Opportunity>([select Id,Framework_Agreement__c from Opportunity where Framework_Agreement__c in :optyIds]);

 

any help would be appreciated,I've to deploy it on prod in urgent basis.

 

Amruta

 

 

Hi

 

I've Account & opty object.opty shared 22 recordtypes.when opty recordtype status is 'xxx' then it's updating Account field value to 'xxx' through trigger.

 

Now when I change recordtype to another [thru Change Link option beside recordtype] then it should set 'None' value on previous recordtype related Acct field.

 

Any suggestions how this can be achievable?

 

Amruta

Hi

 

I've one wf rule,and also written trigger on after insert,after update event.Now I am worrying about when this wf rule execute ,it will update status field of custom object and purpose of trigger is when any status changes of that custom object,then update the status field for another object.

 

 

Amruta

Hi

 

I want to write code for SUM() of all opportunity and SUM() of all WON opty.

 

here is my code but getting error:

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

 

trigger OptyTrigger on Opportunity(after delete, after insert, after undelete,after update) {
Opportunity[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of opty
Set<ID> acctIds = new Set<ID>();
for (Opportunity con : cons) {
acctIds.add(con.Framework_Agreement__c);
}

Map<ID, Opportunity> contactsForAccounts = new Map<ID, Opportunity>([select Id
,Framework_Agreement__c
from Opportunity
where Framework_Agreement__c in :acctIds]);

Map<ID, Opportunity> acctsToUpdate = new Map<ID, Opportunity>([select Id
,Number_of_Opportunities__c
from Opportunity
where Id in :acctIds]);

for (Opportunity acct : acctsToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Opportunity con : contactsForAccounts.values()) {
if (con.Framework_Agreement__c== acct.Id)
conIds.add(con.Id);
}
if (acct.Number_of_Opportunities__c != conIds.size())
acct.Number_of_Opportunities__c = conIds.size();
}

update acctsToUpdate.values();


LIST<AggregateResult> ChildCMRRList = [select Framework_Agreement__c fm,sum(Amount)childsum
from Opportunity where Framework_Agreement__c in :acctIds group by Framework_Agreement__c];
System.debug('ChildCMRR: ' + ChildCMRRList );

list<Opportunity> AccToUpdate = new list<Opportunity >();
for(AggregateResult ChildCMRR : ChildCMRRList){
ID Opportunity = (ID)ChildCMRR.get('fm');
Opportunity acc = new Opportunity (ID = Opportunity);

Decimal D = (Decimal)ChildCMRR.get('childsum');
acc.Total_Opportunity_Sum__c = D;

AccToUpdate.add(acc);
}
if(!AccToUpdate.isEmpty())
update AccToUpdate;

}

 

 

pls help how to resolve this.

 

Amruta

 

Hi There,

 

My req. is,I've Account obj as a master and Contract(custom obj)as detail.I've created 2 custom fields on Account eg.Asset Management Calculated Status,Built Environment Calculated Status with picklist values 'Customer' and 'Ex-Customer'.and Contract have 2 recordtypes say,'Asset Management','Built Environment'.Now whenever user select Contract recordtype as 'Asset Management' with Status 'Active' then it's corresponding Account 'Asset Management Calculated Status' field should get updated as 'Customer' value. and in other case, if user select Status as 'Terminated' then it's corresponding Account 'Asset Management Calculated Status' field should be updated as 'Ex-Customer'.

 

Business wants to write trigger on Contract and call apex class from there and class will hold all the logic......

 

plus I've to use custom setting for this scenario.in future if more Contract recordtype added then no need to touch code it should run dynamically......here are details:

 

Created custom setting named Record Maping added 2 custom fields and thru manage button inserted 2 records.

Custom Setting : Record Mapping

 

Record Type Name: Asset Management

Field Name :Asset Management Calculated Status

 

Record Type Name: Built Environment

Field Name :Built Environment Calculated Status

 

here is my code:

Trigger:

trigger ContractUpdate on MITIE_Contract__c (after insert,after update) {


// Creating an object named 'obj' of class "AccountUpdate"
    AccountUpdate obj = new AccountUpdate();
    system.debug('object calling 1');
  // Calling the 'CheckCondition' function of class "AccountUpdate"
    obj.CheckCondition(Trigger.new);
}

Class:

 

Public with sharing class AccountUpdate{


List<ID> accid= New List<ID>();

public void CheckCondition(MITIE_Contract__c[] m){

List<Record_Mapping__c> mcs = Record_Mapping__c.getAll().values();
system.debug('mcs..'+mcs);


//For Asset Management recordtpe on Contract
for(integer j=0;j<mcs.size();j++){
if(m[0].Status__c =='Active' && mcs[j].RecordType_Name__c=='Asset Management' &&m[0].Organisation_Name__c != null){

accid.add(m[0].Organisation_Name__c);
List<Account> oppList = [SELECT id, Asset_Management_Calculated_Status__c FROM Account WHERE id in :accid]; 

for(integer i = 0 ; i < oppList.size(); i++){
oppList[i].Asset_Management_Calculated_Status__c ='Customer';
}
update oppList;


}
}

 

 

Amruta

 

Hi There,

 

I am new to custom settings concept, I've created 1 custom setting with 3 custom fields and added 22 records.

Now I've to write trigger which will call apex class and thru class Account object custom fields should be updated.

 

I've to use custom settings in my class to run in dynamic manner

 

Require suggetions here how to use custom setting in apex class and how to implement.

 

 

Amruta

Hi There,

 

I'm only getting 42% code coverage with error msg :

 

System.NullPointerException: Attempt to de-reference a null object.

Class.PrewiredSearch.runSearch: line 282, column 1 Class.PrewiredSearch.Beginning: line 472, column 1 Class.testSearch.testSearch: line 71, column 1

 

Any advise?

 

Class:

 

public with sharing class PrewiredSearch{
private ApexPages.StandardController controller;
public String retURL {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}
public String cancelURL {get; set;}
public String ent {get; set;}
public String confirmationToken {get; set;}
String recordId;
String oppName;
public String accntName {get; set;}

 private integer counter=0;  //keeps track of the offset
   private integer list_size=20; //sets the page size or number of rows
   public integer total_size; //used to show user the total size of the list

String country1 = null;
Public String selection = '';
public Boolean shouldRender= false;
  private String soqlWhereClause {get;set;}

public String country {get; set;}

  public List<Site_Address__c> sites{get;set;}
  public Site_Address__c site{get;set;}

  Public String province {get; set;}
  Public String city {get; set;}
  Public String street {get; set;}
  Public String suburb {get; set;}
   Public Boolean flagNoRecordFound  {get; set;}
   Public Boolean flagNoApplicable {get; set;}


 public PrewiredSearch(ApexPages.StandardController  controller) {
 ///this.controller = controller;
  this.site= (Site_Address__c)controller.getRecord();

 recordId=ApexPages.currentPage().getParameters().get('Id');
 oppName=ApexPages.currentPage().getParameters().get('Name');
retURL = ApexPages.currentPage().getParameters().get('retURL');
rType = ApexPages.currentPage().getParameters().get('RecordType');
 cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');
ent = ApexPages.currentPage().getParameters().get('ent');
confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
accntName = ApexPages.currentPage().getParameters().get('CF00N20000002wMtX'); //lkid
system.debug('accntName :'+accntName );
       soql = 'select Country_Name__c, id,Name,Province__c, Pre_Wired_Site_Name__c,Pre_Wired_Site_Name__r.Name,City_Name__c,ignoredhidden__c,Ignored_Records__c, Street_Name__c,Suburb_Name__c from Site_Address__c where Establishment_Type__c in(\'Pre-Ducted Building\',\'Pre-Wired Building\')';
       soql += ' and Country_Name__c LIKE \'%South Africa%\'';       
       soqlWhereClause =' Country_Name__c LIKE \'%South Africa%\'';       
       runQuery();

 flagNoRecordFound=false;
flagNoApplicable =true;
    }
   public boolean getShouldRender() {
return shouldRender;
}

public void setBoolean(Boolean shouldRender) {
this.shouldRender= shouldRender;
}

 public boolean getFlagNoRecordFound() {

return this.flagNoRecordFound;
}

public void setFlagNoRecordFound(Boolean flagNoRecordFound) {
this.flagNoRecordFound= flagNoRecordFound;
}

 public boolean getFlagNoApplicable() {
return this.flagNoApplicable;
}

public void setFlagNoApplicable(Boolean flagNoApplicable) {
this.flagNoApplicable= flagNoApplicable;
}

 public String getString() {
return selection ;
}

public void setString(String selection ) {
this.selection = selection ;
}

public void Disable() {

if (selection.equals('Select')) {
shouldRender= true;
} else {
shouldRender= false;
}
}

PageReference pageRef ;
    private String soql {get;set;}
 

public PageReference redirect(){
PageReference pageRef ;
PageReference returnURL ;
 if(rType=='01220000000JJaz') {
 
            if ((accntName==null)){ 
           
 
              returnURL = new PageReference('/apex/PrewiredSearchVFPage');
             
              }
           else      
           {
             returnURL = new PageReference('/apex/PrewiredSearchVFPage?CF00N20000002wMtX='+accntName+'');

             }
            returnURL.setRedirect(true);
      }      
      return returnURL;
      If(rType=='012P00000000Hcj'){
  returnURL = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk');
   returnURL.setRedirect(true);
  
  }return returnURL;
 if(rType=='012P00000000HrW'){
  returnURL = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk');
   returnURL.setRedirect(true);
  
  }return returnURL;
  if(rType=='01220000000JJb4'){
  returnURL = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk');
   returnURL.setRedirect(true);
  
  }
  return returnURL;
  }
   public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
  public String sortField {
    get  { if (sortField == null) {sortField = 'Pre_Wired_Site_Name__c'; } return sortField;  }
    set;
  }
   public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }
    public PrewiredSearch() {
   
  }
   public void toggleSort() {
        sortDir = sortDir.equals // run the query again
    runQuery();
  }
 List<Site_Address__c> totalSiteAddr{get;set;}

     public void runQuery() {
     try {
    String soqlTot='select id from Site_Address__c where '+ soqlWhereClause ;
     System.debug('soqlTot:'+ soqlTot);

    totalSiteAddr =Database.query(soqlTot); //[select id  from Site_Address__c where  soqlWhereClause];
     total_size=totalSiteAddr.size();
     sites= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit :list_size  offset :counter');
               System.debug('sites :'+sites.size()+' ::counter :'+counter +':: total_size :'+total_size);
                         If (sites.isEmpty())
         {
         flagNoRecordFound=true;
           flagNoApplicable=false;
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Pre-Wired Name not found  or the search does not contain any name,Please select No Records Found Section'));
   
        }
        else
           {
              flagNoRecordFound=false;
              flagNoApplicable=true;
        }
   } catch (NullPointerException npe) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Pre-Wired Name not found  or the search does not contain any name'));
    }
   
    catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops! Please try your search again'));
    }
 
 }
     public PageReference runSearch() {
  
     
     String suburb= Apexpages.currentPage().getParameters().get('suburb');
    String street= Apexpages.currentPage().getParameters().get('street');
    
    soql = 'select Country_Name__c, id,Name,Province__c, Pre_Wired_Site_Name__c,Pre_Wired_Site_Name__r.Name,City_Name__c,ignoredhidden__c,Ignored_Records__c, Street_Name__c,Suburb_Name__c from Site_Address__c where Establishment_Type__c in(\'Pre-Ducted Building\',\'Pre-Wired Building\')';
   
    if (site.Country_Name__c!=null) 
    { 
      if(site.Country_Name__c.length() > 0)
      {
           soql += ' and Country_Name__c LIKE \'%'+ String.escapeSingleQuotes(site.Country_Name__c)+'%\'';
           }
       
       if (site.Province__c!=null ) 
        if(site.Province__c.length() > 0) 
        {
           soql += ' and Province__c LIKE \'%'+ String.escapeSingleQuotes(site.Province__c)+'%\'';
         
          soqlWhereClause  +=' and Province__c LIKE \'%'+ String.escapeSingleQuotes(site.Province__c)+'%\'';


                   }
          
       if (site.City_Name__c!=null)
         if(site.City_Name__c.length() > 0)    {
           soql += ' and City_Name__c LIKE \'%'+String.escapeSingleQuotes(site.City_Name__c)+'%\'';
            soqlWhereClause  += ' and City_Name__c LIKE \'%'+String.escapeSingleQuotes(site.City_Name__c)+'%\'';

          
          
           }
          
        if (street!=null)   
         if(street.length() > 0)  
         {
           soql += ' and Street_Name__c LIKE \'%'+String.escapeSingleQuotes(street)+'%\'';
             soqlWhereClause  += ' and Street_Name__c LIKE \'%'+String.escapeSingleQuotes(street)+'%\'';

           }
          
        if (suburb!=null)  
           if(suburb.length() > 0) 
           {  
           soql += ' and Suburb_Name__c LIKE \'%'+String.escapeSingleQuotes(suburb)+'%\'';
            soqlWhereClause  += ' and Suburb_Name__c LIKE \'%'+String.escapeSingleQuotes(suburb)+'%\'';

          
           }


       runQuery();
   }
  else
  {
       soql += ' and Country_Name__c LIKE \'%'+String.escapeSingleQuotes('null')+'%\''; 
  
   runQuery();
  }
     return null;
  }
 

 public PageReference Clickhere(){
if(accntName==null)
  pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00NW0000000ILAe=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c+'');
else
   pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00NW0000000ILAe=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c +'&CF00N20000002wMtX='+accntName);
  
    PageRef.setRedirect(true);
   PageRef.getParameters().put('nooverride', '1');
       

Return PageRef;
  }
public PageReference Clickhere1(){
       if(accntName==null)
          pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c );
     else    
       pageRef = new PageReference('/a0v/e?retURL=%2Fa0vP0000000xABk&00NW0000000ILAj=Yes&00N20000002wMth='+site.Country_Name__c+'&00N20000002wMtc='+site.City_Name__c+'&00N20000002wMu1='+site.Province__c +'&CF00N20000002wMtX='+accntName);

   PageRef.setRedirect(true);
   PageRef.getParameters().put('nooverride', '1');
       

Return PageRef;
  }
 public PageReference cancel() {
          PageReference pr = new PageReference('a0v/o');
          pr.setRedirect(true);
          return pr;
     }
    
 public PageReference test() {
 
      String siteId= Apexpages.currentPage().getParameters().get('siteId');
         return null;
    }
    public PageReference runSearch2() {
 PageReference pageRef ;
     String siteId= Apexpages.currentPage().getParameters().get('siteId');
      String street= Apexpages.currentPage().getParameters().get('street');
       String suburb= Apexpages.currentPage().getParameters().get('suburb');
     List<Site_Address__c> site = [select Country_Name__c,Name, id,Province__c, Pre_Wired_Site_Name__c,Pre_Wired_Site_Name__r.Name,City_Name__c,ignoredhidden__c,Ignored_Records__c, Street_Name__c,Suburb_Name__c from Site_Address__c where id=:siteId ];
        for(Site_Address__c siteObj : site )    
             { 
             
                 if ((suburb!='') && (street=='')){
         system.debug('inside runSearch2');
          if(accntName==null)
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF000N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuL='+suburb+'&00NW0000000ILAj=No');
          else
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&CF00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuL='+suburb+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');
       
         PageRef.setRedirect(true);
         PageRef.getParameters().put('nooverride', '1');
   }
   else if ((suburb=='') && (street!='')){
         system.debug('inside runSearch2');
          if(accntName==null)
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&00NW0000000ILAj=No');       
           else
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');

         PageRef.setRedirect(true);
         PageRef.getParameters().put('nooverride', '1');
   }
   else if ((suburb!='') && (street!='')){
         system.debug('inside runSearch2');
            if(accntName==null)
             pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&00N20000002wMuL='+suburb+'&00NW0000000ILAj=No');
        else
         pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00N20000002wMuB='+street+'&00N20000002wMuL='+suburb+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');
       
         PageRef.setRedirect(true);
         PageRef.getParameters().put('nooverride', '1');
   }
    else{        
         if(accntName==null)
                pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&00NW0000000ILAj=No');
          else
          pageRef = new PageReference('/a0v/e?&retURL=%2Fa0vP0000000xABk&00N20000002wMth='+siteObj.Country_Name__c+'&00N20000002wMtc='+siteObj.City_Name__c+'&CF00N20000002xCO6='+siteObj.Name+'&00NP0000000fkqZ='+siteObj.Pre_Wired_Site_Name__r.Name+'&00N20000002wMu1='+siteObj.Province__c+'&CF00N20000002wMtX='+accntName+'&00NW0000000ILAj=No');

         
        PageRef.setRedirect(true);
   PageRef.getParameters().put('nooverride', '1');
        }
                                    
        }
        return pageRef ;

        }

        public void StatesSelectList() {
String country= Apexpages.currentPage().getParameters().get('country');
  }
       public PageReference Beginning() { //user clicked beginning
      counter = 0;
      runSearch();
      return null;
   }

   public PageReference Previous() { //user clicked previous button
      counter -= list_size;
            runSearch();
      return null;
   }

   public PageReference Next() { //user clicked next button
      counter += list_size;
            runSearch();
      return null;
   }

   public PageReference End() { //user clicked end
      counter = total_size - math.mod(total_size, list_size);
            runSearch();
      return null;
   }

   public Boolean getDisablePrevious() { 
           if (counter>0) return false; else return true;
   }

   public Boolean getDisableNext() { //this will disable the next and end buttons
      if (counter + list_size < total_size) return false; else return true;
   }

   public Integer getTotal_size() {
   System.debug('total_size:'+total_size);
      return total_size;
   }

   public Integer getPageNumber() {
      return counter/list_size + 1;
   }

   public Integer getTotalPages() {
   System.debug('total_size:'+total_size  +':: list_size :'+list_size );

      if (math.mod(total_size, list_size) > 0) {
         return total_size/list_size + 1;
      } else {
         return (total_size/list_size);
      }
   }

   }

 

 

 

 

Amruta

 

Hi There,

 

I want to know how to take a sandbox backup before it get refreshed.

 

Amruta

Hi There,

 

I've a req. like based on opportunity level if Product Type field is 'ABC' then it's corresponding product manager,i.e.manager of that 'ABC' Product should get notification for approval.

 

is there any approach for this??

 

Amruta

Hi

 

Is there any version control functionality in sfdc??

 

Amruta

Hi,

 

After removing the object level edit and delete permission from the profile. Still I am able to see the Action column in the related list. Is there is any way to remove this Action column?