• manjunath vivek
  • NEWBIE
  • 65 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 34
    Replies
This is my requirement
Create auto number field in the object: npe03_Recurring_Donation. This field will have the property that it will reset every month. This field will be unique according to another field: DSYDonationType_c.
Meaning if DSYDonationType_c='cheque' , the auto number field will start from chq-1,chq-2,chq-3...so on...on 1 st of every month and reset on 1 st of next month. If DSYDonationType_c='Online', auto number will start from onl-1,onl-2,onl-3 ...and so on.
I am working on the below code
It is working fine but the when the first record is created, it will not fetch any value in the field Reset number, from next record onwards it will start incrementing, but I don't want the first record to be empty because of which I need to enter the value manually, can some one help me on this...
Below is my code
trigger Reset_restart_autonum on npe03__Recurring_Donation__c (before insert) {
  Public integer i;
  Public integer month1;
  List<npe03__Recurring_Donation__c> hold=New list<npe03__Recurring_Donation__c>(); 
  String st2;
  Public Date todaysDate = system.today();
  Integer month = todaysDate.month();
  //Integer month=9;
  month1=month+1;
  hold=[Select id,createddate,DSYDonationType__c,Reset_number__c from npe03__Recurring_Donation__c where DSYDonationType__c=:trigger.new[0].DSYDonationType__c order by CreatedDate DESC LIMIT 1];  
  for(npe03__Recurring_Donation__c Adding:Hold){  
  String st = Adding.Reset_number__c; 
  system.debug('========Reset=========='+Adding.Reset_number__c);   
  if(st== null){
  st = 'DD-000';
  }  
  system.debug('========ST=========='+ST);  
  i = Integer.valueOf(st.split('-')[1]);   
  i++;
  system.debug('========Increment=========='+i);
  If(Adding.DSYDonationType__c!=Null && month==  Adding.createddate.month() ){    
  if(String.ValueOf(i).length() == 3){
    /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
    st2 = 'DD-0'+String.valueOf(i);
    system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == 1){
    st2 =  Adding.DSYDonationType__c+'-00'+String.valueOf(i);
    system.debug('========ST=========='+ST2);
  } 
 
  Adding.Reset_number__c= st2;
  system.debug('========ST=========='+ST2);
  
  }Else if((month!=  Adding.createddate.month()) || (month==month1)  ){
     st2='DD-000';
     Adding.Reset_number__c=st2;
     system.debug('========Cash-000=========='+Adding.Reset_number__c); 
  }
   }
  Trigger.New[0].Reset_number__c=St2;
  }
