• Gonzalo Abruna
  • NEWBIE
  • 90 Points
  • Member since 2012


  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 21
    Replies
Hi ,

I am getting all custom object list from the orgainization, but I am getting historical data objects. I don't want those objects in my list.
Can you please help any one.

List<Schema.SObjectType> allObjectsList = Schema.getGlobalDescribe().values();
Set<String> customObjectsList = new Set<String>();
                                            
        for(Schema.SObjectType objType : listOfAllObjects)
        {           
            Schema.DescribeSObjectResult objectResult = objType.getDescribe();
            if(objectResult.isCustom() && !objectResult.isCustomSetting())
            {               
                customObjectsList.add(objectResult.getName());                                                                                           
            }
        }

In customObjectsList I am getting 'Historical Data' Objects like abc__c_hd. I don't want '_hd' objects.

Thanks 
Venkat
Class:
_______________----
public with sharing class SendSMS
{
public void run(String subject,String msg,string smsNumber)
    {
            SessionService S=new SessionService();
            SessionService.SessionServiceSoap sa=new  SessionService.SessionServiceSoap();
             
                sessionservice.BindingResult BinidingResult=Sa.GetBindings(m_Username );
                System.debug('BinidingResult>>>'+BinidingResult.sessionServiceLocation);
                sa.endpoint_x = BinidingResult.sessionServiceLocation;
                // Sa.GetServiceInformation('Salesforce');
                // sa.endpoint_x = 'https://na2.esker.com/EDPWS_C/EDPWS.dll?BindingId=20130730093630andrew.luu@tunstall.com&Handler=Default';
                sessionservice.LoginResult loginResult=sa.Login(m_Username , m_Password );
                String SessinID=loginResult.sessionID;
                submissionservice.SubmissionServiceSoap Submission=new submissionservice.SubmissionServiceSoap();
                Submission.endpoint_x = BinidingResult.SubmissionServiceLocation;
                submissionservice.SessionHeader Header=new submissionservice.SessionHeader();
                Header.SessionID=SessinID;
                Submission.SessionHeaderValue= Header;
                System.debug(Submission.endpoint_x+'********* SessinID ************* '+SessinID);
                // Now allocate a transport with transportName = "SMS"
                    submissionservice.Transport transport = new submissionservice.Transport();
                    transport.RecipientType='';
                    transport.TransportIndex='';
                    transport.TransportName='SMS';
                  
                    submissionservice.vars_element vrs1=new  submissionservice.vars_element();
                    List<submissionservice.Var> VarList=new  List<submissionservice.Var>();
                    submissionservice.Var Vars=new submissionservice.Var();
                    Vars.Attribute = 'Subject';
                   // Vars.type_x='1';
                    Vars.simpleValue = subject;
                   // Vars.nValues=4;
                  
                    submissionservice.Var Vars1=new submissionservice.Var();
                    Vars1.Attribute = 'FromName';
                    // Vars1.type_x='1';
                    Vars1.simpleValue = 'TUNSTALL';
                    // Vars1.nValues=4;
                  
                    submissionservice.Var Vars2=new submissionservice.Var();
                    Vars2.Attribute = 'SMSNumber';
                    // Vars2.type_x='1';'216-256-8216'
                    Vars2.simpleValue = smsNumber;     
                    // Vars2.nValues=4;
                  
                    submissionservice.Var Vars3=new submissionservice.Var();
                    Vars3.Attribute = 'Message';
                    // Vars3.type_x='1';
                    Vars3.simpleValue = msg;
                    // Vars3.nValues=4;
                  
                    VarList.add(Vars);
                    VarList.add(Vars1);
                    VarList.add(Vars2);
                    VarList.add(Vars3);
                    vrs1.Var=VarList;
                    transport.Vars=vrs1;
                    System.debug('######### Mahesh ############# '+submission.submitTransport(transport));
          
  
    }
}

@Test Class
public class SendSMS_TC
{
    static testmethod void m1()
    {
        SendSMS ss = new SendSMS();
        ss.run('test data','test','678jjh');
    }
}
In the Account Object i have custom picklist for District and a number field called Postal Code.
I want to dynamically populate the postal code when the user selects the district before the record is saved.

Please let me know how can i do it.

Thanks in advance.

Hi Guys,

I am trying to merge two contacts. Class is using the keyword  "without sharing". So the the class is running in system admin mode. I have checked the system admin profie, the profile is having all permissions(DELETE contact, MODIFY ALL DATA on contact).

I am calling this class on another class , that parent class is also using the keyword "without sharing". But still I am getting below error:
Merge failed. First exception on row 0 with id 0031100000XXYfRAAX; first error: INSUFFICIENT_ACCESS_OR_READONLY, cannot merge with entity that is not accessible: []

Below is class code:

