• sandeep@dev
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi Guys below is my trigger,

trigger AgenciesCommission on Invoice_Line_Item__c (before Insert, before update) 
{

for(Invoice_Line_Item__c Ili: Trigger.New)
{
    Ili.Total_Agencies_commission__c=Ili.Agencies_commission__c;
    Ili.Gst_Amount__c=Ili.Total_Gst_Amount__c;
      
}

//Sandeep : To Update Days overflown to previous month functionality   : START
    
    if(trigger.isbefore )
        {
        if(triggerHelperRecursiveCheck.runOnce==true){
            map<string,integer> differentStartEndDateMap = new  map<string,integer>();
            set<Id> siteIds = new set<Id>();
            for(Invoice_Line_Item__c invLnItem: trigger.new)
            {
                if(invLnItem.Startdate__c.month() != invLnItem.EndDate__c.month()){
                    if(differentStartEndDateMap.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.EndDate__c.month())+string.valueOf(invLnItem.EndDate__c.year())) == null){
                        differentStartEndDateMap.put(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.EndDate__c.month())+string.valueOf(invLnItem.EndDate__c.year()),invLnItem.EndDate__c.day());
                    }                   
                }
                if(String.valueOf(invLnItem.SiteName__c).substring(0, 15) != null){
                    siteIds.add(String.valueOf(invLnItem.SiteName__c).substring(0, 15));
                }
            }
            map<string,integer> differentStartEndDateMapTemp = differentStartEndDateMap.clone();
            for(Invoice_Line_Item__c invLnItem: trigger.new)
            {
                if(differentStartEndDateMapTemp != null && differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year())) != null){
                    invLnItem.days_Overflow_from_Previous_Month__c = differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                    differentStartEndDateMapTemp.remove(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                }              
            }
            
            //updating Existing Records for days_Overflow_from_Previous_Month__c value - Start.
            differentStartEndDateMapTemp = differentStartEndDateMap.clone();
            if(siteIds != null && !siteIds.isEmpty()){
            System.debug('@@@@ KeySet'+differentStartEndDateMapTemp.keyset());
                list<Invoice_Line_Item__c> listinvLnItemsWithSiteIds =[select Name,Startdate__c,EndDate__c,Days_Inv_nxt_mnth__c,MMYYYYENDDATE__c,SiteName__c,SiteID_MMYYYYSTARTDATE__c from Invoice_Line_Item__c where SiteName__c IN : siteIds and SiteID_MMYYYYSTARTDATE__c in :differentStartEndDateMapTemp.keyset()];
                System.debug('#######'+listinvLnItemsWithSiteIds);
                if(listinvLnItemsWithSiteIds != null && !listinvLnItemsWithSiteIds.isEmpty()){
                    for(Invoice_Line_Item__c invLnItem: listinvLnItemsWithSiteIds)
                    {
                        if(differentStartEndDateMapTemp != null && differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year())) != null){
                            invLnItem.days_Overflow_from_Previous_Month__c = differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                            differentStartEndDateMapTemp.remove(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                        system.debug('$$$$$$$$$$$$$$$$$$'+invLnItem.days_Overflow_from_Previous_Month__c);                        
                        }                           
                        
                    }
                    
                }
                triggerHelperRecursiveCheck.runOnce=false;
                //update listinvLnItemsWithSiteIds;
                
            }
            //updating Existing Records for days_Overflow_from_Previous_Month__c value - End.
        }
    }
    //Sandeep : To Update Days overflown to previous month functionality : END
}

I'm not getting any error, i've also debugged ut it's assigning the value for " invLnItem.days_Overflow_from_Previous_Month__c " in debug also, but not updating the records. 

can anyone please suggest me y it's not.

Thanks in Advance,
Sandeep Kumar
HI Guys,

I want a formula like below.
eg Site XYZ: was booked for 7 days in total in February – formula looks to calendar to determine # days in month and account for leap year or not. The 7 days booked/ 29 days in leap year = 24.13% for Feb 2016/ If booking starts in previous month, or overflows to next month, the days in the previous and next month should not be calculated as part of the February occupancy. Eg starts 28 Feb so only 2 days BOOKED for Feb should count – 28 + 29 Feb

I wanted to showcase the same in report as below

User-added image

Right now I'm showing it as no of days booked b/w start and end dates based on start month. If it was booked b/w two months I want only those no of days booked in current month and remaining should go to next month. Any help is appreciated.

