• Gauravendra
  • 585 Points
  • Member since 2018
  • Salesforce Developer
  • https://graspsalesforce.blogspot.com/

  • Chatter
  • 18
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 91
help me with trigger code.
An object has FirstName and LastName field, if we try to create a record with same FristName and LastName, record should not create(throws error).
I have created an Aura component which is a table.
I wish to visualize it in the page of each contact, for example in the Details tab.
How can I do that?

-we are currently sending all the Invoices from the Platform to Salesforce (via the famous web-service)
-by having those invoices in SF, we can create reports
-but could we report on those invoice by simply doing an “api call” or something similar to the Platform instead of storing the data in SF (ie instead of duplicating in SF the data that is in the Platform)?
  • June 28, 2019
  • Like
  • 0
I would like to keep track of the instance names of orgs I am the administrator for without having to manually handle instance refreshes. Periodically querying those orgs would allow me to access a reletively up-to-date list of clients that are affected by issues listed on trust.salesforce.com.

Is this possible?
i dont see the option to manuallu share the lead to a user, how can i do it.
thansk for suggestion
HI Wondering if anyone can help a newbie here in trouble !  

I'm trying to write a test class for this class which uses an ivokable method callled by process builder. I'm getting the following error on the test class can anyone direct me as to where i'm going wrong ? 
: Compile Error: Method does not exist or incorrect signature: void invokeapexcallout(List<String>, List<Id>) from the type MakeApexCallout at line 29 column 28

Here is my class : 

public class MakeApexCallout {

