• sfdclive
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 6
    Replies

Hi Team,

 

Please help me in if condition.

 

I have contact who became user after approvals no  i am writing one trigger, in that i want to compare id of the user that is submitting the record with this user id.   

Hi,

 

I have a junction object linking account and contact, have a custom picklist field status on account. if account status equal to approved then the record should be shared to contact which is relation with account through junction object.

 

pls give me some help in writing trigger.

please help me in writing test coverage for this property

 

 

   public String sortDirection = 'ASC';
    public String sortExp = 'Model__r.ProductCategory__r.Name';
    public string sortFullExp;
    public String sortExpression
    {
        get
        {
            return sortExp;
        }
         set
        {
             //if the column is clicked on then switch between Ascending and Descending modes
             if (value == sortExp)
             sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
             else
             sortDirection = 'ASC';
             sortExp = value;
        }

global class AWACS_CreateMonthlyPromoterTarget implements Database.Batchable<sObject>{
  
    Integer flag;  
    Integer flagPrevQty;    
    Double PrevActSlQty;
    Double PrevSlTgtQty;
    
   
    date d;
    date dPrev;
    String currMonth;
    String prevMonth;   

   
    Promoter_Product_Target__c targetObj;                    
    List  <Promoter_Product_Target__c>  lstTarget = new List<Promoter_Product_Target__c>();     
    List  <Promoter_Product_Target__c>  lstTargetofPSP = new List<Promoter_Product_Target__c>();
    List  <Promoter_Product_Target__c>  lstNewTarget= new List  <Promoter_Product_Target__c>() ;         
    Map<ID,List<Promoter_Product_Target__c>> mapPSPTarget = new Map<Id,List<Promoter_Product_Target__c>>();   
    
     
    Global String query='Select Id, Name,(select Id,Name,Month__c,Month_Actual_Sales_Quantity__c,Sales_Target_Quantity__c from Promoter_Product_Target__r) from Delar_Promoter_Shop_Products__c where RecordType.DeveloperName=\'Promoter_Shop_Products\''; 

    Global   AWACS_CreateMonthlyPromoterTarget () {     
        d=get_Sales_Target_Month(AWACS_Cutoff_day());
        system.debug('sales Target month##'+d);
        dPrev=d.addMonths(-1);
        system.debug('sales Target prcmonth##'+dPrev);
        currMonth= DateTime.newInstance(d, Time.newInstance(0, 0, 0, 0)).format('MMMM-yyyy'); 
        prevMonth= DateTime.newInstance(dPrev, Time.newInstance(0, 0, 0, 0)).format('MMMM-yyyy'); 
        
    }
       
    Global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator(query);    
    }   
    
    Global void execute(Database.BatchableContext BC, List<sObject> scope){
    
        List <Delar_Promoter_Shop_Products__c> lstPSP = (List <Delar_Promoter_Shop_Products__c>) scope;    
            
        system.debug('size of lstPSP##'+lstPSP.size()+'###PSP List value##'+lstPSP);     
           
        for(Delar_Promoter_Shop_Products__c onePSP : lstPSP) {
            if(onePSP.Promoter_Product_Target__r != null){
                lstTarget=onePSP.Promoter_Product_Target__r;   
                system.debug('PSP Obj##'+onePSP.Name+'##lstTarget##'+lstTarget);         
                mapPSPTarget.put(onePSP.ID,lstTarget);             
                //lstTarget.clear();
            }
            else{
                
                targetObj= new Promoter_Product_Target__c();    
                targetObj.Promoter_Shop_Products__c= onePSP.ID ;
                targetObj.Month_Actual_Sales_Quantity__c = 0;             
                targetObj.Sales_Target_Quantity__c = 0; 
                targetObj.Previous_Actual_Sales_Quantity__c = 0; 
                targetObj.Previous_Sales_Target_Quantity__c = 0;          
                targetObj.Month__c = currMonth;                            
                lstNewTarget.add(targetObj);      
            }
         }   
              
        for(ID PSPId : mapPSPTarget.keyset()) { 
        
           flag=0;  
         
                               
           if(mapPSPTarget.get(PSPId) != null){
             
                 system.debug('Lst of Target##'+mapPSPTarget.get(PSPId));
           
                  lstTargetofPSP=mapPSPTarget.get(PSPId);                                
                  system.debug('List of Target###'+lstTargetofPSP)  ;
                   
                  for(Promoter_Product_Target__c oneTarget : lstTargetofPSP){ 
                    
                    system.debug('Target Object Name##'+oneTarget.Name+'#Target object month summary#'+oneTarget.Month__c+'###Prev month##'+prevMonth+'##Curr month##'+currMonth);
                    if(oneTarget.Month__c == prevMonth){
                        flagPrevQty=0;
                        PrevActSlQty=0;
                        PrevSlTgtQty=0;
                        
                        if(oneTarget.Month_Actual_Sales_Quantity__c != null)  {              
                            PrevActSlQty = oneTarget.Month_Actual_Sales_Quantity__c;
                            system.debug('Target Object Name##'+oneTarget.Name+'##Month Sale Qty###'+oneTarget.Month_Actual_Sales_Quantity__c+'##Prev Actual Sale Qty###'+PrevActSlQty);}
                        
                            
                        if(oneTarget.Sales_Target_Quantity__c != null)    {
                            PrevSlTgtQty=oneTarget.Sales_Target_Quantity__c;
                             system.debug('Target Object Name##'+oneTarget.Name+'##Month Sale Qty###'+oneTarget.Sales_Target_Quantity__c+'##Prev Sale Target Qty###'+PrevSlTgtQty);}
                     
                        
                            
                        flagPrevQty=1;
                 }
                 
                if (oneTarget.Month__c == currMonth){                                
                        flag=1; 
                        system.debug('Target Object Name##'+oneTarget.Name+'#Target object month summary#'+oneTarget.Month__c);
                  
                    }                                                                   
                }     
                system.debug('Value of flag##'+flag);
                                       
                if(flag == 0){
                    targetObj= new Promoter_Product_Target__c();    
                    targetObj.Promoter_Shop_Products__c= PSPId ;                      
                    targetObj.Month__c = currMonth; 
                    
                    if (flagPrevQty==1){
                    
                         system.debug('#Target objectPrevious_Actual_Sales_Quantity__c#'+PrevActSlQty);                  
                        targetObj.Previous_Actual_Sales_Quantity__c=PrevActSlQty; 
                        system.debug('#Target objectPrevious_Actual_Sales_Quantity__c#'+targetObj.Previous_Actual_Sales_Quantity__c);
                  
                        system.debug('#Target objectPrevious_Actual_Sales_Quantity__c#'+PrevSlTgtQty);                 
                        targetObj.Previous_Sales_Target_Quantity__c=PrevSlTgtQty;
                        system.debug('#Target objectPrevious_Actual_Sales_Quantity__c#'+targetObj.Previous_Sales_Target_Quantity__c);
                  
                    } 
                    else{
                     
                        targetObj.Previous_Sales_Target_Quantity__c = 0;
                        targetObj.Previous_Actual_Sales_Quantity__c= 0; 
                    }
                        
                    targetObj.Month_Actual_Sales_Quantity__c=0; 
                    targetObj.Sales_Target_Quantity__c=0;           
                   
                    lstNewTarget.add(targetObj);                              
                } 
          }           
        }
        
        system.debug('#Size of Target list to be updated in DB#'+lstNewTarget.size());
        
        if(lstNewTarget.size()>0){
            insert  lstNewTarget;  }

    }
          
    Global void finish(Database.BatchableContext BC){
    }
    
    public integer AWACS_Cutoff_day()
    {
        Upload_Settings__c settings=Upload_Settings__c.getInstance('Cutoff_day');
        if(settings.Cutoff_day__c!=null)
        {
            return integer.valueOf(settings.Cutoff_day__c);
        }
        else
        {
            //in cutoff day is 0 then we need to take cutoff date as month last day
              date startofmonth=date.today().toStartOfMonth();
                date endofmonth=startofmonth.addMonths(1).adddays(-1);
                
            return endofmonth.day();
                
        }
        
        return 0;
    }
    
    public date get_Sales_Target_Month(integer cutoffday)
    {
        
        Date dt=date.today();
        integer today=dt.day();
        if(today>=cutoffday)
        {
            return dt.addMonths(1);
        }
        return dt;
    }
    
    
}
public id emailtemplateid{get;set;}
//private final ApexPages.StandardController thecontroller;
public List<SelectOption> emailtemplates {
    get {
      if (emailtemplates == null) {
       emailtemplates = new List<SelectOption>();
        emailtemplates.add(new SelectOption('00Xf0000000Hzi9','Dealer Source - TEST'));
        emailtemplates.add(new SelectOption('00Xf0000000I0MT','News Snapshot'));
      }
      return emailtemplates;
    }
    set;
  }