public without sharing class DeleteContact {
    public void deleteContact(String contactId,string email){
        Map<String, Schema.SobjectField> contactfields = Schema.SObjectType.contact.fields.getMap();
        List<Schema.SObjectField> fldObjMapValues = contactfields.values();
        string theQuery1;
        string theQuery2;
        String theQuery = 'SELECT ';
            for(Schema.SObjectField s : fldObjMapValues)
            {
               String theLabel = s.getDescribe().getLabel();
               String theName = s.getDescribe().getName();
               theQuery += theName + ',';
            }
            theQuery = theQuery.subString(0, theQuery.length() - 1);
          
            theQuery1 = theQuery + ' FROM Contact WHERE Id =: contactId';
            theQuery2 = theQuery + ' FROM Contact WHERE Id !=: contactId AND Email =: email';
          
      
        Contact previouscontact=Database.query(theQuery1);
        List<Contact> listContacts=Database.query(theQuery2);
        if(previouscontact!=null && listContacts[0]!=null){
            try{
                merge  previouscontact listContacts[0];
            }
            catch(Exception e){
                system.debug('============='+e.getMessage());
            }
    }
}


Can some one please suggest me why this error is coming?. Urgent Please.
We are using a read-only Visualforce page to display list of records summarized by a text field. We having about 1500 unique values (across 3000 record).
We are using dynamic styles for each column to differentiate backgroud based on some criteria (around 30 columns).
We are using maximum HTML tags and apex output format tags to display value in currency format and to enable hyperlink on each values.

Page is working fine with 1100 unique rows. For 1150 unique rows, we are getting the "Response Size Exceeded 15 MB" error in ON and OFF situations. For 1200 rows, we are getting this error everytime. We are trying to reduce the complexity of the page as much as possible (Converting VF tags to HTML). Still we are getting this error.

Is there any other best practise to follow? Do we have the same Response size limit for sandbox and production?
Hi I am crating a visualforce page showing some data with one lookup field. Page is loading in my developer account (having 100 records).  Even I have used te paginaion i.e. showing only 20 records per page. After creating package when I am installing package in my live accoun t(having 2000+  records) and trying to open that page but  it is giving the following error.
Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 604.391KB

I tried to check the view state in my developer account. Only 6.44 kb is used.  While live account does'nt showing the view state I dont know why ?
Please check my class and visual force page code below :

Class Code
public with sharing class PolicyWrapperClassController {
public List<wPolicy> policyList {get; set;}

//public String accountName {get; set;}
//public Id accountId {get; set;}

   private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 20;

public PolicyWrapperClassController()
{
totalRecs = [select count() from CanaryAMS__Policy__c where CanaryAMS__To_be_Reviewed__c = true];
}
  
    public List<wPolicy> getPolicies() {
        if(policyList == null) {
             policyList = new List<wPolicy>();
           
             Map<Id, Contact> ContactsDetail = new Map<Id, Contact>();
             List<Contact> contacts = [ SELECT Id,Name from Contact];
          
              for(Contact c : contacts){
                  ContactsDetail.put(c.id, c);
              }
            
                Map< Id,String> recordTypeMap = RecordTypeMap();
                 List<CanaryAMS__Policy__c> oldpoliciesList = new List<CanaryAMS__Policy__c>();
            oldpoliciesList = [SELECT Id,CanaryAMS__Effective_Date__c,Name,CanaryAMS__Policy_Number__c,CanaryAMS__Carrier__r.Name,CanaryAMS__PolicyTypeCd__c,CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c,CanaryAMS__Carrier_Product__c from CanaryAMS__Policy__c where  CanaryAMS__To_be_Reviewed__c = false];  
             //system.debug('SELECT Id,Name,CanaryAMS__Policy_Number__c,CanaryAMS__Effective_Date__c,CanaryAMS__Carrier__r.Name,CanaryAMS__PolicyTypeCd__c,CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c,CanaryAMS__Carrier_Product__c from CanaryAMS__Policy__c where  CanaryAMS__To_be_Reviewed__c = true LIMIT'  LIMIT :LimitSize OFFSET :OffsetSize  +LimitSize+ 'OFFSET' +OffsetSize);
             for(CanaryAMS__Policy__c p: Database.Query('SELECT Id,Name,RecordTypeId,CanaryAMS__Policy_Number__c,CanaryAMS__Effective_Date__c,CanaryAMS__Carrier__r.Name,CanaryAMS__PolicyTypeCd__c,CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c,CanaryAMS__Carrier_Product__c from CanaryAMS__Policy__c where CanaryAMS__To_be_Reviewed__c = true LIMIT :LimitSize OFFSET :OffsetSize')) {
                // As each contact is processed we create a new wPolicy object and add it to the policyList
                //system.debug('test=========>>>>' + p);
                  wPolicy policyWrapper = new wPolicy(p);
                
               policyWrapper =  fetchSuggestedPolicies(p,oldpoliciesList,ContactsDetail,policyWrapper);
                  
                  if(policyWrapper.bestMatch != null)
                  {
                   policyWrapper.policyId = policyWrapper.bestMatch.Id;
                   policyWrapper.policyName = policyWrapper.bestMatch.CanaryAMS__Policy_Number__c;
                  }
           /*       
                  try {
                   Contact contact = ContactsDetail.get(p.CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c);     
                   policyWrapper.con = contact;
                  }catch(DmlException e) {
               system.debug('info putinto ivansreulsts. test>>>'+p.Name);
            } catch(Exception e) {
                system.debug('info putinto ivansreulsts. test6>>>'+p.Name);
            }
            */
            try {
                   String name = recordTypeMap.get(p.RecordTypeId);     
                   policyWrapper.recordTypeName = name;
                   //policyWrapper.recordTypeId = p.RecordTypeId;
                  }catch(DmlException e) {
            } catch(Exception e) {
            }
           
                
                
                 policyList.add(policyWrapper);
            }
        }
        return policyList;
    }


    public PageReference processSelected() {
     system.debug('coming -----');
                //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<wPolicy> selectedPolicies = new List<wPolicy>();
        for(wPolicy wPol: getPolicies()) {
            if(wPol.selected == true) {
             system.debug(wPol);
                selectedPolicies.add(wPol);
            }
          
         }
         system.debug('selectedPolicies -----'+selectedPolicies);
  
  if(!selectedPolicies.isEmpty())
        {
         fetchData(selectedPolicies);
      ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Policy successfully merged'));
     }
        else
        {
           ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Select atleast one Policy you want to merge'));
        }
 
        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
       /* System.debug('These are the selected Contacts...');
        for(CanaryAMS__Policy__c pol: selectedPolicies) {
            system.debug('selectedPolicies -----'+pol);
        }*/
        policyList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
        return null;
    }
    

      public PageReference markAsResolved() {
       system.debug('coming here -----');
                //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<wPolicy> selectedPolicies = new List<wPolicy>();
// system.debug('resolve these policies -----'+getPolicies);
        //We will cycle through our list of wPolicys and will check to see if the selected property is set to true, if it is we add the Contact to the selectedPolicies list
        for(wPolicy wPol: getPolicies()) {
          //  system.debug('resolve these policies -----'+wPol);
            if(wPol.selected == true) {
            system.debug(wPol);
            
             //getData(oldPolicyId, newPolicyId);
             //system.debug(wPol.pol.CanaryAMS__Account__r.Primary_Contact__c);
           
                selectedPolicies.add(wPol);
            }
          
         }
          
   system.debug('selectedPolicies -----'+selectedPolicies);
    if(!selectedPolicies.isEmpty())
         {
          resolveSelectedPolicies(selectedPolicies);
       //ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Policy successfully merged'));
      }
         else
         {
            //ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Select atleast one Policy you want to merge'));
         }
   policyList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
        return null;
    }


    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class wPolicy {
        public CanaryAMS__Policy__c pol {get; set;}
        public Boolean selected {get; set;}
       // public Contact con {get; set;}
        public Map<CanaryAMS__Policy__c, Integer> suggestedPolicies {get; set;}
        public CanaryAMS__Policy__c bestMatch {get; set;}
       
        //public CanaryAMS__Policy__c suggestedPol {get; set;}
      //  public String policyName {get; set;}
       // public String recordTypeId {get; set;}
        public String recordTypeName {get; set;}
        public String policyId {get; set;}
        public String policyName {get; set;}
     
        //This is the contructor method. When we create a new wPolicy object we pass a Contact that is set to the con property. We also set the selected value to false
        public wPolicy(CanaryAMS__Policy__c p) {
            pol = p;
            selected = false;
        }
    }
   
   
   public String fetchFields(String objectName)
    {
    
  Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();

  string fieldnames=' ';
  for(String s : objectFields.keySet())
  {
   s = objectFields.get(s).getDescribe().getName() ;
      fieldnames+=s+',';
  }
     fieldnames=fieldnames.substring(0,fieldnames.length()-1);
     return fieldnames;
    
    }
   
    public void fetchData(List<wPolicy> selectedPolicies)
     { 
      System.debug('selectedPolicies3456...'+selectedPolicies);
     
       List<CanaryAMS__Policy__c> policiesToUpdate =  new List<CanaryAMS__Policy__c>();
       List<CanaryAMS__Policy__c> policiesToUpsert =  new List<CanaryAMS__Policy__c>();
       List<CanaryAMS__Policy_Contact_Junction__c> updateInsuredData = new List<CanaryAMS__Policy_Contact_Junction__c>();
       List<CanaryAMS__Vehicle__c> updateVehicleData = new List<CanaryAMS__Vehicle__c>();
       List<CanaryAMS__Claim__c> updateClaimData = new List<CanaryAMS__Claim__c>();
       List<CanaryAMS__Additional_Interests__c> updateAdditionalInterstData = new List<CanaryAMS__Additional_Interests__c>();
       List<CanaryAMS__Form__c> updateFormData = new List<CanaryAMS__Form__c>();
       List<CanaryAMS__Coverage__c> updateCoverageData = new List<CanaryAMS__Coverage__c>();
      
       string fieldnames =  fetchFields('CanaryAMS__Policy__c');
       string query=  'SELECT '+fieldnames +' from CanaryAMS__Policy__c';
           List <CanaryAMS__Policy__c> policiesData = Database.query(query);
           Map<Id, CanaryAMS__Policy__c> policiesMap = new Map<Id, CanaryAMS__Policy__c>();
          for(CanaryAMS__Policy__c pol : policiesData){
              policiesMap.put(pol.Id, pol);
          }
     
       List<CanaryAMS__Vehicle__c> vehicleData =  [select id ,Name, CanaryAMS__Policy__c from CanaryAMS__Vehicle__c];
      List<CanaryAMS__Claim__c> claimData = [select id ,Name, CanaryAMS__Policy__c from CanaryAMS__Claim__c ];
   List<CanaryAMS__Coverage__c> coverageData = [select id ,Name, CanaryAMS__Policy__c from CanaryAMS__Coverage__c];
   List<CanaryAMS__Additional_Interests__c> additionalInterstData = [select id ,Name, CanaryAMS__Policy__c from CanaryAMS__Additional_Interests__c];
   List<CanaryAMS__Form__c> formData  = [select id ,Name, CanaryAMS__Policy__c from CanaryAMS__Form__c ];
   List<CanaryAMS__Policy_Contact_Junction__c> insuredData =  [select id ,Name, CanaryAMS__Policy__c ,CanaryAMS__Contact__c from CanaryAMS__Policy_Contact_Junction__c ];
  
       Map<String, List<CanaryAMS__Vehicle__c>> polVehicleMap = new Map<String, List<CanaryAMS__Vehicle__c>>();     
         Map<String, List<CanaryAMS__Claim__c>> polClaimMap = new Map<String, List<CanaryAMS__Claim__c>>();
         Map<String, List<CanaryAMS__Coverage__c>> polCoverageMap = new Map<String, List<CanaryAMS__Coverage__c>>();
         Map<String, List<CanaryAMS__Additional_Interests__c>> polAddIntMap = new Map<String, List<CanaryAMS__Additional_Interests__c>>();  
         Map<String, List<CanaryAMS__Form__c>> polFormMap = new Map<String, List<CanaryAMS__Form__c>>(); 
         Map<String, List<CanaryAMS__Policy_Contact_Junction__c>> polConJunctionMap = new Map<String, List<CanaryAMS__Policy_Contact_Junction__c>>(); 
     
      if(!insuredData.isEmpty())
      {
        for(CanaryAMS__Policy_Contact_Junction__c insured : insuredData){
                String policyId = insured.CanaryAMS__Policy__c;
                List <CanaryAMS__Policy_Contact_Junction__c> polConJunctionList = polConJunctionMap.get(policyId);
                 if(polConJunctionList == null )
                 {
                   polConJunctionList =  new List<CanaryAMS__Policy_Contact_Junction__c>();
                 }
                 polConJunctionList.add(insured);
                 polConJunctionMap.put(policyId, polConJunctionList);
        }
      }
     
      if(!formData.isEmpty())
      {
        for(CanaryAMS__Form__c form : formData){
                String policyId = form.CanaryAMS__Policy__c;
                List <CanaryAMS__Form__c> polFormList = polFormMap.get(policyId);
                 if(polFormList == null )
                 {
                   polFormList =  new List<CanaryAMS__Form__c>();
                 }
                 polFormList.add(form);
                 polFormMap.put(policyId, polFormList);
        }
      }
     
      if(!additionalInterstData.isEmpty())
      {
        for(CanaryAMS__Additional_Interests__c AI : additionalInterstData){
                String policyId = AI.CanaryAMS__Policy__c;
                List <CanaryAMS__Additional_Interests__c> polAddIntList = polAddIntMap.get(policyId);
                 if(polAddIntList == null )
                 {
                   polAddIntList =  new List<CanaryAMS__Additional_Interests__c>();
                 }
                 polAddIntList.add(AI);
                 polAddIntMap.put(policyId, polAddIntList);
        }
      }
     
     
      if(!coverageData.isEmpty())
      {
        for(CanaryAMS__Coverage__c cov : coverageData){
                String policyId = cov.CanaryAMS__Policy__c;
                List <CanaryAMS__Coverage__c> polCoverageList = polCoverageMap.get(policyId);
                 if(polCoverageList == null )
                 {
                   polCoverageList =  new List<CanaryAMS__Coverage__c>();
                 }
                 polCoverageList.add(cov);
                 polCoverageMap.put(policyId, polCoverageList);
        }
      }
      
      if(!claimData.isEmpty())
      {
        for(CanaryAMS__Claim__c claim : claimData){
                String policyId = claim.CanaryAMS__Policy__c;
                List <CanaryAMS__Claim__c> polClaimList = polClaimMap.get(policyId);
                 if(polClaimList == null )
                 {
                   polClaimList =  new List<CanaryAMS__Claim__c>();
                 }
                 polClaimList.add(claim);
                 polClaimMap.put(policyId, polClaimList);
        }
      }
     
      if(!vehicleData.isEmpty())
      {
        for(CanaryAMS__Vehicle__c veh : vehicleData){
                String policyId = veh.CanaryAMS__Policy__c;
                List <CanaryAMS__Vehicle__c> polVehicleList = polVehicleMap.get(policyId);
                 if(polVehicleList == null )
                 {
                   polVehicleList =  new List<CanaryAMS__Vehicle__c>();
                 }
                 polVehicleList.add(veh);
                 polVehicleMap.put(policyId, polVehicleList);
        }
      }
        Map<Id,String> policyIdsMap = new Map<Id,String>();
      
      for(wPolicy wPols: selectedPolicies) {
               
          //Id oldPolicyId1 = wPols.policyId;
           String oldPolicyId = wPols.policyId;
              // system.debug(newPolicyId);   
       if(oldPolicyId != null && !oldPolicyId.equals('') )
       {
               
       CanaryAMS__Policy__c Policy = new CanaryAMS__Policy__c();
     
         //String oldPolicyId = wPols.policyId;
             Id newPolicyId = wPols.Pol.Id ;
         // Id newPolicyId = wPols.Pol.Id ;
            
             policyIdsMap.put(newPolicyId,oldPolicyId);
       CanaryAMS__Policy__c newPolicyData = policiesMap.get(newPolicyId);   //Database.query(query);;
          CanaryAMS__Policy__c oldPolicyData = policiesMap.get(oldPolicyId);  //[SELECT Id,Name,CanaryAMS__Policy_Number__c from CanaryAMS__Policy__c where Id = : oldPolicyId];
       System.debug('oldPolicyData ==== '+oldPolicyData);
       //CanaryAMS__Policy__c policyUpdate = new CanaryAMS__Policy__c();
       Policy.Id = newPolicyData.Id;
          Policy.CanaryAMS__Policy_Number__c = newPolicyData.CanaryAMS__Policy_Number__c+'_DELETE';
          Policy.CanaryAMS__To_be_Reviewed__c = false ;
       Policy.Name = newPolicyData.Name+'_DELETE';
       Policy.CanaryAMS__Policy_Number_Ex__c = Policy.CanaryAMS__Policy_Number__c;
       policiesToUpdate.add(Policy);
         
       
       
        newPolicyData.Id = oldPolicyData.Id;
           newPolicyData.CanaryAMS__To_be_Reviewed__c = false ;
          //  newPolicyData.CanaryAMS__To_be_Reviewed__c = false ;
           policiesToUpsert.add(newPolicyData);
          
          List<CanaryAMS__Vehicle__c> polVehicleList =   polVehicleMap.get(newPolicyId);
       System.debug('polVehicleList ==== '+polVehicleList);
              if(polVehicleList != null && !polVehicleList.isEmpty())
        { 
            for(CanaryAMS__Vehicle__c Vehicle : polVehicleList )
         {
            CanaryAMS__Vehicle__c updateVehicle = new CanaryAMS__Vehicle__c();
          updateVehicle.CanaryAMS__Policy__c =  oldPolicyId;
          updateVehicle.Id = Vehicle.Id;
          updateVehicleData.add(updateVehicle);
         }
        }
        
          List<CanaryAMS__Coverage__c> polCoverageList =   polCoverageMap.get(newPolicyId);
       System.debug('polCoverageList ==== '+polCoverageList);
          if(polCoverageList != null && !polCoverageList.isEmpty())
        { 
            for(CanaryAMS__Coverage__c Coverage : polCoverageList )
         {
            CanaryAMS__Coverage__c updateCoverage = new CanaryAMS__Coverage__c();
          updateCoverage.CanaryAMS__Policy__c = oldPolicyId;
          updateCoverage.Id = Coverage.Id;
          updateCoverageData.add(updateCoverage);
         }
        }
       
        List<CanaryAMS__Claim__c> polClaimList =   polClaimMap.get(newPolicyId);
       System.debug('polClaimList ==== '+polClaimList);
       
        if(polClaimList != null && !polClaimList.isEmpty())
        { 
            for(CanaryAMS__Claim__c Claim : polClaimList )
         {
            CanaryAMS__Claim__c updateClaim = new CanaryAMS__Claim__c();
          updateClaim.CanaryAMS__Policy__c = oldPolicyId;
          updateClaim.Id = Claim.Id;
          updateClaimData.add(updateClaim);
         }
        }
       
        List<CanaryAMS__Additional_Interests__c> polAddIntList =   polAddIntMap.get(newPolicyId);
       System.debug('polAddIntList ==== '+polAddIntList);
       
        if(polAddIntList != null && !polAddIntList.isEmpty())
        { 
            for(CanaryAMS__Additional_Interests__c AdditionalInterst : polAddIntList )
         {
            CanaryAMS__Additional_Interests__c updateAdditionalInterst = new CanaryAMS__Additional_Interests__c();
          updateAdditionalInterst.CanaryAMS__Policy__c = oldPolicyId;
          updateAdditionalInterst.Id = AdditionalInterst.Id;
          updateAdditionalInterstData.add(updateAdditionalInterst);
         }
        }
       
        List<CanaryAMS__Form__c> polFormList =   polFormMap.get(newPolicyId);
       System.debug('polFormList ==== '+polFormList);
        if(polFormList != null && !polFormList.isEmpty())
        { 
            for(CanaryAMS__Form__c Form : polFormList )
         {
            CanaryAMS__Form__c updateForm = new CanaryAMS__Form__c();
          updateForm.CanaryAMS__Policy__c =oldPolicyId;
          updateForm.Id = Form.Id;
          updateFormData.add(updateForm);
         }
        }
       
        List<CanaryAMS__Policy_Contact_Junction__c> polConJunctionList =   polConJunctionMap.get(newPolicyId);
       System.debug('polConJunctionList ==== '+polConJunctionList);
       
        if(polConJunctionList != null && !polConJunctionList.isEmpty())
        { 
            for(CanaryAMS__Policy_Contact_Junction__c Insured : polConJunctionList )
         {
            CanaryAMS__Policy_Contact_Junction__c insuredForm = new CanaryAMS__Policy_Contact_Junction__c();
          insuredForm.CanaryAMS__Policy__c =oldPolicyId;
          insuredForm.Id = Insured.Id;
          insuredForm.CanaryAMS__Composite_Key__c = ''+insuredForm.CanaryAMS__Contact__c+insuredForm.CanaryAMS__Policy__c;
          updateInsuredData.add(insuredForm);
         }
        }
           }
      }
    
     if(!updateVehicleData.isEmpty())
      {
      update updateVehicleData;
      System.debug('updateVehicleData ==== '+updateVehicleData);
      }
      if(!updateClaimData.isEmpty())
      {
      update updateClaimData;
      System.debug('updateClaimData ==== '+updateClaimData);
      }
     if(!updateCoverageData.isEmpty())
      {
      update updateCoverageData;
      System.debug('updateCoverageData ==== '+updateCoverageData);
      }
       if(!updateAdditionalInterstData.isEmpty())
      {
      update updateAdditionalInterstData;
      System.debug('updateAdditionalInterstData ==== '+updateAdditionalInterstData);
      }
      if(!updateFormData.isEmpty())
      {
      update updateFormData;
      System.debug('updateFormData ==== '+updateFormData);
      }
      if(!updateInsuredData.isEmpty())
      {
      update updateInsuredData;
      System.debug('updateInsuredData ==== '+updateInsuredData);
      }
      if(!policiesToUpdate.isEmpty())
      {
      delete policiesToUpdate ;
      System.debug('policiesToUpdate ==== '+policiesToUpdate);
      }//CanaryAMS__Policy_Number_Ex__c;
     
      if(!policiesToUpsert.isEmpty())
      {
      upsert policiesToUpsert;
      System.debug('policiesToUpsert ==== '+policiesToUpsert);
      }
  
   
    }
   
   
    public wPolicy fetchSuggestedPolicies(CanaryAMS__Policy__c newPolicy,List<CanaryAMS__Policy__c> oldPolicies,Map<Id, Contact> ContactsDetail, wPolicy policyWrapper)
    {
   Map<CanaryAMS__Policy__c, Integer> suggestedPolicies = new Map<CanaryAMS__Policy__c, Integer>();
      CanaryAMS__Policy__c bestMatch ;
      Integer MaxCount = 0;
     
      for(CanaryAMS__Policy__c pol : oldPolicies)
      { 
       Integer value = 0;
     
       if(newPolicy.CanaryAMS__Carrier_Product__c ==  pol.CanaryAMS__Carrier_Product__c)
       {
        value = value + 1;
         }
      
       if(newPolicy.CanaryAMS__Effective_Date__c ==  pol.CanaryAMS__Effective_Date__c)
       {
        value = value + 1;
       }
      
       Contact oldContact ;
       Contact newContact;
      
       oldContact = ContactsDetail.get(pol.CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c);
       newContact= ContactsDetail.get(newPolicy.CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c);
      
       if(oldContact != null && newContact !=null)
       {
        String oldPolicyContactName= ContactsDetail.get(pol.CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c).Name;
        String newPolicyContactName= ContactsDetail.get(newPolicy.CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c).Name;
        ContactsDetail.get(pol.CanaryAMS__Account__r.CanaryAMS__Primary_Contact__c);
      
        if(oldPolicyContactName!= null && oldPolicyContactName.equals(newPolicyContactName) )
        {
         value = value + 1;
        }
       }
      
       if(value > 0)
        {
         suggestedPolicies.put(pol,value);
      
        if(value >= MaxCount)  
        {
         bestMatch =  pol;
        }
        }
      }
     
      policyWrapper.suggestedPolicies = suggestedPolicies;
      policyWrapper.bestMatch = bestMatch;
    
      return policyWrapper;
     
    }
   
    public void resolveSelectedPolicies(List<wPolicy> selectedPolicies)
    {
      List<CanaryAMS__Policy__c> policiesToUpdate =  new List<CanaryAMS__Policy__c>();
      for(wPolicy wPols: selectedPolicies) {
        CanaryAMS__Policy__c Policy = new CanaryAMS__Policy__c();
      
       Policy.CanaryAMS__To_be_Reviewed__c = false;
       Policy.Id = wPols.Pol.Id;
      
       policiesToUpdate.add(Policy);
       }
       system.debug('policiesToUpdate -----'+policiesToUpdate);
       update policiesToUpdate;
    }
   
    public void FirstPage()
{
  policyList = null;
  OffsetSize = 0;
  system.debug('FirstPage OffsetSize === >> '+ OffsetSize);
}
public void previous()
{
   policyList = null;
  OffsetSize = OffsetSize - LimitSize;
  system.debug('previous OffsetSize === >> '+ OffsetSize);
}
public void next()
{
  policyList = null;
  OffsetSize = OffsetSize + LimitSize;
  system.debug('next OffsetSize === >> '+ OffsetSize);
}
public void LastPage()
{
  policyList = null;
  OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
  system.debug('LastPage OffsetSize === >> '+ OffsetSize);
}
public boolean getprev()
{
  //policyList = null;
  if(OffsetSize == 0)
  return true;
  else
  return false;
}
public boolean getnxt()
{
  //policyList = null;
  if((OffsetSize + LimitSize) > totalRecs)
  return true;
  else
  return false;
}

  public Map<Id,String> RecordTypeMap(){
        Map<Id,String>recordTypesMap = new map<Id,String>();
        List<RecordType> recordTypes = null;
        try{
            recordTypes = [Select Id,Name From RecordType];
            for(RecordType info: recordTypes) {
                recordTypesMap.put(info.Id,info.Name);
            }
        }catch (DmlException e) {
               system.debug('error'+e);
                return null;
        }
        return recordTypesMap;
    }    
   
}
VisualForce Page Code
<apex:page controller="PolicyWrapperClassController">

<script>
    var newWin=null;
    function openLookupPopup(name, id)
    {
        var url="/apex/LookupExamplePopup?namefield=" + name + "&idfield=" + id;
        newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
        if (window.focus)
        {
            newWin.focus();
        }
          
        return false;
    }
                
    function closeLookupPopup()
    {
       if (null!=newWin)
       {
          newWin.close();
       }
    }
  
     function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");               
            for(var i=0; i<inputCheckBox.length; i++){       
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){                                  
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
  
</script>
<apex:pageMessages />


    <apex:form >
        <apex:pageBlock id="details" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Merge Policies" action="{!processSelected}" rerender="table"/>
                  <apex:commandButton value="Mark As Resolved" action="{!markAsResolved}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!policies}" var="p" id="table">
                <apex:column >
              
                    <apex:facet name="header">
                        <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                    </apex:facet>
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!p.selected}" id="inputId"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
              <apex:column headerValue="Policy Name" >
                <apex:outputLink value="/{!p.pol.Id}" id="eventlink" target="_blank"> {!p.pol.Name}
                    </apex:outputLink>
               </apex:column>
                <apex:column headerValue="Policy Number" value="{!p.pol.Policy_Number__c}" />
               <!--  <apex:column headerValue="Contact" >
                    <apex:outputLink value="/{!p.pol.CanaryAMS__Account__r.Primary_Contact__c}" id="eventlink">{!p.con.Name}
                    </apex:outputLink>
                </apex:column> -->
                <apex:column headerValue="Policy Type" value="{!p.recordTypeName}" />
              
               <apex:column headerValue="Carrier" value="{!p.pol.CanaryAMS__Carrier__r.Name}" />
                <apex:column headerValue="Suggested Policy" >
                    <apex:outputPanel >
                        <apex:inputHidden value="{!p.bestMatch.Id}" id="bestMatchId" />
                         <apex:outputLink value="/{!p.bestMatch.Id}" id="eventlink5" target="_blank"> {!p.bestMatch.Name}
                          </apex:outputLink>
                    </apex:outputPanel>
                </apex:column>
                         
              
                <apex:column headerValue="Policy" >
                    <apex:outputPanel >
                        <apex:inputHidden value="{!p.policyId}" id="policyId" />
                        <apex:inputText value="{!p.policyName}" id="policyName" onFocus="this.blur()" /> <a href="#" onclick="openLookupPopup('{!$Component.policyName}', '{!$Component.policyId}'); return false">Lookup</a>
                    </apex:outputPanel>
                </apex:column>
             </apex:pageBlockTable>
           
             <apex:pageblockButtons >
    <apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
    <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
    <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
    <apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
   </apex:pageblockButtons>
           
        </apex:pageBlock>
      
    </apex:form>
 
</apex:page>

Hi All,

I want to display mutiple records on page using pagination.

i want create a next button and on clicking of this button the want display next set of records along with the current records.

Is there any way that I can append the newly fetched records with previous records?


Is it possible to pick values ​​between SELECT and FROM (String) and use the code in Apex?

Example: the user informe = SELECT casenumber,subject,Contact.Name,status FROM Case WHERE ClosedDate=TODAY
The Apex code uses only: casenumber, subject, Contact.Name, status to build a CSV::::

...
string titre= 'casenumber,subject,Contact.Name,status'+'\n';

...

for(Case a: (List<case>)database.query(caseTT) )
{
   string contenu = a.casenumber + ',' + a.subject+ ',' +a.Contact.Name+ ',' + a.status +'\n';
   contenuCSV = contenuCSV + contenu ;
}

....

Thank you!!!
Hi ,

I am getting all custom object list from the orgainization, but I am getting historical data objects. I don't want those objects in my list.
Can you please help any one.

List<Schema.SObjectType> allObjectsList = Schema.getGlobalDescribe().values();
Set<String> customObjectsList = new Set<String>();
                                            
        for(Schema.SObjectType objType : listOfAllObjects)
        {           
            Schema.DescribeSObjectResult objectResult = objType.getDescribe();
            if(objectResult.isCustom() && !objectResult.isCustomSetting())
            {               
                customObjectsList.add(objectResult.getName());                                                                                           
            }
        }

In customObjectsList I am getting 'Historical Data' Objects like abc__c_hd. I don't want '_hd' objects.

Thanks 
Venkat
Is it necessary to have code coverage in your full sandbox before deploying via change set to production?  If not, please explain?  I will give kudos to whomever responds.

Thank you,
S
Hi ..
I have a master-detail relationship to my object Order__c and account.
When I ausführe my query:
List <AggregateResult> result = [SELECT Account__c, COUNT (name), SUM (Price__c) total FROM Order__c GROUP BY Account__c];

How do I get through the Account__c field returns the name of the account?
Hi,

I have a Visualfore page on which I need to conditionally render a commandlink. 

<apex:commandLink value="CrowdGuides" onclick="window.open('/apex/cGuide__Guide_Viewer?id={!CrowdGuideid}&url=https%3A%2F%2Fcs10.salesforce.com%2F001%2Fo','_blank','width=700,height=700');return False;"/>

I have added a Query in the controller class to get the CrowdGuideId
Private final id CrowdGuideid = [SELECT ID FROM cGuide__Guide__c WHERE (cGuide__Object_Prefix__c = '001' and cGuide__Active__c = true) order by cGuide__Likes__c desc limit 1].id;

The controller runs in WIth Sharing mode and some of our users does not have access to the records on the Guide__c object. Hence, when they try to open the VF page, system is throwing the exception. 

1. How can I handle the scenario, when the query did not return any result?
2. How can I render the commandlink only when the Query returned result?

Thank You for the help in Advance!!
Hi All,

If i select a date in datefield while inserting/updating record.I want a field to populated with +2 yrs of selected date.

Can we achieve this with formula field ??
Hi,

I am getting the following rule exception on the below line of code. Please suggest what can be the alternative for this -

Opportunity updateOpportunity;
        List<Opportunity> listToUpdateMasterOpportunity = new List<Opportunity>();
        for(Opportunity opp : updateMasterOpportunity) {
            updateOpportunity = new Opportunity(id = opp.id); ////////////Avoid instantiating new objects inside loops
            if(mapCalculatedMasterOptyVal.get(opp.id) != null) {
                updateOpportunity.Sub_Opportunities_Total_Amounts__c = mapCalculatedMasterOptyVal.get(opp.id);
            }
            listToUpdateMasterOpportunity.add(updateOpportunity);
        }
        opportunityDao.updateOpportunity(listToUpdateMasterOpportunity);
    }
