• Nikhil Somvanshi
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 7
    Replies
I tried googling but couldn’t find a clear answer to what all emails that are sent from Salesforce count against the SingleEmailLimit of 5000 per day. Does workflow rule e-mail alerts count against this limit? If we have multiple additional addresses would that count against the limit too ? Thanks in advance.
Hello Guys!

I am trying to create a functionality in which the i have a list of child records on edit page of parent object. In this list, i have an Edit and Delete button for every record. Deleting the child records is working well but i have issues with Edit, when Edit is clicked, it leads to nowhere. Below is my code. I have a bet on id is not captured by controller method. Please help!
 
Page:

<apex:page standardController="Account" tabStyle="Account" extensions="ContactExtension">
 <apex:form > 
    <apex:pageblock title="Custom Edit Account Page">
        <apex:pageBlockSection title="Information" columns="2">
            <apex:inputField value="{!Account.Name}">
                <apex:param name="AccountId" value="{!Account.Id}"/>
            </apex:inputfield>
            <apex:inputField value="{!Account.Type}"/>
            <apex:inputField value="{!Account.Industry}"/>
            <apex:inputField value="{!Account.AnnualRevenue}"/>
            <apex:inputField value="{!Account.Status__c}"/>
            <apex:inputField value="{!Account.Completion_Status_For_Opportunity__c}"/>
            <apex:inputField value="{!Account.Rating}"/>
            <apex:inputField value="{!Account.Fax}"/>
            <apex:inputField value="{!Account.Phone}"/>
            <apex:inputField value="{!Account.Website}"/>
            <apex:inputField value="{!Account.Ownership}"/>
            <apex:inputField value="{!Account.NumberOfEmployees}"/>
       </apex:pageBlockSection>
       
       <apex:pageBlockSection title="Address Information" columns="2">
   <!-- <apex:panelGrid columns="1"> !-->
            <apex:inputField value="{!Account.BillingStreet}"/>
            <apex:inputField value="{!Account.BillingCity}"/>
            <apex:inputField value="{!Account.BillingState}"/>
            <apex:inputField value="{!Account.BillingPostalCode}"/>
            <apex:inputField value="{!Account.BillingStreet}"/>
            <apex:inputField value="{!Account.BillingCountry}"/>
   <!-- </apex:panelGrid> --!>  
       
   <!-- <apex:panelGrid columns="1"> !-->
            <apex:inputField value="{!Account.ShippingStreet}"/>
            <apex:inputField value="{!Account.ShippingCity}"/>
            <apex:inputField value="{!Account.ShippingState}"/>
            <apex:inputField value="{!Account.ShippingPostalCode}"/>
            <apex:inputField value="{!Account.ShippingStreet}"/>
            <apex:inputField value="{!Account.ShippingCountry}"/>
  <!--  </apex:panelGrid> !-->  
       </apex:pageBlockSection>
       
       <apex:pageBlocksection title="Additional Information">
           <apex:inputField value="{!Account.CustomerPriority__c}"/>
           <apex:inputField value="{!Account.SLAExpirationDate__c}"/>
           <apex:inputField value="{!Account.NumberofLocations__c}"/>
           <apex:inputField value="{!Account.SLASerialNumber__c}"/>
           <apex:inputField value="{!Account.SLA__c}"/>
           <apex:inputField value="{!Account.UpsellOpportunity__c}"/>
       </apex:pageBlocksection>
       
       <apex:pageBlockSection title="Description">
           <apex:inputField value="{!Account.Description}"/>
       </apex:pageBlockSection> 
       
   <apex:pageBlockButtons location="Top">
       <apex:commandButton value="Save" Action="{!Save}"/>
       <apex:commandButton value="Cancel" Action="{!Cancel}"/>
   </apex:pageBlockButtons>
   
   <apex:pageBlockSection title="Related Contacts">
   
   </apex:pageBlockSection>
   <apex:commandButton value="Display Contacts" action="{!Check}" reRender="ajax" id="actionRender"/>
   
       <apex:pageBlockTable value="{!Conlist}" var="c" id="ajax">
           <apex:column headerValue="Action">
               <apex:commandButton value="Edit">
                   <apex:actionSupport event="onchange" action="{!EditRedirect}" >
                   <apex:param value="{!c.Id}" name="ContactToEdit"/>
                   </apex:actionSupport>
               </apex:commandButton>
           
               <apex:commandButton value="Delete" action="{!deletecontact}" reRender="ajax">
                   <apex:param value="{!c.id}" name="ContactToDelete"/>
               </apex:commandButton>
           </apex:column> 
           
           <apex:column value="{!c.Name}"/> 
           <apex:column value="{!c.Phone}"/>   
           <apex:column value="{!c.Active__c}"/>    
                
   </apex:pageblock>
 </apex:form>
