• test code
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 12
    Replies

Hi,

 

I am not able to update a field when a new record is saved.

 

Below is the code for an Custom Object Policy where I am trying to update a field "Product Id"  when a  new Policy Record is created.

Please find out error and provide a solution for it.

 

trigger PolicyProduct on Policy__c (before insert) {
        List<Policy__c> poli=new List<Policy__C>();
    for(List<Policy__c> policies:[select Id,Name,Product_Id__c,Status__c from Policy__c where Status__c='Active']){
                for(Policy__c pol:policies){
String Id=pol.Id;

            if(pol.Status__c=='Active'){
                pol.Product_Id__c='PD1'; 
              pol= new Policy__c(Id=pol.Id,Product_Id__c= pol.Product_Id__c);
                poli.add(pol);
               
            }
        }
    }
        if(poli.size()>0)
        {
                try{
                Database.SaveResult[] saveresults=Database.insert(poli,false);
                Integer x=0;
                for(Database.SaveResult svr:saveresults){
                    if(!svr.isSuccess())
                    {
                        Database.Error err=svr.getErrors()[0];
                        System.debug('Unable to insert policy'+poli[0].Name+'.Error'+err.getMessage());
                       
                    }
                    x++;
                   
                }
            }catch(Exception e){
            System.debug(e);
            }
           
       
    }

}

 

 

Thanks,

Manga

hi,i am trying to get total of a custom field i.e sum of premium,but the problem is whenever i m using SUM its throwing error.i have pasted my code in that code only i m using the function.When i m grouping the fields also its throwing error.i used aggregate methods also.Can anyone tell how to get the sum??

 

 

 

public class MyPolicy{
    public MyPolicy(ApexPages.StandardController controller) {

    }


        public List<Policy__c> getMyPolicy() {
Policy__c[] Pol = [SELECT name,Sum_Of_Premium__c,Channel_Name__r.Target__c,Channel_Name__r.name from Policy__c ];
 return Pol;
    }

}

Hi I am using Contact and Lead. In both Contact and Lead I have a custom field called TEB_ID__c. Now when I am creating a Contact record I am comparing all the TEB_ID_c of Customer with all the records Lead for similar TEB_ID__c. If TEB_ID_c of  Lead and Customer matches the Status__c field of Lead is updated to Close and that Lead record whose Status__c field has been updated will become a child record of customer for which TEB_ID_c is matching.

Now my issue is in my code I am able to update the Status__c field to Close but I am not able to get any clue how to add this updated Lead as child of Contact.

 

My code for to update Status__c field: 

 

trigger CloseLead2NEW on Contact (before update, before insert) {


List<Lead> lee=new List<Lead>();

Lead leeList;

Contact cc;

List<Lead> Updatelee=new List<Lead>();

if (Trigger.isUpdate||Trigger.isInsert)

{

    cc=Trigger.New[0];
    lee=[select id,TEB_ID__c,Citizenship_Number__c,Tax_Number__c from Lead where TEB_ID__c=:cc.TEB_ID__c OR Citizenship_Number__c=:cc.Citizenship_Number__c ];
  if(lee.size()>0)
 {

        for(Lead l:lee)
        {
       
                            l.Status='Closed';
                 
                             leeList= new Lead(id=l.id,Status=l.Status);
            Updatelee.add(leeList);
          
  
}
}
}
 

update Updatelee;

 

}

 

Help me to cretate this updated Lead as child of Contact record which has triggered the Lead record to get updated.

 

Thanks.

Hi i am new to salesforce. my code is not working, the where condition in query is not filtering data and when i am using groupby its showing the error

Field must be grouped or aggregated..even when i use WHERE its throwing error.

 

here is the class

 