Hi,

i want emailtempaltes as dropdown list , here i hardcoded emailtempalte ids for dropdown. please suggest me the code with out hard coding.

Please tell me the code  for  page refreshment after saving a record in visualforce page.

 

 

System.ListException: List index out of bounds: 0

Error is in expression '{!send}' in component <apex:commandButton> in page emailprocessingauto


    Messaging.singleEmailMessage email = new Messaging.singleEmailMessage();
    EmailTemplate Templates = [Select Id, Name, IsActive, Folder.Name,subject
                               From EmailTemplate  where Folder.Name ='DRM Email Templates' and id = :emailtemplateid];
   
    email.setToAddresses( toAddresses );

email.setTemplateID(Templates.Id);
email.settargetObjectId(contactList[0].Id);

 Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.singleEmailMessage[] {email});
return null;

 

 

please tell me how to resolve it .

Hi All,

 

I have four Recordtypes for  Account like AC1, AC2, AC3 , AC4 and four recordtypes for Account contacts, i need to import Data

Using Data loader.

 

I have csv files for  AC1  type records and  its contact,AC2  type records and  its contact like that.

 

Please tell me the query to import records using data loader

Hi,

Pls let me know where did i make a mistake. its urgent.

     when i click on send email button it is showing error at multiselect picklist field