</apex:page>

Class:

public class ContactExtension {

Public List<Contact> Conlist {set;get;}
Public String AccId {get;set;}
Public String var;

Public ContactExtension(ApexPages.StandardController sc)
{
    AccId = ApexPages.CurrentPage().getParameters().get('AccountId');
}

Public void Check()
{
    Conlist = [select id,name,Phone,Active__c from Contact where AccountId=:AccId];
}

Public void deletecontact()
{
    String ConId = ApexPages.CurrentPage().GetParameters().Get('ContactToDelete');
   
    List <Contact> ContactList = [select id,name from contact where id =: ConId];
    
    Delete ContactList;
    Check();
    
}

Public Boolean newId{get;set;}

Public PageReference EditRedirect()
{    
    var = ApexPages.CurrentPage().GetParameters().Get('ContactToEdit');
    
    return new Pagereference ('/'+var+'/e').setredirect(true);

}

}

 

Hello Community,

I am trying to create a Visualforce page that has single-select radio button in front of every record. When user selects a particular record's radio button and clicks create task, it creates a task and associates it with the corresponding Account. So far i am not able to figure out why it is not working. My guess is that the parameters are not able to travel from page to class method. Please help! Code below:

 

Visualforce Page:

<apex:page controller="AccountTask">
  <apex:form >
      <apex:pageBlock title="Page that creates Tasks">
          <apex:pageBlockTable value="{!Acclist}" var="ac">
          
              <apex:column value="{!ac.name}" id="name"/>
              <apex:column value="{!ac.phone}"/>
              <apex:column value="{!ac.type}"/>
              <apex:column value="{!ac.SLAExpirationDate__c}"/>
              
              <apex:column headerValue="Select to Create Task" id="task">
              
                 <apex:actionSupport event="onclick" rerender="pbs2"> 
                     <input type="radio" name = "newselect">
                         <apex:param name="SelectedAccountId" value="{!ac.Id}"/>
                         <apex:param name="SelectedAccountName" value="{!ac.name}"/>
                     </input>
                 </apex:actionSupport>
                  
              </apex:column>
              
              <apex:column headerValue="Action">
              <apex:commandButton value="Create Task" action="{!CreateTask}"/>
              </apex:column>          
          </apex:pageBlockTable>
          
          <apex:pageBlockSection id="pbs2" > <!-- Just to check what values are assigned to the parameter variables !-->
          Id: {!$CurrentPage.Parameters.SelectedAccountId} 
          <br></br>
          Name: {!$CurrentPage.Parameters.SelectedAccountName}
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

Controller Class:

public class AccountTask 
{
Public List<Account> Acclist {set;get;} 
Public string AccId {set;get;}

Public AccountTask ()
{
Acclist = [select name,phone,type,Create_Task__c,SLAExpirationDate__c from Account where SLAExpirationDate__c != NULL];
}

Public void CreateTask ()
{
AccId = System.CurrentPageReference().getParameters().get('SelectedAccountId');

Task t = new Task ();

t.WhatId = AccId;
t.Subject = 'New VF Task';
t.Description = 'Gibberish'; 
insert t;

}
}

Hello Community,

I am very confused on how Rendered attribute would work for the case: I want to display a Field B only if another Field A (which is a Picklist of 'Yes' and 'No') is set as Yes, on my Visualforce page. I want someone please share a basic example on how to go about it.

Hello People,

 

I am new here to Visualforce and trying to save the following program to show a list Objects based on the selected value from a List. I am getting an Error: ListPageClass Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Boolean, String) at line 18 column 16.

 

//Class

Public class ListPageClass {

Public ListPageClass()
{
ObjectList = new List<SelectOption>();

}

Public List<SelectOption> ObjectList {get;set;}
Public Boolean AccountCheck {get;set;}
Public Boolean ContactCheck {get;set;}
Public Boolean OpportunityCheck {get;set;}
Public Boolean Checkvalue {get;set;}

Public List<selectoption> getDisplaylist ()
{
 
ObjectList.add(new SelectOption(AccountCheck,'Account'));
ObjectList.add(new SelectOption(ContactCheck,'Contact'));
ObjectList.add(new SelectOption(OpportunityCheck,'Opportunity'));

return ObjectList;
}
}