This is my requirement
Create auto number field in the object: npe03_Recurring_Donation. This field will have the property that it will reset every month. This field will be unique according to another field: DSYDonationType_c.
Meaning if DSYDonationType_c='cheque' , the auto number field will start from chq-1,chq-2,chq-3...so on...on 1 st of every month and reset on 1 st of next month. If DSYDonationType_c='Online', auto number will start from onl-1,onl-2,onl-3 ...and so on.
I am working on the below code
It is working fine but the when the first record is created, it will not fetch any value in the field Reset number, from next record onwards it will start incrementing, but I don't want the first record to be empty because of which I need to enter the value manually, can some one help me on this...
Below is my code
trigger Reset_restart_autonum on npe03__Recurring_Donation__c (before insert) {
  Public integer i;
  Public integer month1;
  List<npe03__Recurring_Donation__c> hold=New list<npe03__Recurring_Donation__c>(); 
  String st2;
  Public Date todaysDate = system.today();
  Integer month = todaysDate.month();
  //Integer month=9;
  month1=month+1;
  hold=[Select id,createddate,DSYDonationType__c,Reset_number__c from npe03__Recurring_Donation__c where DSYDonationType__c=:trigger.new[0].DSYDonationType__c order by CreatedDate DESC LIMIT 1];  
  for(npe03__Recurring_Donation__c Adding:Hold){  
  String st = Adding.Reset_number__c; 
  system.debug('========Reset=========='+Adding.Reset_number__c);   
  if(st== null){
  st = 'DD-000';
  }  
  system.debug('========ST=========='+ST);  
  i = Integer.valueOf(st.split('-')[1]);   
  i++;
  system.debug('========Increment=========='+i);
  If(Adding.DSYDonationType__c=='DD' && month==  Adding.createddate.month() ){   
  
  if(String.ValueOf(i).length() == 3){
    /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
    st2 = 'DD-0'+String.valueOf(i);
    system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == 1){
    st2 = 'DD-00'+String.valueOf(i);
    system.debug('========ST=========='+ST2);
  } 
 
  Adding.Reset_number__c= st2;
  system.debug('========ST=========='+ST2);
  
  }Else if((month!=  Adding.createddate.month()) || (month==month1)  ){
     st2='DD-000';
     Adding.Reset_number__c=st2;
     system.debug('========Cash-000=========='+Adding.Reset_number__c); 
  }Else If(Adding.DSYDonationType__c=='Cash' && month==  Adding.createddate.month() ){ 
  if(String.ValueOf(i).length() == 3){
    /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
  st2 = 'Cash-0'+String.valueOf(i);
  }else if(String.ValueOf(i).length() == 1){
  system.debug('========ST2=========='+ST2); 
  st2 = 'Cash-00'+String.valueOf(i);
  system.debug('========ST=========='+ST2); 
  }
  Adding.Reset_number__c= st2;
  system.debug('========Reset Number=========='+Adding.Reset_number__c); 
  }Else if((month!=  Adding.createddate.month()) || (month==month1)  ){
  st2='Cash-000';
  Adding.Reset_number__c=st2;
  system.debug('========Cash-000=========='+Adding.Reset_number__c); 
  }
  system.debug('========DSYDonationType=========='+Adding.DSYDonationType__c);
  If(Adding.DSYDonationType__c=='Online' && month==  Adding.createddate.month() ){ 
  System.debug('====enter the loop=====');
  system.debug('========DSYDonationType=========='+Adding.DSYDonationType__c);
  if(String.ValueOf(i).length() == 3){
  /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
  st2 = 'Online-0'+String.valueOf(i);
  system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == 1){
  st2 = 'Online-00'+String.valueOf(i);
  system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == null){
  st2 = 'Online-000';
  }
  Adding.Reset_number__c= st2;
  system.debug('========ST=========='+ST2);
  } Else if((month!=  Adding.createddate.month()) || (month==month1)  ){
  st2='Online-000';
  Adding.Reset_number__c=st2;
  system.debug('========Cash-000=========='+Adding.Reset_number__c); 
  }
  If(Adding.DSYDonationType__c=='Cheque' && month==  Adding.createddate.month() ){ 
  System.debug('====enter the loop=====');
  system.debug('========DSYDonationType=========='+Adding.DSYDonationType__c);
  if(String.ValueOf(i).length() == 3){
  /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
  st2 = 'Cheque-0'+String.valueOf(i);
  system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == 1){
  st2 = 'Cheque-00'+String.valueOf(i);
  system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == null){
  st2 = 'Cheque-000';
  }
  Adding.Reset_number__c= st2;
  system.debug('========ST=========='+ST2);
  }  
  Else if((month!=  Adding.createddate.month()) || (month==month1)  ){
  st2='Cheque-000';
  Adding.Reset_number__c=st2;
  system.debug('========Cheque-000=========='+Adding.Reset_number__c); 
  }    
  If(Adding.DSYDonationType__c=='Card' && month==  Adding.createddate.month() ){
  system.debug('========DSYDonationType=========='+Adding.DSYDonationType__c);
  if(String.ValueOf(i).length() == 3){
    /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
  st2 = 'Card-0'+String.valueOf(i);
  system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == 1){
  st2 = 'Card-00'+String.valueOf(i);
  system.debug('========ST=========='+ST2);
  }else if(String.ValueOf(i).length() == null){
  st2 = 'Card-000';
  }
  Adding.Reset_number__c= st2;
  system.debug('========ST=========='+ST2);
  }   
  Else if((month!=  Adding.createddate.month()) || (month==month1)  )
  {
  st2='Card-000';
  Adding.Reset_number__c=st2;
  system.debug('========Card-000=========='+Adding.Reset_number__c); 
  }   
  If(Adding.DSYDonationType__c=='Direct transfer' && month==  Adding.createddate.month() ){
  if(String.ValueOf(i).length() == 3){
   /*Do Nothing*/
  }else if(String.ValueOf(i).length() == 2){
  st2 = 'DT-0'+String.valueOf(i);
  }else if(String.ValueOf(i).length() == 1){
  st2 = 'DT-00'+String.valueOf(i);
  }else if(String.ValueOf(i).length() == null){
  st2 = 'DT-000';
  }
  Adding.Reset_number__c= st2;
  }  
  Else if((month!=  Adding.createddate.month()) || (month==month1)  ){
  st2='DT-000';
  Adding.Reset_number__c=st2; 
  }    
   }
  Trigger.New[0].Reset_number__c=St2;
  }

 
Hi,

Iam trying add the values from the inputfield of the sandard object product to add cart list (whenc addcart command button is clicked i need to to list out the values of product).I am getting error message.
<apex:page standardController="product2" showheader="false" sidebar="false" recordSetVar="Product2" extensions="addcart">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!product2}" var="pitem">
<apex:column headerValue="Product">
<apex:outputText value="{!pitem.name}"/>
</apex:column>
<apex:column headerValue="Price">
<apex:outputText value="{!pitem.Product_price__c}"/>
</apex:column>
<apex:column headerValue="Number of products">
<apex:inputText value="{!pitem.Number_of_products__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton action="{!additems}" value="Add items"/>
<apex:pageBlock title="Your items" id="shopping_cart">
<apex:outputText value="{!message}" />
</apex:pageBlock>
</apex:form>
</apex:page>