Error: j_id0:j_id1:j_id3:Distribution_List: An error occurred when processing your submitted information.

 

 public class sendingemail {
Public String subject{get;set;}
Public String body{get;set;}
Public List<Contact> contactlist;
    public sendingemail(ApexPages.StandardController controller) {
//contact = [select name, lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    public List<Contact> getContact() {
return contactlist;
}
    public PageReference send() {
    contactlist =[select lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where Opt_out_Email__c = false and Distribution_List__c='DL1;DL2'];
    // Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// Sets the paramaters of the email
String addresses;
if (Contactlist[0].Email != null)
{
addresses = Contactlist[0].Email;
// Loop through the whole list of contacts and their emails
for (Integer i = 1; i < Contactlist.size(); i++)
{
if (Contactlist[i].Email != null)
{
addresses += ':' + Contactlist[i].Email;
}
}
}
String[] toAddresses = addresses.split(':', 0);
email.setSubject( subject );
email.setToAddresses(toAddresses);
email.setPlainTextBody( body );
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
    }

}

this is my page.

<apex:page StandardController="Contact" extensions="sendingemail">
<apex:pageBlock title="Send an Email to Your
{!Contact.name}">
<p>Please choose the distribution List</p>
<br />
<apex:form >
<br /><br />
<apex:outputLabel value="Distribution_Lists" for="Distribution_List"/>:<br />
<apex:inputfield value="{!Contact.Distribution_List__c}" />
<br /><br />
<apex:outputLabel value="Subject" for="Subject"/>:<br />
<apex:inputText value="{!subject}" id="Subject" maxlength="80"/>
<br /><br />
<apex:outputLabel value="Body" for="Body"/>:<br />
<apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/>
<br /><br />

<br />
<apex:commandButton value="Send Email" action="{!send}" />
</apex:form>

 </apex:pageBlock>
</apex:page>

 

 

Regards

Sri

Hi,

Pls let me know where did i make a mistake. its urgent.

     when i click on send email button it is showing error at multiselect picklist field