Hi,

I need to wriate a SOQL query to get the aggregate value of Contacts object custom objects.
I have created two custom fields ( NoOfPagesPrinted__c, DatePrinted__c) in contact object.
I need to get sum of pages printed of each account. I have written below query. Please correct this query.

Select Account.ID, Account.Name, SUM(Select Contact.NoOfPagesPrinted__c from contact where Contact.DatePrinted__c = LAST_N_DAYS:30) from Account where Account.AccountType__c ='LES' group by Account.Name

-Thanks.




Class:
_______________----
public with sharing class SendSMS
{
public void run(String subject,String msg,string smsNumber)
    {
            SessionService S=new SessionService();
            SessionService.SessionServiceSoap sa=new  SessionService.SessionServiceSoap();
             
                sessionservice.BindingResult BinidingResult=Sa.GetBindings(m_Username );
                System.debug('BinidingResult>>>'+BinidingResult.sessionServiceLocation);
                sa.endpoint_x = BinidingResult.sessionServiceLocation;
                // Sa.GetServiceInformation('Salesforce');
                // sa.endpoint_x = 'https://na2.esker.com/EDPWS_C/EDPWS.dll?BindingId=20130730093630andrew.luu@tunstall.com&Handler=Default';
                sessionservice.LoginResult loginResult=sa.Login(m_Username , m_Password );
                String SessinID=loginResult.sessionID;
                submissionservice.SubmissionServiceSoap Submission=new submissionservice.SubmissionServiceSoap();
                Submission.endpoint_x = BinidingResult.SubmissionServiceLocation;
                submissionservice.SessionHeader Header=new submissionservice.SessionHeader();
                Header.SessionID=SessinID;
                Submission.SessionHeaderValue= Header;
                System.debug(Submission.endpoint_x+'********* SessinID ************* '+SessinID);
                // Now allocate a transport with transportName = "SMS"
                    submissionservice.Transport transport = new submissionservice.Transport();
                    transport.RecipientType='';
                    transport.TransportIndex='';
                    transport.TransportName='SMS';
                  
                    submissionservice.vars_element vrs1=new  submissionservice.vars_element();
                    List<submissionservice.Var> VarList=new  List<submissionservice.Var>();
                    submissionservice.Var Vars=new submissionservice.Var();
                    Vars.Attribute = 'Subject';
                   // Vars.type_x='1';
                    Vars.simpleValue = subject;
                   // Vars.nValues=4;
                  
                    submissionservice.Var Vars1=new submissionservice.Var();
                    Vars1.Attribute = 'FromName';
                    // Vars1.type_x='1';
                    Vars1.simpleValue = 'TUNSTALL';
                    // Vars1.nValues=4;
                  
                    submissionservice.Var Vars2=new submissionservice.Var();
                    Vars2.Attribute = 'SMSNumber';
                    // Vars2.type_x='1';'216-256-8216'
                    Vars2.simpleValue = smsNumber;     
                    // Vars2.nValues=4;
                  
                    submissionservice.Var Vars3=new submissionservice.Var();
                    Vars3.Attribute = 'Message';
                    // Vars3.type_x='1';
                    Vars3.simpleValue = msg;
                    // Vars3.nValues=4;
                  
                    VarList.add(Vars);
                    VarList.add(Vars1);
                    VarList.add(Vars2);
                    VarList.add(Vars3);
                    vrs1.Var=VarList;
                    transport.Vars=vrs1;
                    System.debug('######### Mahesh ############# '+submission.submitTransport(transport));
          
  
    }
}

