• 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,

I have two objects, contact(standard object) and Callrecord__c (custom object),Contact has lookup relationship with Callrecord__c,I would like to  display Call_Date__c field  which is in  custom object when we enter the phone number in inputfield and submit button is clicked.We should make sure Call_Date__c field should be related to the phone number that we enter in inputfield.My code is given below,iam not getting any error but the code is not displaying Call_Date__c field .
<apex:page Standardcontroller="Contact" extensions="Retrievefields" >

 <apex:form >
<apex:pageblock title="Callrecords" >
 <apex:inputText value="{!phnum}" />
 
 <apex:commandButton value="Submit" action="{!find}"/>
 </apex:pageblock>
 <apex:pageBlock title="Search Result">
      <apex:pageblockTable value="{!CallList}" var="a">

      <apex:column value="{!a.Call_Date__c}"/>

                 </apex:pageBlockTable>     
    </apex:pageBlock>    

  </apex:form>
 </apex:page>



public class Retrievefields{

     public Integer Phnum {get; set;}
  public List<Call_Record__c>  CallList {get; set;}
   

    
public Retrievefields(ApexPages.StandardController controller) {

}

public void find()
  {
    string sql = 'SELECT Call_Date__c FROM Call_Record__c WHERE Donor__c.phone LIKE \'%'+Phnum+'%\' LIMIT 5 ';
    CallList = Database.query(sql);
    
   }
   
   }



 
Iam trying to test the data to check if invoice with line item is not getting deleted, Iam getting above error.

@isTest
private class TestInvoiceStatementDeletion {
    static testmethod void TestDeleteInvoiceWithLineItem() {
// Create an invoice statement with a line item then try to delete it
Invoice_Statement__c inv = TestDataFactory.createOneInvoiceStatement(true);
Test.startTest();
Database.DeleteResult result = Database.delete(inv, false);
Test.stopTest();
// Verify invoice with a line item didn't get deleted.
System.assert(!result.isSuccess());
}
static testmethod void TestDeleteInvoiceWithoutLineItems() {
// Create an invoice statement without a line item and try to delete it
Invoice_Statement__c inv = TestDataFactory.createOneInvoiceStatement(false);
Test.startTest();
Database.DeleteResult result = Database.delete(inv, false);
Test.stopTest();
// Verify invoice without line items got deleted.
System.assert(result.isSuccess());
}
static testmethod void TestBulkDeleteInvoices() {
// Create two invoice statements, one with and one with out line items
// Then try to delete them both in a bulk operation, as might happen
// when a trigger fires.
List<Invoice_Statement__c> invList = new List<Invoice_Statement__c>();
invList.add(TestDataFactory.createOneInvoiceStatement(true));
invList.add(TestDataFactory.createOneInvoiceStatement(false));
Test.startTest();
Database.DeleteResult[] results = Database.delete(invList, false);
Test.stopTest();
// Verify the invoice with the line item didn't get deleted
System.assert(!results[0].isSuccess());
// Verity the invoice without line items did get deleted.
System.assert(results[1].isSuccess());
}
}
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?
Not able to retrieve fields from contact.

<apex:page standardController="contact" recordSetVar="contacts" >
<apex:form >
<apex:pageBlock title="Viewing Contacts">
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column value="{!c.name}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
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>
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();
}
}
I have two custom objects Review__c and Job_application__c, they have master-detail relationship,Job_application__c is a master object and Review__c  is a child object.Iam trying to write a trigger to update thee field status as new for every new review__C record,
 
Iam not succeeded writing trigger

below is the code I tried
trigger child on Review__c(before insert){

List<id> parent=New list<id>();
For(Review__c R:trigger.new){
Parent.add(R.parentid);
}
for(Review__C R :[Select id,Total_Rating__c from Job_application__c where id IN: parentid]){
R.satus__c='0';
}
}