public List<Policy__c> getMyPolicy() {
List<Policy__c> temp =[SELECT name,AVG(Sum_Of_Premium__c),Channel_Name__r.Target__c from Policy__c GROUP BY CreatedDate];
return temp;

 

In this i need average of custom field sum of premium.

 

any idea on this why it is not working???

Hi I am new to salesforce. my code is not giving any error but the where condition in query is not filtering data when I am adding second 'OR' clause in it. If I am not adding second OR clause the code is working in the expected way but moment I am adding any OR clause the query is not filtering any record it is just returning entire data.

 

trigger CloseLead2NEW on Contact (before update, before insert) {


List<Lead> lee=new List<Lead>();

Lead leeList;

Contact cc;

List<Lead> Updatelee=new List<Lead>();

if (Trigger.isUpdate||Trigger.isInsert)

{

    cc=Trigger.New[0];
  
 lee=[select id,TEB_ID__c,Citizenship_Number__c,Tax_Number__c from Lead where TEB_ID__c=:cc.TEB_ID__c OR Citizenship_Number__c=:cc.Citizenship_Number__c OR Tax_Number__c=:cc.Tax_Number__c ];
 if(lee.size()>0)
 {

        for(Lead l:lee)
        {
        l.Test_Integer_Field__c=lee.size();

                            l.Status='Closed';
                 
                             leeList= new Lead(id=l.id,Status=l.Status);
            Updatelee.add(leeList);
          
  
}
}
}
 

update Updatelee;

 

}

 

Please hlep and Thanks.

 

hi,i am trying to get total of a custom field i.e sum of premium,but the problem is whenever i m using SUM its throwing error.i have pasted my code in that code only i m using the function.When i m grouping the fields also its throwing error.i used aggregate methods also.Can anyone tell how to get the sum??

 

 

 

public class MyPolicy{
    public MyPolicy(ApexPages.StandardController controller) {

    }


        public List<Policy__c> getMyPolicy() {
Policy__c[] Pol = [SELECT name,Sum_Of_Premium__c,Channel_Name__r.Target__c,Channel_Name__r.name from Policy__c ];
 return Pol;
    }

}

Hi I am using Contact and Lead. In both Contact and Lead I have a custom field called TEB_ID__c. Now when I am creating a Contact record I am comparing all the TEB_ID_c of Customer with all the records Lead for similar TEB_ID__c. If TEB_ID_c of  Lead and Customer matches the Status__c field of Lead is updated to Close and that Lead record whose Status__c field has been updated will become a child record of customer for which TEB_ID_c is matching.

Now my issue is in my code I am able to update the Status__c field to Close but I am not able to get any clue how to add this updated Lead as child of Contact.

 

My code for to update Status__c field: 

 

trigger CloseLead2NEW on Contact (before update, before insert) {


List<Lead> lee=new List<Lead>();

Lead leeList;

Contact cc;

List<Lead> Updatelee=new List<Lead>();

if (Trigger.isUpdate||Trigger.isInsert)

{

    cc=Trigger.New[0];
    lee=[select id,TEB_ID__c,Citizenship_Number__c,Tax_Number__c from Lead where TEB_ID__c=:cc.TEB_ID__c OR Citizenship_Number__c=:cc.Citizenship_Number__c ];
  if(lee.size()>0)
 {

        for(Lead l:lee)
        {
       
                            l.Status='Closed';
                 
                             leeList= new Lead(id=l.id,Status=l.Status);
            Updatelee.add(leeList);
          
  
}
}
}
 

update Updatelee;

 

}

 

Help me to cretate this updated Lead as child of Contact record which has triggered the Lead record to get updated.

 

Thanks.

Hi i am new to salesforce. my code is not working, the where condition in query is not filtering data and when i am using groupby its showing the error

Field must be grouped or aggregated..even when i use WHERE its throwing error.

 

here is the class

 

public List<Policy__c> getMyPolicy() {
List<Policy__c> temp =[SELECT name,AVG(Sum_Of_Premium__c),Channel_Name__r.Target__c from Policy__c GROUP BY CreatedDate];
return temp;

 

In this i need average of custom field sum of premium.

 

any idea on this why it is not working???

Hi,

 

I have setup data loader from command line as mentioned in this article.

http://www.developerforce.com/media/Cheatsheet_Setting_Up_Automated_Data_Loader_9_0.pdf

 

I am  running into the issues. I do not understand what the below messages meant. can any one point me in the right direction.

 

Microsoft Windows [Version 6.1.7600]Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Windows\system32>cd C:\Program Files\salesforce.com\Apex Data Loader 22.0\bin

C:\Program Files\salesforce.com\Apex Data Loader 22.0\bin>process.bat "C:\Program Files\salesforce.com\Apex Data Loader 22.0\test\" csvLeadInsertProcess

Usage: java [-options] class [args...]         

                              (to execute a class) 

                     or  java [-options] -jar jarfile [args...]         

                              (to execute a jar file)
where options include:   

    -client       to select the "client" VM   

   -server       to select the "server" VM   

-hotspot      is a synonym for the "client" VM  [deprecated]                 

                     The default VM is client.
    -cp <class search path of directories and zip/jar files>   

   -classpath <class search path of directories and zip/jar files>                 

                           A ; separated list of directories, JAR archives,                 

                           and ZIP archives to search for class files. 

  -D<name>=<value>                  set a system property   

-verbose[:class|gc|jni]                  enable verbose output 

  -version      print product version and exit   

-version:<value>                  require the specified version to run   

-showversion  print product version and continue 

  -jre-restrict-search | -jre-no-restrict-search                  include/exclude user private JREs in the version search   

-? -help      print this help message   

-X            print help on non-standard options   

-ea[:<packagename>...|:<classname>]   

-enableassertions[:<packagename>...|:<classname>]                  enable assertions 

  -da[:<packagename>...|:<classname>]   

-disableassertions[:<packagename>...|:<classname>]                  disable assertions   

-esa | -enablesystemassertions                  enable system assertions   

-dsa | -disablesystemassertions                  disable system assertions   

-agentlib:<libname>[=<options>]                  load native agent library <libname>, e.g. -agentlib:hprof                    see also, -agentlib:jdwp=help and -agentlib:hprof=help    -agentpath:<pathname>[=<options>]                  load native agent library by full pathname    -javaagent:<jarpath>[=<options>]                  load Java programming language agent, see java.lang.instrument
C:\Program Files\salesforce.com\Apex Data Loader 22.0\bin>

 

I have no idea what it meant and all i know id that my process did not create the Leads from my csv file.

Any help is highly appreciated.

 

Thanks,

Sales4ce