@Test Class
public class SendSMS_TC
{
    static testmethod void m1()
    {
        SendSMS ss = new SendSMS();
        ss.run('test data','test','678jjh');
    }
}
In the Account Object i have custom picklist for District and a number field called Postal Code.
I want to dynamically populate the postal code when the user selects the district before the record is saved.

Please let me know how can i do it.

Thanks in advance.
I have a VF page displaying as a component in a custom console. It allows the user to perform what I call "quick edits" for a few key fields. When the console is opened, those fields are displayed with the component in edit mode. If the users changes or adds to these fields, then clicks save, it does save the records as I want it to. However, instead of refreshing to display the VF page, it refreshes to display the page layout of the (custom) object into which the records were saved. 

For a visual example, the first screen shot is what I want the left side component to look like all the time (before a save and after a save).
console component (VF page) as I want it to be before and after a save


This is what the page looks like after a save - it displays the object's detail page in view mode. I want it to display my custom VF page which is the edit mode shown above. 

User-added image


Is this possible? Thanks in advance for any contributions!
I am trying to pull an image from a Rich text area field on Account object to a field on a related custom object. Has anyone done this before or have any advise on the easiest way to do it?.

Basically, the data from the standard Account object is being pulled across (via formula fields) to a related custom object. I am struggling with pulling accross the image from a rich text area field.

Any ideas on best practice for doing this?

As many of you have discovered, our developer community is awesome. The wealth of knowledge here is phenomenal. This is an all volunteer community and people who take the time to help and post answers do so totally on their own initiative. With that said when someone provides the right answer to your question please take the time to mark their answer as the accepted solution. Also give them a kudos if they've really gone the extra mile to help out. Show some love ;)