Public class addcart {

    public addcart(ApexPages.StandardSetController controller) {
    }
    

public String message { get; set; }
    
public PageReference additems() {
message = 'You bought: ';
for (Displayproducts p: products) {
if (p.count> 0) {
message += p.newproduct.name ; 
System.debug('test'+message);
}
}
return null;
}
 
   
   
      Displayproducts[] products;

public class Displayproducts {
public product2 newproduct { get; set; }
public Decimal count{ get; set; }

public Displayproducts(product2 item) {
this.newproduct = item;
 }
}

    

public Displayproducts[] getproducts() {
if(products == null) {


          Products=new Displayproducts[]{};

      for(Product2 item : [SELECT Id, Name,Number_of_products__c FROM product2]) {
      products.add(new displayproducts(item));
      
                        }

                     }
        return products;
       }
    
  }


System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!additems}' in component <apex:commandButton> in page addcart: Class.addcart.additems: line 11, column 1
Class.addcart.additems: line 11, column 1
Hi,

I am trying to modify  the values of monthly investments  and update it to the yearly investments of the same object but Iam getting an error message.

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Yearlyinvestments caused an unexpected exception, contact your administrator: Yearlyinvestments: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Yearlyinvestments: line 15, column 1". 


Below is my code

trigger Yearlyinvestments  on Budget__c (after insert, after update) {


List<Budget__c> budg=new list<budget__C> ();


for(Budget__c bud:trigger.new){

If(bud.Monthlyinvestments__C!=null){

     decimal X,Y;
 
     x=bud.Monthlyinvestments__C;
  
     Y+=X;
     
     bud.Yearlyinvestments__C=y;
  
     budg.add(bud);


    }
    
  }

update budg;

 }
Hi all,

My visualforce code and controller is as follows.

<apex:page standardcontroller="Bankloan__c" extensions="inform">
<apex:form >
  <apex:pageBlock >
   <apex:pageblockTable value="{!bank}" var="b">
    <apex:column value="{!b.EMI__c}"/>
    <apex:column value="{!b.Bank_name__c}"/>
    <apex:column value="{!b.Loan_type__c}"/>
    <apex:column value="{!b.EMI_date__c}"/>
    <apex:column value="{!b.Loan_taken__c}"/>
    
   </apex:pageblockTable>
   
   <apex:outputText value="{!emi}"/>
   <BR></Br>
    <apex:outputText value="{!loanamount}"/>
  </apex:pageBlock>
  </apex:form>
  
</apex:page>




Public  class inform{

Public List<Bankloan__C> Bank {get;set;}


    public inform(ApexPages.StandardController controller) {
Bank=[Select EMI__c,Bank_name__c,Loan_type__c,EMI_date__c,Loan_taken__c from Bankloan__c];
    }
  
  
Public Decimal getemi(){  
 
  Decimal sum=0;


  For(Bankloan__C BK: Bank){
    
Sum+=BK.EMI__C;

}
Return Sum;

}


Public Decimal getloanamount(){  
  Decimal summ=0;
    For(Bankloan__C BK: Bank){

Summ=BK.Loan_taken__c;

  }
Return Summ;

}

}


It works fine, but when I change Summ=BK.Loan_taken__c;( I have written it in bold letters in the above code)
 to Summ+=BK.Loan_taken__c;, it throws an error message "System.NullPointerException: Argument cannot be null. 
Class.inform.getloanamount: line 19, column 1",I a not able to fix the issue, i have used same type of method in the above code
for retrieving EMI,without any issue.I made sure there are values available for Loan_taken__c field, still unable to fix he isssue.

Can some one help me please?
I am not able to retrieve the fields from contact,can some one help me  on this?

<apex:page standardController="contact" recordSetVar="contact">
<apex:pageBlock title="Viewing Contacts">
<apex:form id="theForm">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!contact}" var="c" id="List">
{!c.name}    
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
</apex:page>

Iam trying to count the number of contacts on account, Iam getting the following error message

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Account> at line 10 column 1    

Trigger counting on contact(after update,after insert){
Set<account> accids=New Set<Account>();
For(contact c:trigger.new){
Accids.add(c.Account);
}
List<Contact> con = [select id  from contact where AccountID IN:accids];
List<Account> Acc=[Select count__C from account where id IN:accids ];
For(contact c:trigger.new)
{
Acc.count__c=con.size();
}
}
I am trying to count the number of contacts associated with the account.Code is saved , but  not works.Please help me.

Trigger counting on contact(after update,after insert){
List<account> accids=New list<Account>();
For(contact con:trigger.new){
Accids.add(con.account);
}
For(contact con:trigger.new)
{
Account Acc;
Acc.count__c=accids.size();
}
}