Can some one help me on this?
01 trigger populateFieldOnCase on Case (before insert){

02     Set<id>parentIds = new Set<id>();

03     for(Case acase:trigger.new){

04         parentIds.add(acase.project__c);

05     }

06     Map<id,parent__c> pro = new Map<id,parent__c>([select id,parentField__c from parent__c where idin :parentIds]);

07     for(case acase:trigger.new){

08         <strong>if(pro.get(acase.id) != null){</strong>

09             acase.childfield__c = pro.get(acase.id).parentField__c;

10         <strong>}</strong>

11     }

12 }
<apex:page Controller="Delet">

<apex:form >

  <center>
  <apex:pageBlock >
    <b>Category:&nbsp;&nbsp;</b>
    <apex:selectList value="{!ctgry}" size="1">
      <apex:selectOptions value="{!ctgrys}"/>
    </apex:selectList> 
  </apex:pageBlock>
  </center>
 
</apex:form>
</apex:page>





public class Delet
{

    public String[] ctgry = new String[]{};
   
    public Delet()
    {

    }
   
    public List<SelectOption> getCtgrys()
    {   
      List<SelectOption> options = new List<SelectOption>();
      options.add(new SelectOption('US','US'));
      options.add(new SelectOption('CANADA','Canada'));
      options.add(new SelectOption('MEXICO','Mexico'));
      return options;
    }
   
    public String[] getCtgry()
    {
      return ctgry;
    }
   
    public void setCtgry(String[] ctgry)
    {
    this.ctgry = ctgry;
    }   

}



Can some one tell me in the above code,what is &nbsp;&nbsp and in the line public String[] ctgry = new String[]{};
why [] and {} both the braces is used and what does that line mean.
why  MEXICO','Mexico' caps and small letters used.why constructor,getter and setter used.
Can some one suggest any website in which there are some sample  code of apex with screen shots except infallible and shiva websites.Tha
apex:page standardController="Member__c" extensions="Search" >

  <style type = "text/css">
    .Bld { font-weight:bold;}
  </style>
 
  <apex:form >
 
    <apex:pageblock title="Members" >
      <table align = "center" width = "100%" cellspacing = "5">
        <tr>
          <td class = "Bld">Member Name:</td>
          <td><apex:inputText value="{!memName}" /></td>         
        </tr>
        <tr>
          <td align = "center" class = "Bld" colspan = "2"><apex:commandButton value="Find" action="{!find}"/></td>
        </tr>       
      </table>
      
    </apex:pageblock>
       
    <apex:pageBlock title="Search Result">
      <apex:pageblockTable value="{!memList}" var="a">
        <apex:column >
          <apex:outputlink value="https://na12.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
        </apex:column>
        <apex:column value="{!a.id}"/>
      </apex:pageBlockTable>    
    </apex:pageBlock>   
     
  </apex:form>
</apex:page>

Apex:

public class Search
{
 
  public String memName {get; set;}
 
  public List<Member__c>  memList {get; set;}
 
  public Search(ApexPages.StandardController controller)
  {
  }
 
  public void find()
  {
    String sql = 'SELECT Name,id FROM Member__c WHERE Name LIKE \'%'+memName+'%\' LIMIT 20';
    memList = Database.query(sql);
  } 
}


Can some one explain, How does this line works in the above code .
public Search(ApexPages.StandardController controller)
  {
  }
trigger Winning on Opportunity (before update) {
  for (Opportunity opp : Trigger.new) {
    // Access the "old" record by its ID in Trigger.oldMap
    Opportunity oldOpp = Trigger.oldMap.get(opp.Id);

    // Trigger.new records are conveniently the "new" versions!
    Boolean oldOppIsWon = oldOpp.StageName.equals('Closed Won');
    Boolean newOppIsWon = opp.StageName.equals('Closed Won');
   
    // Check that the field was changed to the correct value
    if (!oldOppIsWon && newOppIsWon) {
      opp.I_am_Awesome__c = true;
    }
  }
}

when I try to save the above code, iam getting error message Error Error: Compile Error: Invalid field I_am_Awesome__c for SObject Opportunity at line 13 column 7
 I have I_am_Awesome__c custom field in the oppurtunity object still I am getting the message, can some one help me on this?
Adderror method doesn't display error message, i tried the following Trigger.New[0].name.adderror('Duplicate entry found. There already exists an entry for the same Record. Please update the old one');
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();
}
}