Visualforce Page:
 
<apex:page controller="ListPageClass" >
<apex:form >
<apex:pageBlock >
<apex:selectList value="{!Checkvalue}">
<apex:selectOption value="{!Displaylist}">
</apex:selectOption>
</apex:selectList>
</apex:pageBlock>
</apex:form>
</apex:page>
Any pointers in the right direction would be gladly appreciated.

Hello Masters,

My requirement here is to create a Trigger on Contact which, in case of change of record ownership, populates a field Previously Owned By with name of the previous owner of the record. Please find my code below and reflect some suggestions to make it work correctly.

trigger PreviousOwnerPopulate on Contact (before update) 
{
Set <ID> PreviousId = new Set<ID>();

for (contact co: trigger.new)
{
for (Contact con: trigger.old)
{

if(co.OwnerID != con.OwnerID)
{
PreviousId.add(con.OwnerID);
}
}

}

map<id,string> mapforPreviousIdname = new map<id,string> ();

for (User u : [select id, name from User where id in:PreviousId])
{
mapforPreviousIdname.put(u.id,u.name);
}

for (contact c : trigger.new)

if (mapforPreviousIdname.size() > 0 )
{
c.Previously_Owned_By__c = mapforPreviousIdname.get(c.OwnerID);
}

Hello Community,

My requirement is to display a field Provided_Cash_Amount__c if another field Cash_Provided__c only if it is populated as  'Yes'. I believe I can do it using Rendered, which I tried but couldn't get to work. Please look at the code below:

Visualforce Page:

<apex:page standardController="Response_Action_Plan__c" extensions="RapSaver"  tabStyle="Response_Action_Plan__c">
<apex:form >
<apex:pageBlock >
<apex:sectionHeader title="New Response Action Plan" />
<apex:pageBlockSection title="Information" collapsible="False" columns="1">

<apex:inputField value="{!RAP.name}"/>
<apex:inputField value="{!RAP.Disaster__c}"/>
<apex:inputField value="{!RAP.Causalities_Attended__c}"/> 
<apex:inputField value="{!RAP.Staff_Allotted_Offshore__c}"/>
<apex:inputField value="{!RAP.Staff_Onsite__c}"/>
<apex:inputField value="{!RAP.Onsite_Staff_Count__c}"/>
<apex:inputField value="{!RAP.Blankets_Provided__c}"/>
<apex:inputField value="{!RAP.Number_of_Blankets_Provided__c}"/>
<apex:inputField value="{!RAP.Cash_Provided__c}"/> 
<apex:inputField value="{!RAP.Provided_Cash_Amount__c}" rendered="{!IF(RAP.Cash_Provided__c = 'Yes', true, false)}"/>


</apex:pageBlockSection>
<apex:pageblockbuttons location="Bottom" >
<apex:commandbutton value="Save RAP" action="{!RapSaver}"/>
</apex:pageblockbuttons>
</apex:pageBlock>
</apex:form>
</apex:page>

Extension Class:

Public class RapSaver
{
Public Response_Action_Plan__c RAP{get;set;}
Public ApexPages.StandardController Stcl{get;set;}

Public RapSaver(ApexPages.StandardController str)  
{
Stcl = str;
}

Public RapSaver()                           
{
RAP = new Response_Action_Plan__c();
}

Public PageReference RapSaver()
{
insert RAP;

PageReference pg = new PageReference ('/a07?fcf=00B7F000009BsJx');
pg.SetRedirect(true);

return pg;

}

}


 

Hello Masters,

I am trying to write a trigger that is supposed to throw an error when a field Name is populated with a pre-existing value. Please have a look at my code below and advise. The code although saves successfully but doesn't work as desired.

Code Logic: 

if(trigger.IsInsert && trigger.IsUpdate)
{

List<Disasters__c> DisList = [select Id,Name from Disasters__c];

for (Disasters__c dis : Trigger.new)
{
    for (Disasters__c lis: DisList) 
    {
    
    if(lis.Name == dis.Name)
    {
    lis.Name.AddError('Name already exists. Try another name');
    }
}
 

Hello Guys,

Can anyone please give me a helpful explanation of when, how and why exactly do we use Trigger.Oldmap and Trigger.newMap.

Thanks in Advance!

Hello Masters,

I am writing the following Batch but not able to save it. It only ends up with the afore-stated error even though I have included the execute method perfectly to my knowledge. I am mentioning my Class code below and would appreciate any help.

Class:
Global class DisasterRapMonitor implements Database.Batchable <sObject>
{

Global Database.QueryLocator start (Database.BatchableContext BC)
{
String DisasterWithoutRap = 'Select id,name from Disaster__c where id NOT in (select DisasterId from Response_Action_Plan__c)';
return Database.getQueryLocator(DisasterWithoutRap);
}

Global void execute ( Database.BatchableContext BC,List<Disaster__c> Dis)
{
for (Disaster__c di:Dis)
    {
    Task tk = new Task ();
    tk.Subject = 'Need to be associated with a Response immediately. Please work it out.';
    tk.WhoId = di.Id;
    }
    
    Update Dis;
}

Global void finish (Database.BatchableContext BC)
{}

}

Hello All,

I have written a Trigger to abort creation of new opportunities at a certain condition and send an Email as a report to the admin. I am using a helper class-method to implement this. The trigger works fine (Aborts the process successfully), but i am not able to receive the email, even though the program saves without an error. Please take a quick look at my code:

Trigger:

trigger AmountLimitCheck on Opportunity (Before insert) {

If(Trigger.IsInsert)
{
OpportunityAmountLimitCheck.Opportunity_records(trigger.new);
}

}


Helper Class:

Public class OpportunityAmountLimitCheck
{

Public static void Opportunity_records(List <Opportunity> ops)
{
double Amount_op = 0;

    for(Opportunity op:[select Amount from Opportunity where CreatedDate = today])
    {
    Amount_op = Amount_op + op.Amount ;
    }
    
    for (Opportunity o: ops)
    {
    Amount_op = Amount_op + o.Amount;
    
        If (Amount_op > 100000)
        {
        o.addError('Daily Opportunity Amount limit exceeded');
        
        Messaging.SingleEmailMessage sendmail = new Messaging.SingleEmailMessage();
        
        List<String> Recepient= new List <String> ();
        
        {
        Recepient.add('nikhilsomvanshi08@gmail.com');
        }
        
        sendmail.SetToAddresses(Recepient);
        
        String emailbody = 'Dear ' +o.OwnerId ;
                          emailbody += 'Please note that your opportunities has reached daily limit.';
                          emailbody += 'You will now be restricted from creating any more opportunities';
        
        sendmail.SetHTMLBody(emailbody);
        sendmail.SetSubject('Opportunity Creation Error, Daily limit exceeded');
        
        Messaging.SendEmailResult[] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {sendmail});
        
        }
    } 
    
}

}

Hi People,
I am writing a simple code to refrain the user from deleting a record if it's active but getting the below error:

 Error: There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Cannot Delete".

Here is my code:
trigger DontDeleteIfActive on Position__c (before delete) {

if(trigger.isdelete)
{
for (Position__c pos : trigger.old)

{   

    if(pos.Active__c != null || pos.Active__c == True)
        pos.addError('Cannot Delete');
    
}
}

}
 

Hello Community,

I am very confused on how Rendered attribute would work for the case: I want to display a Field B only if another Field A (which is a Picklist of 'Yes' and 'No') is set as Yes, on my Visualforce page. I want someone please share a basic example on how to go about it.

Hello Community,

My requirement is to display a field Provided_Cash_Amount__c if another field Cash_Provided__c only if it is populated as  'Yes'. I believe I can do it using Rendered, which I tried but couldn't get to work. Please look at the code below:

Visualforce Page:

<apex:page standardController="Response_Action_Plan__c" extensions="RapSaver"  tabStyle="Response_Action_Plan__c">
<apex:form >
<apex:pageBlock >
<apex:sectionHeader title="New Response Action Plan" />
<apex:pageBlockSection title="Information" collapsible="False" columns="1">

<apex:inputField value="{!RAP.name}"/>
<apex:inputField value="{!RAP.Disaster__c}"/>
<apex:inputField value="{!RAP.Causalities_Attended__c}"/> 
<apex:inputField value="{!RAP.Staff_Allotted_Offshore__c}"/>
<apex:inputField value="{!RAP.Staff_Onsite__c}"/>
<apex:inputField value="{!RAP.Onsite_Staff_Count__c}"/>
<apex:inputField value="{!RAP.Blankets_Provided__c}"/>
<apex:inputField value="{!RAP.Number_of_Blankets_Provided__c}"/>
<apex:inputField value="{!RAP.Cash_Provided__c}"/> 
<apex:inputField value="{!RAP.Provided_Cash_Amount__c}" rendered="{!IF(RAP.Cash_Provided__c = 'Yes', true, false)}"/>


</apex:pageBlockSection>
<apex:pageblockbuttons location="Bottom" >
<apex:commandbutton value="Save RAP" action="{!RapSaver}"/>
</apex:pageblockbuttons>
</apex:pageBlock>
</apex:form>
</apex:page>

Extension Class:

Public class RapSaver
{
Public Response_Action_Plan__c RAP{get;set;}
Public ApexPages.StandardController Stcl{get;set;}

Public RapSaver(ApexPages.StandardController str)  
{
Stcl = str;
}

Public RapSaver()                           
{
RAP = new Response_Action_Plan__c();
}

Public PageReference RapSaver()
{
insert RAP;

PageReference pg = new PageReference ('/a07?fcf=00B7F000009BsJx');
pg.SetRedirect(true);

return pg;

}

}


 

Hello Masters,

I am trying to write a trigger that is supposed to throw an error when a field Name is populated with a pre-existing value. Please have a look at my code below and advise. The code although saves successfully but doesn't work as desired.

Code Logic: 

if(trigger.IsInsert && trigger.IsUpdate)
{

List<Disasters__c> DisList = [select Id,Name from Disasters__c];

for (Disasters__c dis : Trigger.new)
{
    for (Disasters__c lis: DisList) 
    {
    
    if(lis.Name == dis.Name)
    {
    lis.Name.AddError('Name already exists. Try another name');
    }
}
 

Hello Masters,

I am writing the following Batch but not able to save it. It only ends up with the afore-stated error even though I have included the execute method perfectly to my knowledge. I am mentioning my Class code below and would appreciate any help.

Class:
Global class DisasterRapMonitor implements Database.Batchable <sObject>
{

Global Database.QueryLocator start (Database.BatchableContext BC)
{
String DisasterWithoutRap = 'Select id,name from Disaster__c where id NOT in (select DisasterId from Response_Action_Plan__c)';
return Database.getQueryLocator(DisasterWithoutRap);
}

Global void execute ( Database.BatchableContext BC,List<Disaster__c> Dis)
{
for (Disaster__c di:Dis)
    {
    Task tk = new Task ();
    tk.Subject = 'Need to be associated with a Response immediately. Please work it out.';
    tk.WhoId = di.Id;
    }
    
    Update Dis;
}

Global void finish (Database.BatchableContext BC)
{}

}

Hello All,

I have written a Trigger to abort creation of new opportunities at a certain condition and send an Email as a report to the admin. I am using a helper class-method to implement this. The trigger works fine (Aborts the process successfully), but i am not able to receive the email, even though the program saves without an error. Please take a quick look at my code:

Trigger:

trigger AmountLimitCheck on Opportunity (Before insert) {

If(Trigger.IsInsert)
{
OpportunityAmountLimitCheck.Opportunity_records(trigger.new);
}

}


Helper Class:

Public class OpportunityAmountLimitCheck
{

Public static void Opportunity_records(List <Opportunity> ops)
{
double Amount_op = 0;

    for(Opportunity op:[select Amount from Opportunity where CreatedDate = today])
    {
    Amount_op = Amount_op + op.Amount ;
    }
    
    for (Opportunity o: ops)
    {
    Amount_op = Amount_op + o.Amount;
    
        If (Amount_op > 100000)
        {
        o.addError('Daily Opportunity Amount limit exceeded');
        
        Messaging.SingleEmailMessage sendmail = new Messaging.SingleEmailMessage();
        
        List<String> Recepient= new List <String> ();
        
        {
        Recepient.add('nikhilsomvanshi08@gmail.com');
        }
        
        sendmail.SetToAddresses(Recepient);
        
        String emailbody = 'Dear ' +o.OwnerId ;
                          emailbody += 'Please note that your opportunities has reached daily limit.';
                          emailbody += 'You will now be restricted from creating any more opportunities';
        
        sendmail.SetHTMLBody(emailbody);
        sendmail.SetSubject('Opportunity Creation Error, Daily limit exceeded');
        
        Messaging.SendEmailResult[] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {sendmail});
        
        }
    } 
    
}

}