Error: j_id0:j_id1:j_id3:Distribution_List: An error occurred when processing your submitted information.

 

 public class sendingemail {
Public String subject{get;set;}
Public String body{get;set;}
Public List<Contact> contactlist;
    public sendingemail(ApexPages.StandardController controller) {
//contact = [select name, lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    public List<Contact> getContact() {
return contactlist;
}
    public PageReference send() {
    contactlist =[select lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where Opt_out_Email__c = false and Distribution_List__c='DL1;DL2'];
    // Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// Sets the paramaters of the email
String addresses;
if (Contactlist[0].Email != null)
{
addresses = Contactlist[0].Email;
// Loop through the whole list of contacts and their emails
for (Integer i = 1; i < Contactlist.size(); i++)
{
if (Contactlist[i].Email != null)
{
addresses += ':' + Contactlist[i].Email;
}
}
}
String[] toAddresses = addresses.split(':', 0);
email.setSubject( subject );
email.setToAddresses(toAddresses);
email.setPlainTextBody( body );
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
    }

}

this is my page.

<apex:page StandardController="Contact" extensions="sendingemail">
<apex:pageBlock title="Send an Email to Your
{!Contact.name}">
<p>Please choose the distribution List</p>
<br />
<apex:form >
<br /><br />
<apex:outputLabel value="Distribution_Lists" for="Distribution_List"/>:<br />
<apex:inputfield value="{!Contact.Distribution_List__c}" />
<br /><br />
<apex:outputLabel value="Subject" for="Subject"/>:<br />
<apex:inputText value="{!subject}" id="Subject" maxlength="80"/>
<br /><br />
<apex:outputLabel value="Body" for="Body"/>:<br />
<apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/>
<br /><br />

<br />
<apex:commandButton value="Send Email" action="{!send}" />
</apex:form>

 </apex:pageBlock>
</apex:page>

 

 

Regards

Sri

Hi,

I created some distrubution lists using custom settings, in each distribution list i have email field,created 10 records for each distribution list,.

 

I need to send automatic emails based on email templates on scheduled base.

 

 

please help how to write code for this

 

hi,

here is my trigger, please give me a test class

 

trigger UpdateProductRecordType on OpportunityLineItem (after insert)
{
    Set<String> oppLineItemIds = new Set<String>();
    
     for(OpportunityLineItem oppLineItem : Trigger.new)
     {
         oppLineItemIds.add(oppLineItem.Id);
     }
     List<OpportunityLineItem> oppLineItems = new List<OpportunityLineItem>();
     
     for(OpportunityLineItem oppLineItem : [select Opportunity.RecordType.Name, RecordType__c from OpportunityLineItem where Id in :oppLineItemIds])
     {
          oppLineItem.RecordType__c = oppLineItem.Opportunity.RecordType.Name;
          oppLineItems.add(oppLineItem);
     }
     if(oppLineItems.size() > 0)
     {
          update oppLineItems;
     }
}





please help me how to write test class for this trigger

 

trigger UpdateProductRecordType on OpportunityLineItem (after insert)
{
    Set<String> oppLineItemIds = new Set<String>();
    
     for(OpportunityLineItem oppLineItem : Trigger.new)
     {
         oppLineItemIds.add(oppLineItem.Id);
     }
     List<OpportunityLineItem> oppLineItems = new List<OpportunityLineItem>();
     
     for(OpportunityLineItem oppLineItem : [select Opportunity.RecordType.Name, record_type_c__c from OpportunityLineItem where Id in :oppLineItemIds])
     {
          oppLineItem.record_type_c__c = oppLineItem.Opportunity.RecordType.Name;
          oppLineItems.add(oppLineItem);
     }
     if(oppLineItems.size() > 0)
     {
          update oppLineItems;
   }

}

 

the below test class is not covering my trigger 

test class:

 

@isTest
Private class UpdateProductRecordType_test
{
static testMethod void testUpdateProductRecordType()
{
RecordType rt = [select id,Name from RecordType where SobjectType='opportunity' and Name='A' Limit 1];
Opportunity o = new Opportunity(Name = 'Test' , StageName ='Closed Won' , CloseDate = Date.today());
insert o;

Product2 p = new Product2(Name = 'productname');
insert p;

Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];

Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
insert pb;
Product2 prod = new Product2(Name = 'productname', Family = 'Best Practices' , IsActive = true);
insert prod;

PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = standardPB.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
insert standardPrice;


OpportunityLineItem ol = new OpportunityLineItem(OpportunityId = o.id , record_type_c__c ='oppotunity b',
PricebookEntryId = standardPrice.id);
insert ol;
}

 

 

 

 