Thanks in Advance,
Sandeep Kumar

Hi,

 

I need a test class for below Trigger. Need to move it to production urgently. Any help is much appreciated.

 

trigger AutogenarateUsernamepassword on Account (before insert, before update)
{
Private Account[] acc = Trigger.new;
Private Contact c = new Contact();
Public Account accnt;
Public string fromAddress{get;set;}
Private List<Contact_Commitment__c> concomm = new List<Contact_Commitment__c>();
Private List<Contact_Commitment__c> concomm1 = new List<Contact_Commitment__c>();
List<String> characters = new List<String>{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'};
Public String txtdata='';


public Integer randomNumber(){
Integer random = Math.Round(Math.Random()* characters.Size());
if(random == characters.size()){
random--;
}
return random;
}

public String getChar1()
{
txtdata='';
for(integer i=0;i<6;i++)
{
txtdata+=characters[randomNumber()];

}
return txtdata.trim();
}

if(acc[0].Notify_Client__c=='Send Username/Password to Client')
{

for(Contact con : [Select id,Name,Email from Contact Where Id in (Select Contact_Name__c from Contact_Commitment__c Where Contact_Role__c = 'ACT - Client Primary Contact' and company_Name__c=:acc[0].Id)])
{
List<Login__c> check1= new List<Login__c>();
check1=[select Id,Account__c,Password__c,UserName__c,Contact__c from Login__c where Contact__c=: con.Id and Account__c =: acc[0].Id and Name='Client'];
if(check1.size()>0)
{
if(acc[0].Notify_Client__c=='Send Username/Password to Client')
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<EmailTemplate> emailTemp=[Select Subject, Name, HtmlValue, FolderId, DeveloperName, Body From EmailTemplate where developername =:'Password_retrieval'];
string sBody='';
if(emailTemp.size() > 0)
{
sBody=emailTemp[0].Body;
if(sBody != '' || sBody != '')
{
sBody=sBody.replace('FullName', con.Name);
sBody=sBody.replace('$UName$',check1[0].UserName__c);
sBody=sBody.replace('$PWD$',check1[0].Password__c);
}
}

String[] toAddresses= new String[] {con.Email};
List<OrgWideEmailAddress> orgEmailAdd = [Select Id, DisplayName, Address From OrgWideEmailAddress where DisplayName =:'Stanford ACT' limit 1];
if(orgEmailAdd.size()>0)
{
fromAddress = orgEmailAdd[0].Id;
}
// Assign the addresses for the To list to the mail object.
mail.setToAddresses(toAddresses);
mail.setOrgWideEmailAddressId(fromAddress);
if(emailTemp.size() > 0)
mail.SetSubject(emailTemp[0].subject);
mail.setUseSignature(false);
mail.setPlainTextBody(sBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

accnt = acc[0];
accnt.Notify_Client__c = 'Username/Password Sent';
}
}
else
{

if(acc[0].Notify_Client__c=='Send Username/Password to Client')
{
Login__c check= new Login__c();
check.Name='Client';
check.Account__c=acc[0].Id;
check.Contact__c=con.Id;
check.UserName__c=con.Email;
check.Password__c=getChar1();
insert check;

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<EmailTemplate> emailTemp=[Select Subject, Name, HtmlValue, FolderId, DeveloperName, Body From EmailTemplate where developername =:'Client_New_Credentials'];
string sBody='';
if(emailTemp.size() > 0)
{
sBody=emailTemp[0].Body;
if(sBody != '' || sBody != '')
{
sBody=sBody.replace('FullName', con.Name);sBody=sBody.replace('$UName$',check.UserName__c);sBody=sBody.replace('$PWD$',check.Password__c);

}
}


List<OrgWideEmailAddress> orgEmailAdd = [Select Id, DisplayName, Address From OrgWideEmailAddress where DisplayName =:'Stanford ACT' limit 1];
if(orgEmailAdd.size()>0)
{
fromAddress = orgEmailAdd[0].Id;
}
String[] toAddresses= new String[] {con.Email};
// Assign the addresses for the To list to the mail object.
mail.setOrgWideEmailAddressId(fromAddress);
mail.setToAddresses(toAddresses);
if(emailTemp.size() > 0)
mail.SetSubject(emailTemp[0].subject);
mail.setUseSignature(false);
mail.setPlainTextBody (sBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

accnt = acc[0];
accnt.Notify_Client__c = 'Username/Password Sent';
}
}
}
}

}

 

Thanks in Advance

 

Hi there
   any one answer this qstn and solve dis problem
while creating a vf page on IDE I am getting dis error

Multiple annotations found at this line:
- Save error: Unable to perform save on all files: 
com.salesforce.ide.api.metadata.types.Metadata$JaxbAccessorF_fullName cannot be cast to 
com.sun.xml.internal.bind.v2.runtime.reflect.Accessor
- File only saved locally, not to server


solve dis and answer me
Hi Guys below is my trigger,

trigger AgenciesCommission on Invoice_Line_Item__c (before Insert, before update) 
{

for(Invoice_Line_Item__c Ili: Trigger.New)
{
    Ili.Total_Agencies_commission__c=Ili.Agencies_commission__c;
    Ili.Gst_Amount__c=Ili.Total_Gst_Amount__c;
      
}

//Sandeep : To Update Days overflown to previous month functionality   : START
    
    if(trigger.isbefore )
        {
        if(triggerHelperRecursiveCheck.runOnce==true){
            map<string,integer> differentStartEndDateMap = new  map<string,integer>();
            set<Id> siteIds = new set<Id>();
            for(Invoice_Line_Item__c invLnItem: trigger.new)
            {
                if(invLnItem.Startdate__c.month() != invLnItem.EndDate__c.month()){
                    if(differentStartEndDateMap.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.EndDate__c.month())+string.valueOf(invLnItem.EndDate__c.year())) == null){
                        differentStartEndDateMap.put(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.EndDate__c.month())+string.valueOf(invLnItem.EndDate__c.year()),invLnItem.EndDate__c.day());
                    }                   
                }
                if(String.valueOf(invLnItem.SiteName__c).substring(0, 15) != null){
                    siteIds.add(String.valueOf(invLnItem.SiteName__c).substring(0, 15));
                }
            }
            map<string,integer> differentStartEndDateMapTemp = differentStartEndDateMap.clone();
            for(Invoice_Line_Item__c invLnItem: trigger.new)
            {
                if(differentStartEndDateMapTemp != null && differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year())) != null){
                    invLnItem.days_Overflow_from_Previous_Month__c = differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                    differentStartEndDateMapTemp.remove(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                }              
            }
            
            //updating Existing Records for days_Overflow_from_Previous_Month__c value - Start.
            differentStartEndDateMapTemp = differentStartEndDateMap.clone();
            if(siteIds != null && !siteIds.isEmpty()){
            System.debug('@@@@ KeySet'+differentStartEndDateMapTemp.keyset());
                list<Invoice_Line_Item__c> listinvLnItemsWithSiteIds =[select Name,Startdate__c,EndDate__c,Days_Inv_nxt_mnth__c,MMYYYYENDDATE__c,SiteName__c,SiteID_MMYYYYSTARTDATE__c from Invoice_Line_Item__c where SiteName__c IN : siteIds and SiteID_MMYYYYSTARTDATE__c in :differentStartEndDateMapTemp.keyset()];
                System.debug('#######'+listinvLnItemsWithSiteIds);
                if(listinvLnItemsWithSiteIds != null && !listinvLnItemsWithSiteIds.isEmpty()){
                    for(Invoice_Line_Item__c invLnItem: listinvLnItemsWithSiteIds)
                    {
                        if(differentStartEndDateMapTemp != null && differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year())) != null){
                            invLnItem.days_Overflow_from_Previous_Month__c = differentStartEndDateMapTemp.get(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                            differentStartEndDateMapTemp.remove(String.valueOf(invLnItem.SiteName__c).substring(0, 15)+string.valueOf(invLnItem.Startdate__c.month())+string.valueOf(invLnItem.Startdate__c.year()));
                        system.debug('$$$$$$$$$$$$$$$$$$'+invLnItem.days_Overflow_from_Previous_Month__c);                        
                        }                           
                        
                    }
                    
                }
                triggerHelperRecursiveCheck.runOnce=false;
                //update listinvLnItemsWithSiteIds;
                
            }
            //updating Existing Records for days_Overflow_from_Previous_Month__c value - End.
        }
    }
    //Sandeep : To Update Days overflown to previous month functionality : END
}

I'm not getting any error, i've also debugged ut it's assigning the value for " invLnItem.days_Overflow_from_Previous_Month__c " in debug also, but not updating the records. 

can anyone please suggest me y it's not.

Thanks in Advance,
Sandeep Kumar