   public static void invokeapexcallout(list<Account> acc) {

My Test Class 


public Class MakeApexCalloutTest {

static testMethod void CallOutTest() {


// Create Account
        Account acc = new Account();

        acc.Name = 'test Account';

        acc.Siret_Number__c = '42097142600035';
        insert acc;
           List<Id> AccountIds = new List<Id>(); 
           List<String> SiretNumbers= new List<String>();


           MakeApexCallout.invokeapexcallout(SiretNumbers, AccountIds);


Hi All,
      i want to develope a batch for my requirement is to Fetch All opportunities which  has recordtype =time rack , 
       and check if their name STARTS with  thier Related account's name then update name of opportunity  Should be in this format - {!Account.Name} : Opportunity Name and populate Opportunity's field Customer Type = 'End User' on opportunity.

Ex:  Opportunity name is ABC 1234 and account name is ABC  Than after running the batch OppName would become- ABC: 1234 and its customer type should become -'End User'
Im not sure how to get started unit test this method below.
private static double setAfterSave(Opportunity deal) { 
        double returnValue;
        if(deal.Restaurant__c) {            
          returnValue = deal.HVAC__c == null ? 0 : deal.HVAC__c;
        } else {
           returnValue = deal.HVAC__c == null ? 0 : deal.HVAC__c;
        return returnValue;
  • March 05, 2019
  • Like
  • 0
var action = component.get("c.fetchData");
   action.setCallback(this, function(response) {
                        var state = response.getState();
                        console.log("State " + state);
                        if (state === "SUCCESS") {
                            var storeResponse = response.getReturnValue();
                            component.set("v.Customer", storeResponse);
                            var Credit = storeResponse.field__c;
                            console.log("Credit  "+Credit);
                        } });

Not able to access "response.getReturnValue();" outside of setcallback, How to do that ?
  • June 08, 2018
  • Like
  • 0
Hi Guys - I have written a controller which is being used in an vf component. My issue is I need to display adresses comma seperated.
pls suggest 

public with sharing class DisplayList{ 
    public List<Address__c> Records {get; set;} 
    public DisplayList(){ 
    Records = [SELECT Name 
               FROM Address__c
               WHERE Billing_Account__c = :ApexPages.currentPage().getParameters().get('Id')];
vf component snippet
        <apex:repeat value="{!Records}" var="Record">
         <div><span>Service Addresses:</span><span><apex:outputText value="{!Record.Name}" escape="false"/></span></div>
I am trying to display the opportunitycontactroles list on an object (Deal_Desk_Request__c) related to the opportunity.  I am not getting errors when saving the code, but nothing is appearing in the visualforce page other than the headers.  I am new to apex/visualforce development and not sure what I am doing wrong.  Can someone please help?

Here is the visualforce page:
<apex:page standardcontroller="deal_desk_request__c" extensions="dealdeskcontactrole" >
  <apex:pageblock >
      <apex:pageblocktable value="{!roles}" var="role">
          <apex:column headervalue="Contact" >
                      <apex:outputfield value="{!role.contactid}"/>
          <apex:column headervalue="Role" >
                      <apex:outputfield value="{!role.role}"/>
          <apex:column headervalue="Primary" >
                      <apex:outputfield value="{!role.isprimary}"/>


Here is the extension class:
public with sharing class dealdeskcontactrole {
list<opportunitycontactrole> roles;
 public final Deal_Desk_Request__c DDR;
    public dealdeskcontactrole(ApexPages.StandardController controller) {
        this.DDR = (Deal_Desk_Request__c)controller.getRecord();

    public list<opportunitycontactrole> getroles() {
        list<opportunitycontactrole> roles = [select id, contactID, Role, Isprimary from opportunitycontactrole where Opportunityid =: DDR.Opportunity__r.id];
         return roles;
        catch(system.exception e){
        return null;

Hi Team,

I have amount__c in both contact and account . if account has many contacts  and i need to update highest amount of contacts and update that into account amount field ?

Ex : ABC account   Amount__c  =

       Contact1 :  T -- Amount__c = 500$
       Contact2 :  A -- Amount__c = 700$
       Contact3 :  B -- Amount__c =300$

now account amount__c need to update with 700$ . how can i acheive it using trigger
I have a requirement for PAN Number field should include 5 text, 4 Number and 1 Text characters should include for that i wrote validation rule.
Rule passed succesfully, but record is not saving in any formates. Can you please let me know the my mistake.

(REGEX( PAN_Number__c , "[A-Z][a-z]{5}[0-9]{4}[A-Z][a-z]{1}") ), 
LEN( PAN_Number__c) <> 10))

User-added image
Thanks in Advance!
Hi Guys,

I have a requirement ..i  need to create a visualforce page which will display all account names in custom picklist.
Please help me on this.

Thanks in Advance.
I want to develop a page which has two radio button as options : radio1  and radio2 . on click of radio1 a form of account should be avaialble and on click of radio2 a form of contact should be available. 

I have my code but on click of both radio button it is redirecting to contact page only. can u help me to solve my issue

<apex:page controller="AccController">
 <apex:form >
 <apex:pageBlock id="pgblk"> 
 <apex:selectRadio id="radioid" layout="pageDirection">
 <apex:selectOption  itemLabel="radio1" itemValue="1"></apex:selectOption>
 <apex:actionSupport event="onclick" action="{!AccForm}">
 <apex:selectOption itemLabel="radio2" itemValue="2"></apex:selectOption>
 <apex:actionSupport event="onclick" action="{!ContForm}">

Here is my controller
public class AccController 
 public PageReference AccForm()
 PageReference Page = new PageReference('/apex/CreateAcc');
 return Page;
 public PageReference ContForm()
 PageReference Page = new PageReference('/apex/CreateContact');
 return Page;
while saving 11th  record it should show an error while saving that limit had exceeded

I am trying to display a selectList in a visualforce page using a custom controller i built.

I get an "List has no rows for assignment to SObject" error when trying to preview the page, but running the query in the developer console, returns the rows.

here is my page:

<apex:page Controller="BpmIcountPayment">
    <apex:param name="first_name" value="Account.FirstName"/>
    <apex:param name="last_name" value="Account.LastName"/>
    <apex:param name="id" value="Account.idnumber__c"/>
    <apex:param name="address" value="Account.Address"/>
    <apex:form >
        <apex:selectList value="{!productsTitle}" multiselect="false">
            <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>

and my controller:

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

    public Account getAccount() {
        return account;

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Id, Name, Family 
                                      FROM Product2 
                                      WHERE (Family = 'ShopProduct') 
                                      OR (Family = 'CourseParent') 
                                      OR (Family = 'SFCourseProgram')];

        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));

        return products;
Am, using the concept of Wrapper class. I want to delete recently created contact record from pageBlockTable.
I am facing Unknown property 'SingleRecordDelete.ContactWrp.id' Error
Here is What I did--

VF page

<apex:page controller="SingleRecordDelete">
  <apex:form >
     <apex:pageBlock title="Contacts">
          <apex:pageBlockSection title="New Contact" columns="2" id="fresh">
              <apex:inputText label="FirstName" value="{!fname}" />
              <apex:inputText label="LastName" value="{!lname}"/>
              <apex:commandButton action="{!save}" value="Save" reRender="lab,fresh"/>
          <apex:pageBlockSection title="ContactList" id="lab">
              <apex:pageBlockTable value="{!crp}" var="cy" id="update">
                  <apex:column headerValue="FirstName">
                      <apex:outputLabel value="{!cy.cn.firstname}"/>
                  <apex:column headerValue="LastName">
                      <apex:outputLabel value="{!cy.cn.lastname}"/>
                  <apex:column >
                         <apex:commandLink value="Delete" action="{!doDelete}" style="color:Red" reRender="lab">
                             <apex:param name="did" value="{!cy.id}" assignTo="{!did}"/>

public with sharing class SingleRecordDelete {

    public String fname {get;set;}
    public String lname {get;set;}
    public String did {get;set;}
    public List<ContactWrp> crp {get;set;}
    public SingleRecordDelete(){
        crp = new List<ContactWrp>();
    public void save(){
      Contact c = new Contact();
      c.firstname = fname;
      c.lastname = lname;
      insert c;
      crp.add(new ContactWrp(c));
    public void doDelete()
        List<Contact> contactToBeDelete = new List<Contact>();
        Contact cod = [select id from Contact where id =: did];
        delete contactToBeDelete;
     public class ContactWrp{
      public Contact cn {get;set;}
        public ContactWrp(Contact cs){
            this.cn = cs;                   
Hi all ,

new to salesforce development . I need a basic design for school-student management  . We will have 3 different object as 

1. Student --> containing basic info about student like DOB ,name ,standard,StudnetID  etc....StudentID will be unique . 

2. Marksheet --> This object has field like studentID ,name , marks in every subject ,and many more . we need to send report card to parent . mail will be used from Student object .

3. attendance sheet --> montly attendance sheet which need to be send to parent with remarks . Also StudendID and Student name will be here . 

Now student ID is here unique and we need to send marksheet and attendance sheet everymonth . we will upload csv file for marks and attendance at the end of every month . according to that data we want to send a mail to parent .

my question is how I can relate this student object to rest of two object based on studentID and how I can store data for every month (like if someone wants to check  attendance for the current year ,we should be able show them ). 

Hi! I am a new developer in Apex... Could someone help me to solve this error? I can´t understand what I have to do.
private static List<Task> queryExistingContractsTasks( List<User> entradaDuenos, List<Contract__c> entradaContratos ){
        return [
                OwnerId IN :entradaDuenos
            AND WhoId IN :entradaContratos
            AND Subject LIKE '%Contract%'
            AND CreatedDate = TODAY

We are trying to use the Visual studio code, but having an issue with Java file.
User-added image
Location fo the java file,
C:\Program Files\Java\jdk-11.0.6
What is the best way to create an index on a custom field?

I believe the only way to do this yourself is by creating the custom field as an External Id, this ensures the field has an index.

Is that the best option? Is there any down side to doing this?

  • December 16, 2019
  • Like
  • 0
Hi, while doing Aura input data using forms trail (https://trailhead.salesforce.com/content/learn/modules/lex_dev_lc_basics/lex_dev_lc_basics_forms) challenge, I am getting following error:

The campingList JavaScript controller doesn't appear to be checking if form fields are valid.

My code is as follows:

<aura:component >
	<aura:attribute name="items" type="Camping_Item__c[]"/>
    <aura:attribute name="newItem" type="Camping_Item__c"
                    default="{'sobjectType' : 'Camping_Item__c',
                               'Name': '',
                               'Packed__c': false,
                               'Quantity__c' : 0,
                               'Price__c' : 0}"/>

        <li>Bug Spray</li>

        <li>Bear Repellant</li>

        <li>Goat Food</li>


  <fieldset class="slds-box slds-theme--default slds-container--small">

    <legend id="newCampItemForm" class="slds-text-heading--small 
      Add Camping Item

    <form class="slds-form--stacked">

      <lightning:input aura:id="itemform" 

      <lightning:input type="number" 

      <lightning:input type="number" 

      <lightning:input type="checkbox" 

      <lightning:button label="Create Camping Item"


   <div class ="slds-card slds-p-top--meduim">
      <header class ="slds-card__header">
         <h3 class = "slds-text-heading--small">Items</h3>

       <section class ="slds-card__body">
          <div id="list" class = "row">
            	<aura:iteration items="{!v.items}" var="campItem">
                    <c:campingListItem item="{!campItem}"/>



<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true"/>        
    <p>Name: {!v.item.name}</p>
    <p>Price: <lightning:formattednumber value="{!v.item.Price__c}" 
                                         currencyCode="USD" />    </p>
    <p>Quantity:<lightning:formattednumber value="{!v.item.Quantity__c}" />
       <lightning:button label="Packed!" 
                           value="{! v.item.Packed__c }"/>


and  campingListController.js
    clickCreateItem: function(component, event, helper) {

        // Simplistic error checking
        var validItem = true;

        // Name must not be blank
        var nameField = component.find("itemname");
        var itemname = nameField.get("v.value");
        if ($A.util.isEmpty(itemname)){
            validItem = false;
            nameField.set("v.errors", [{message:"Item name can't be blank."}]);
        else {
            nameField.set("v.errors", null);
        // Quantity must not be blank
        var quantityField = component.find("quantity");
        var quantity = quantityField.get("v.value");
        if ($A.util.isEmpty(quantity)){
            validItem = false;
            quantityField.set("v.errors", [{message:"Quantity can't be blank."}]);
        else {
            quantityField.set("v.errors", null);

        var priceField = component.find("price");
        var price = priceField.get("v.value");
        if ($A.util.isEmpty(price)){
            validItem = false;
            priceField.set("v.errors", [{message:"Price can't be blank."}]);
        else {
            quantityField.set("v.errors", null);

            var newItem = JSON.parse(JSON.stringify(component.get("v.newItem")));
            console.log("Items before 'create': " + JSON.stringify(theItems));
		    component.set("v.expenses", theItems);
		    console.log("Items after 'create': " + JSON.stringify(theItems));
            component.set("v.items", theItems);

In the above code though I am validating the inputs, getting no idea why still I am getting this error.
help me with trigger code.
An object has FirstName and LastName field, if we try to create a record with same FristName and LastName, record should not create(throws error).
I have written process builder flow for an email alert. The first set of criteria is met to send an email alert the first time the criteria is met. The second set of criteria is met to send an email any time the fields change after the initial criteria being sent. Right now it is skipping the initial criteria alert and only sending the ischanged criteria. Not sure what to do to correct this.

Initial Criteria to be Met to Send Initial Email
User-added image
Initial Crtieria Above defined
Initial Criteria:
  1. Stage Name equals Closed Won
  2. Foot Traffic Reports equals DAP
  3. Foot Traffic Reports equals DAP2
  4. Foot Traffic Reports equals DAP3
  5. Cross-Channel Reports Is Null False
  6. MTA Reports Is Null False
  7. TV Reports equals Grace
  8. TV Reports equals Tune
  9. Measurement Reports Offered equals Yes
  10. Record Type Name equals Viant MS
  11. Last Modified Profile ID equals xxxxx1
  12. Last Modified Profile ID equals xxxxx2
Filter Logic
(1 AND 9 AND 10 AND (11 OR 12)) AND (2 OR 3 OR 4 OR 5 OR 6 OR 7 OR 8)

Advanced is checked as yes

IsChanged Criteria after Initial Criteria being met
User-added image
Hi All,

If we have 2 record types with different fields and If we insert or update the records using data loader with specific record type like record type A.

Will it insert in that record type only or both? or If we give data to that both fields in both records irrespective of record type we give it will insert both fields in both records.

Hello all, I am trying to create a user with User License "Salesforce"..but I could only find  "Chatter external", "Chatter free" and  "Salesforce Platform" only. Please help me  why I couldnt find "Salesforce" under user license..
Appreciate your help, thanks in advance
What is wrong with my code?

Description: The purpose of this code is to create multiple records based on two conditions
  1. Custom Picklist: Value = Yes (condition set in process builder)
  2. (Number Field) Contract Term (Number of years) =
So whatever is the value entered in the contract term custom field, those many child record would be created.
Parent Object: Opportunity Contract
Child Object: Annual Maintenance
Error in Production
This code is working fine in Developer Sandbox, after I installed in Production, this program is working as expected with the opportunity contract records which were previously created (before deploying this code)
However, this code does not work with opportunity contract records which are created after the deployment.
The error I am geting is “dereference a null object”
Where am I going wrong? Why this behaviour of working for existing records and not working with new records in Production?

Finally i have recomplied all Apex Classes in Production, but the result is the same

Any Help is highly appreciated!

Below is the code
public class OppConAMInvocableClass {
    @InvocableMethod(label='Insert Child Records for Opportunity Contracts' description='Inserts the child records based on number of contract years.')
  public static void insertChildRecords(List<Opportunity_Contract__c> parentList) {
      List<Annual_Maintenance__c> childrecords = new List<Annual_Maintenance__c>();       
      for(Opportunity_Contract__c parent : parentList) {
        Integer numberYears = Integer.valueOf(parent.Contract_Years__c);
        for(Integer i=1;i<numberYears;i++) {
        //Account acct = [SELECT Id FROM Account where Id = :e.WhatId];
        Integer j = i + 1;         
        Annual_Maintenance__c child = new Annual_Maintenance__c();
            Child.Opportunity_Department__c =Parent.Opportunity_Department__c;
    Database.SaveResult[] results = Database.insert(childrecords);
    List<ID> itemIds = new List<ID>();
    for (Database.SaveResult result : results) {
      if (result.isSuccess()) {
    return itemIds;

I have created an Aura component which is a table.
I wish to visualize it in the page of each contact, for example in the Details tab.
How can I do that?

-we are currently sending all the Invoices from the Platform to Salesforce (via the famous web-service)
-by having those invoices in SF, we can create reports
-but could we report on those invoice by simply doing an “api call” or something similar to the Platform instead of storing the data in SF (ie instead of duplicating in SF the data that is in the Platform)?
  • June 28, 2019
  • Like
  • 0
I would like to keep track of the instance names of orgs I am the administrator for without having to manually handle instance refreshes. Periodically querying those orgs would allow me to access a reletively up-to-date list of clients that are affected by issues listed on trust.salesforce.com.

Is this possible?
I have an external app that I would like to use to create records of a custom object through the rest API. I can create Accounts just fine, but have not been able to replicate that functionality for any custom object.

I took a look at workbench.developerforce.com, and found that the rest explorer is not returning information about any custom objects.

I am logged in as a system administrator, so I should have access to everything. What am I doing wrong?
Hi Team,

Batch Apex Mass Upload Issue ?
Requirement : Need to Update Account fileds from Custom object based on condition.For 1 record we need to update around 5000 Account records with some value.
How can we achieve this request ?
I have tried with trigger and batch apex, for 1 record it is working. But mass upload it is not working.

Please advise any one.

Lakshmi S.
I have the following class that is hitting cpu time limit exception. still learning so help very much appreciated!!  When its working I'll put it in a schedulable class. 
public class test1 {
 public static void test1() {
     Map<id,account> aMap = new Map<id,account>([Select Id,Name, Total_number_of_open_opportunities__c,Total_number_of_open_Upsel_opportunities__c, No_of_days_since_last_AE_activity__c
                        FROM ACCOUNT WHERE Assigned_AE__c != null AND (Assigned_AE__r.profile.Name = 'Sales Executive' OR 
   Assigned_AE__r.profile.Name = 'Premier Account Executive') AND No_of_days_since_AE_assigned__c >=60]);
     List<account> acc =  aMap.values() ;
   List<Opportunity> opps = new List<Opportunity>();    //list of all open opps
   List<account> acc1 = new List<account>();  
  if(acc.size() > 0)
  // Query to get all open opportunites with no stage change in over 60 days 
   Map<id,opportunity> aMap2 = new Map<id,opportunity>([SELECT Id,accountid FROM Opportunity 
                                     WHERE AccountId IN :acc AND ISCLOSED = FALSE AND days_since_last_stage_change__c > 60 AND (RecordType.Name= 'New Business' OR RecordType.Name= 'Upsell')]);
       opps = aMap2.values() ;
     for (account a : acc )
       If((a.Total_number_of_open_opportunities__c == 0 && a.Total_number_of_open_Upsel_opportunities__c == 0) || (a.No_of_days_since_last_AE_activity__c > 30 || a.No_of_days_since_last_AE_activity__c == 0) || opps.size()>0)
            a.Assigned_AE__c = null;
     update acc1;