regards

sri

 

 

Hi, 

Iam very new to salesforce please help me for the below senario, please its urgent.

 

I have an opportunity object which have record types opportunity a, opportunity b, when ever i choose the price book for opportunity a record type, then in product it shows the opportunity a in one custom field, for that i created a picklist field on opportunity 

 

please help how to write the trigger for it, on which object we should write the trigger

 

regards

sri

 

hi,

i have 50 custom labels. i want to dispaly all custom labels with values in salesforce

please help me

 

 

 

regards

sri

Hi

Iam very new to salesforce, please help me on this

 

I have 3 fields in salesforce, one field is picklist field it containing 3 objects if we select one object from this picklict field. after saving it will display the records 

of that object with remaining 2 feild values

 

please help me

 

thanks&regards

sri

 

 

Hi,

I have one object(account) with a picklist field location__c having values us,uk,india,china. if i select any picklist value,  records will be displayed as a table

 

please help me, I am new to salesforce

 

 

regards

sri

 

 

Hi,

Iam perty new to salesforce.com and here is my question.

How to upsert the related record fields when we are upserting the primary object record by using data loader , please explain me with example 

 

 

thanks@regards

sri

Hi,

 

I want to export my custom_object__c by using data loader and it is related with opportunity.

 

if i am exporting the cutom_object__c i need to export the opportunity record which is related to that custom_object__c 

 

please tell me the sutable query

 

thanks

sri

 

Hi,

Pls let me know where did i make a mistake. its urgent.

     when i click on send email button it is showing error at multiselect picklist field

Error: j_id0:j_id1:j_id3:Distribution_List: An error occurred when processing your submitted information.

 

 public class sendingemail {
Public String subject{get;set;}
Public String body{get;set;}
Public List<Contact> contactlist;
    public sendingemail(ApexPages.StandardController controller) {
//contact = [select name, lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    public List<Contact> getContact() {
return contactlist;
}
    public PageReference send() {
    contactlist =[select lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where Opt_out_Email__c = false and Distribution_List__c='DL1;DL2'];
    // Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// Sets the paramaters of the email
String addresses;
if (Contactlist[0].Email != null)
{
addresses = Contactlist[0].Email;
// Loop through the whole list of contacts and their emails
for (Integer i = 1; i < Contactlist.size(); i++)
{
if (Contactlist[i].Email != null)
{
addresses += ':' + Contactlist[i].Email;
}
}
}
String[] toAddresses = addresses.split(':', 0);
email.setSubject( subject );
email.setToAddresses(toAddresses);
email.setPlainTextBody( body );
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
    }

}

this is my page.

<apex:page StandardController="Contact" extensions="sendingemail">
<apex:pageBlock title="Send an Email to Your
{!Contact.name}">
<p>Please choose the distribution List</p>
<br />
<apex:form >
<br /><br />
<apex:outputLabel value="Distribution_Lists" for="Distribution_List"/>:<br />
<apex:inputfield value="{!Contact.Distribution_List__c}" />
<br /><br />
<apex:outputLabel value="Subject" for="Subject"/>:<br />
<apex:inputText value="{!subject}" id="Subject" maxlength="80"/>
<br /><br />
<apex:outputLabel value="Body" for="Body"/>:<br />
<apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/>
<br /><br />

<br />
<apex:commandButton value="Send Email" action="{!send}" />
</apex:form>

 </apex:pageBlock>
</apex:page>

 

 

Regards

Sri

Hi,

I created some distrubution lists using custom settings, in each distribution list i have email field,created 10 records for each distribution list,.

 

I need to send automatic emails based on email templates on scheduled base.

 

 

please help how to write code for this

 

Hi, 

Iam very new to salesforce please help me for the below senario, please its urgent.

 

I have an opportunity object which have record types opportunity a, opportunity b, when ever i choose the price book for opportunity a record type, then in product it shows the opportunity a in one custom field, for that i created a picklist field on opportunity 

 

please help how to write the trigger for it, on which object we should write the trigger

 

regards

sri

 

hi,

i have 50 custom labels. i want to dispaly all custom labels with values in salesforce

please help me

 

 

 

regards

sri