• Akshay_Dhiman
  • PRO
  • 2167 Points
  • Member since 2017
  • Salesforce Expert
  • Cloudanalogy softech pvt ltd


  • Chatter
    Feed
  • 61
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 397
    Replies
I have a custom object Students and several fields within it. I now wish to access that data using APEX class and display it in a VP. Here's what I have so far:
public class stdnts {
    List<student__c> enrolledStdnts = [SELECT ID, Name, Year__c, Class__c FROM student__c LIMIT 10];
}
and
<apex:page controller="stdnts">
	<apex:form >
        <apex:pageBlock title="List of enrolled Students">
			<apex:pageBlockTable value="{! enrolledStdnts }" var="ct">
            <apex:column value="{! ct.Year__c }"/>
            <apex:column value="{! ct.Class__c }"/>
			</apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
What am I doing wrong?

 
  • September 16, 2018
  • Like
  • 0
Actually my scenario is 
In vf page shows picklist values are account names and onchange the page shows contact picklist values are child contacts names of above account names. Finally onchange the page shows another picklist option & value of this is opportunity names of above selected contact name. 
Shows the errors if no contact of account and no opportunity of contact when really does not have child record in parent level 
How to fetch all child account and frnd child account ids from a parent account Soql query? 
Hi,

I was reading about testing in apex. I have a doubt with @isTest(SeeAllData=true). Now lets say i have a class with around 20 methods and i want to see data for all the methods in a class except for one or two. If I use @istest(SeeAllData=false) on a particular method it is not working. How can i achieve this. Is there a way of achieving this without specifying for individual methods .

Thanks
Mayank.
Hi All,

I've written & executing the test class for below code and receiving " FATAL_ERROR System.LimitException: Apex CPU time limit exceeded" 
Any idea what I'm missing out in code?

Trigger code:

trigger Accountteamupdate on Account_Relationship__c (before insert) {
    List<AccountTeamMember> accountTeamList = new List<AccountTeamMember>();
    List<AccountTeamMember> finalaccountTeamList = new List<AccountTeamMember>();
    List<user> UserList = [select User_ID_18__c,Taylor_Business_Unit__c, Function__c  from user];
    
    if(Trigger.isInsert)
        
    {
        for(Account_Relationship__c ar:trigger.new) {
            ar.OwnerId=ar.Assigned_Sales_Rep__c;
            AccountTeamMember Teammemberadd=new AccountTeamMember();
            Teammemberadd.AccountId=ar.Account__c;
            Teammemberadd.UserId=ar.Assigned_Sales_Rep__c;
            accountTeamList.add(Teammemberadd);
        } 
        
        for (AccountTeamMember am : accountTeamList )
        {
            
            for (user ul : UserList)
            {
                
                if  (am.UserId == ul.User_ID_18__c)
                {
                    AccountTeamMember Teammember=new AccountTeamMember();
                    Teammember.AccountId=am.AccountId;
                    Teammember.UserId=am.UserId;
                    if (ul.Taylor_Business_Unit__c != null && ul.Function__c != null )
                    {
                    Teammember.TeamMemberRole=ul.Taylor_Business_Unit__c +' '+ ul.Function__c;
                    }
                    else 
                    {
                    Teammember.TeamMemberRole = 'Unspecified';
                    }
                    
                    finalaccountTeamList.add(Teammember);
                }
            }
        }
        
        insert finalaccountTeamList; 
    }
    
    }

Test Class code:

@isTest
public class sampleTestMethodCls {
    static testMethod void testAccountTrigger(){
        List<Account_Relationship__c> AR = new List<Account_Relationship__c>();
        for (integer i = 0 ; i<=200 ; i++)
        {
        Account_Relationship__c  ct = new Account_Relationship__c (Account__c='xxxxxxxx',Assigned_Sales_Rep__c='xxxxxxxx');
         AR.add(ct);   
        }
        Test.startTest();
        insert AR;
        Test.stopTest();
        
    }    
}
 
  • July 23, 2018
  • Like
  • 0
Can anyone help me in the following questions along with each questions test cases?

1. Query on all Contact records and add them to the List. Print that contents of this list.
2. Write a SOQL query to retrieve/print all active Users. Prepare a Map having User Id as key and User record as value. (Hint : Map)
3. Prepare the following map structures : a. Account Name as key and AccountId as value. b. Account Id as key and entire Account object as value.
4. Create a multi-select picklist on Account object called as 'Enrollment Year' with values - 2010, 2011, 2012, 2013, 2014, 2015 and 2016.
Get all account records where in selected 'Enrollment Year' is:
a. 2010
b. 2013 and 2014
5. Write a SOQL query to find all Account records where 'Billing State' is not 'Maharashtra' and 'Kerala'. Order the results by Billing State in descending order with null values at the end. Display first 10,000 records only. NOTE: do not use AND operator.
​6. Write a SOQL query to display 100 opportunity records with amount greater than 10,000 order by created date. Skip first 50 records and include records from recycle bin.
Thanks
  • July 21, 2018
  • Like
  • 0
Hi,

I am very new to devleoping in salesforce and i was hoping someone could point me in the right direction. 

Basically on my community I want to display an image based on the value of a picklist field on account. For each selected value i want to display a different image. Does anyone know the best way of doing this?

Im am guessing building a Custom Visualforce page/componet is the way to go. 

Maybe there is a way if doing this using HTML/Javascript

Sorry my question is so broad. Any help would be great. 
Hi,
I have a the requirement: I need to create a Custom Object with a relationship to Contact. I need to create 5 checkbox in Contacts and same in custom object. Now when I enter the values in the checkboxes in contact I need to insert a new record in custom object with the checkbox values. After inserting the record in cusgom object I need to make the contact checkbox to unselsect if 2 checkbox is selected. How can I do this. I am done with insert and update trigger. Below is my Trigger for reference. Please give me your suggestions.

trigger projInsert on Contact (after insert, after update) {
    System.debug('---- Inside Contact :----');
    
    if(trigger.isInsert) {
        List<Project__c> projList = new List<Project__c>();
        for(Contact con : Trigger.new) {
            System.debug('---- Inside For Loop : ----');    
            if (con.LastName != '' && con.LastName != null) {
                System.debug('---- Inside IF Loop : ----');    
                Project__c proj = new Project__c();
                proj.Contact__c = con.id;
                proj.Feature_1__c = con.Feature_1__c;
                proj.Feature_2__c = con.Feature_2__c;
                if(con.Product_A__c == true) {
                    proj.Products__c = 'Product A';
                }
                else if (con.Product_B__c == true) {
                    proj.Products__c = 'Product B';
                }
                else {
                    proj.Products__c = '';
                }
                projList.add(proj);
            }
            System.debug('---- Proj List ----');
            System.debug('---- Proj List After If : ----'+projList);   
        }
        
        if(projList.size() > 0) {
            insert projList;
        }
        System.debug('---- Proj List : ----');
        System.debug('---- Proj List Size : ----' +projList.size());
    }
       
    if(trigger.isUpdate) {
        Map <Id, Contact> mapContact = new Map <Id, Contact>();
        List<Project__c> listProject = new List<Project__c>();
        
        for(Contact cont : trigger.new)
            mapContact.put(cont.Id, cont);
        
        listProject = [SELECT id, Contact__c, Feature_1__c, Feature_2__c, Products__c
                         FROM Project__c 
                         WHERE Contact__c IN : mapContact.keySet()];
        
        if (listProject.size() > 0) {
            for (Project__c pro : listProject) {
                pro.Feature_1__c = mapContact.get(pro.Contact__c).Feature_1__c;
                pro.Feature_2__c = mapContact.get(pro.Contact__c).Feature_2__c;
            }
            update listProject;
        }
    }        
}

Thanks
i want to create a button add contact when i clicked one more empty contact show in my page.
like this screen shot.
User-added image
Hello, team!

I'm having this error to finalize my challenge Create the Battle Station App. This is the message: An object named 'Battle Station' does not exist.
I'm using a Developer Edition for training, and all the steps are concluded, so, I couldn't find a answer that corresponds the problem. Please help me. Thanks in advance!
Hello! I am trying to create an account using visual force page. Note that we have person accounts activated. I am just entering first name, last name, date of birth using VF page. When I try to test it ... I am good with fn, ln. When it comes to DOB, I select the date... but the date disappear as soon as my mouse is off of the field...and defaults to mm/dd/yyyy. After I click next, the record is saved with fn, ln... no DOB. Pls help me what's wrong here...thanks.

<apex:page standardController="Account" docType="html-5.0">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
    <apex:pageBlock title="Account Creation">
        <br>
            <apex:pageblocksectionitem >
                <apex:outputlabel value="First Name    "/>
                <apex:inputText value="{!account.firstname}" id="personFname"/>
            </apex:pageblocksectionitem>
        </br>
        <br>
            <apex:pageBlockSectionItem >
                <apex:outputlabel value="Last Name      " for="personLname"></apex:outputLabel>
                <apex:inputText value="{!account.lastname}" id="personLname"/>
            </apex:pageBlockSectionItem>
            </br>
        <br>        
                <apex:outputlabel value="Date of Birth   " for="persondob"></apex:outputLabel>
                <apex:inputfield type="date" value="{!Account.PersonBirthdate}" style="width:150px" id="persondob"/>
        </br>
        <apex:commandButton id="saveBtn" value="Next" action="{!Save}" />
    </apex:pageBlock>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 
  • July 16, 2018
  • Like
  • 0
Hi
I want to fetch all fields which values is not null by  SOQL like (Select * from ObjectName)
exp - Object A have 10 fields
In Obj A has 3 fieds values null and 7 is not null.So I fetch all not null vaues by SOQL
I can't figure out why the list of events expected is not showing up on this page. 

VF Page:

<apex:page standardController="Business_Plan__c" extensions="BusinessPlanEventsControllerExtension"> 
<apex:form >
<apex:pageBlock title="Events">
   <apex:pageBlockTable value="{!eventList}" var="oe">
      <apex:column value="{!oe.OwnerId}"/>      
      <apex:column value="{!oe.StartDateTime}"/> 
      <apex:column value="{!oe.EndDateTime}"/>   
      <apex:column >
          <apex:outputField value="{!oe.Subject}" id="Subject" /> 
          <apex:facet name="header">Subject</apex:facet>
      </apex:column>
      <apex:column value="{!oe.Description}">
          <apex:facet name="header">Purpose of Meeting</apex:facet>
      </apex:column>
      <apex:column value="{!oe.Outcome__c}">
          <apex:facet name="header">Desired and Actual Outcome</apex:facet>
      </apex:column>         
   </apex:pageBlockTable>
   
   <apex:pageBlockButtons > 
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
   </apex:pageBlockButtons> 
   
</apex:pageBlock>
</apex:form>
</apex:page>

Controller Extension:

public with sharing class BusinessPlanEventsControllerExtension {
    public Business_Plan__c bp;
    public Business_Plan__c bpInfo;
    public List<Event> eventList {get;set;}
    public List<Task> taskList;
        
    public BusinessPlanEventsControllerExtension(ApexPages.StandardController Controller) {        
        bp = (Business_Plan__c)controller.getRecord();     
    }    

    public List<Event> getEvents(){          
        bpInfo = [SELECT Id FROM Business_Plan__c WHERE id =: bp.Id];
        eventList = new List<Event>();
        eventList = [SELECT Id, OwnerId, Subject, StartDateTime, EndDateTime, Description, Outcome__c,  Complete__c 
                     FROM Event WHERE WhatId =: bpInfo.Id ];
        System.debug('Event List' + eventList);
        return eventList;         
    }                               

}
  • July 12, 2018
  • Like
  • 0
--------I am not getting how to write a test calss for this apex controller?
public class OV_ObjectUtility {
    public static void getData(){
        List<String> ids = new List<String>();
        ids.add('001U0000004ZjhgIAC');
        ids.add('0010B00001lL1VEQA0');
        ids.add('001e0000018SOK5AAO');
        ids.add('001e0000018SOKAAA4');
        lightningTableWrapper ffff= getRecordsForSearch('Account','Name, OriginalAccountName__c, TradestyleName__c, Continent__c, BillingCity, BillingCountry, website, BillingPostalCode, BillingState, BillingStreet, Id',ids);
        
        system.debug('----Final Query Datas ---'+ffff); 
    }
    public static lightningTableWrapper getRecordsForSearch(String ObjectName,String fieldstoget,List<String> ids){     
        lightningTableWrapper ltw = new lightningTableWrapper();
        String wherecon='';
        try{            
            for(String str : ids){
                if(str!=null){
                    wherecon = wherecon+ ' \''+str + '\',' ;
                }
            }
            wherecon = wherecon.subString(0,wherecon.length()-1);
            String queryString = 'Select '+ String.escapeSingleQuotes(fieldstoget)+
                ' from '+ String.escapeSingleQuotes(ObjectName)+
                ' where id in ('+wherecon+')';
            system.debug('----Final Query---'+queryString);
       
            List<sobject> sObjectsList = new List<sobject>();
           
            sObjectsList.addAll(database.query(queryString));
            system.debug('----Final Query Datas ---'+sObjectsList);
            ltw.sObjectrecords = sObjectsList;
        }catch(Exception e){
        }
        return ltw;
    }
}
Hi All,

I am developing a website for aution on force.com and for that I  need a VF page. Which will be the homepage
Requirements:
1. This login  page should be divided in to two parts first for Sellers and second for Bidders
2. If they are new to the site there should be an option for Register as Seller or Register as Bidder
3. So when the people will click on it, they will be redirected to a new page, for which i already have a VF page for both Seller and Bidder
4. If already a member there has to be a process of authentication also. 
Basically normal fundamentals of a login page
I have a custom object Students and several fields within it. I now wish to access that data using APEX class and display it in a VP. Here's what I have so far:
public class stdnts {
    List<student__c> enrolledStdnts = [SELECT ID, Name, Year__c, Class__c FROM student__c LIMIT 10];
}
and
<apex:page controller="stdnts">
	<apex:form >
        <apex:pageBlock title="List of enrolled Students">
			<apex:pageBlockTable value="{! enrolledStdnts }" var="ct">
            <apex:column value="{! ct.Year__c }"/>
            <apex:column value="{! ct.Class__c }"/>
			</apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
What am I doing wrong?

 
  • September 16, 2018
  • Like
  • 0
Hello Guys...
Pls Help Me for this...
1. Create custom object with label 'Demo Object' and API name Demo_Object.
2. Create a 'text' field with label 'Category'.
3. Create a 'lookup' field for 'Opportunity' object.
4. Write trigger for custom object. On insert of custom object record if the value of 'Category' field is equal to 'Opportunity' create a new opportunity record via trigger.
   The opportunity lookup needs to be populated with this new opportunity.
 
Hi All,

I have requirement where i need schedule batch job 4 times in day. this are the timinings 1AM EST, 10 AM EST, 3PM EST, 8PM EST. I have schedule this using cron expression in dev console. i have prepared script below, please advise is this correct.


className c = new className();
String sch = '0 0 1,10,15,20 * * *';
system.schedule('Four times in day ', sch, c);

Thanks,
Anil Kumar
Hello,

I have scenerio when i click on name (List  field ),when i click on any existing name records in list should redirect to detail page of that particular record.

I am using custom link though it,i want to perform the action
List<String> myList = new List<String>();
myList.add('a');

I'm just playing arround with lists and it seems basic, but I keep getting errors. What am I doing wrong? I literally just copied and pasted, and got the error. I get both errors on the second line:
- Extra ')', at 'a'.
- Invalid constructor name: myList.add
<apex:page standardController="Account" >
    <apex:form >
        <apex:pageBlock title="Show Attached Contacts">
            <apex:pageBlockSection title="Files" >
             <apex:inputField  value="{!Account.Name}" /> 
              <apex:inputField value="{!Account.Industry}"/> </apex:pageBlockSection>
                             
                <apex:pageBlockButtons location="Bottom">
                    <apex:commandButton value="Click Me!"  />           
                </apex:pageBlockButtons>
            </apex:pageBlock>
    </apex:form>
</apex:page>
public class Requirement1 {

    public static void beforeinsert(list<Contact> con){
        
        for(Contact c:con){
            if(string.isblank(c.MobilePhone) && c.Phone!=null && c.Type__c=='prospect'){
                c.MobilePhone=c.Phone;
                
            }
            else{
                if(string.isBlank(c.phone) && c.MobilePhone!=null){
                    c.phone=null;
                }
            
             
            }
        }
    }
    public static void beforeupdate(list<Contact> con1){
     
        for(contact cn:con1){
            if(cn.Office_Phone__c!=null && string.isBlank(cn.Phone)&& string.isBlank(cn.MobilePhone)){
                cn.MobilePhone=cn.Office_Phone__c;
              
            }
        }
     
    }
}
Hello,

How to empty the recycle bin by using apex.
As i am tring to 
    lead l=new lead(id='00Q7F00000CxIwa');
database.emptyRecycleBin(l);

it works,

but what will do if i want to empty all the records from different objects(As there are from differernt objecs how should i select particular object or should i write SOBJECT???)
Hi Everyone,

I'm having problem with heap size error
We have a trigger from the trigger we are calling so any classes,if we do any changes in the record it showing heap size 

Please help 
Thanks in advance 

Regards
Rathod
Hi,
I have a custom object (Demo__c). In this object, I would like to have a custom field that would count and display the number of records for this object based on a filter criteria. I know this can be accomplished using Reports but I want a field on the object itself to show this information. For example, the Demo object has 100 records. Of the 100 records, I want to see in this custim field how many records have a total revenue value less than or $1,000,000. If there are 10, then the custom field should show 10. 
can anyone provide test cases for following scenario..consider all positive negative test cases.\

public class LeadRecord {
/**
This method displays total number of distinct Lead records on basis of 'Lead Source'
having greater than 10 leads.
@return Nothing.
*/
public static void displayLeads() {
List<AggregateResult> leadList = [
SELECT
LeadSource ls,
count_distinct(id) cnt
FROM
Lead
GROUP BY
LeadSource
HAVING
count_distinct(id) > 10
];
for(AggregateResult leadRecord : leadList) {
System.debug(leadRecord.get('ls') + ' -- ' + leadRecord.get('cnt'));
}
}
}
  • August 07, 2018
  • Like
  • 0
Need TEST CLASS for following

Description: Display sum of all closed Opportunity amount for current year

public class FiscalYear {
public static Map<Integer,Decimal> getSumOfOpportunities() {
Map<Integer,Decimal> opportunityMap = new Map<Integer,Decimal>();
List<AggregateResult> opportunityList = [
SELECT
CALENDAR_YEAR(CloseDate) YEAR,
sum(Amount) SUM
FROM
Opportunity
WHERE
isClosed = true
GROUP BY
CALENDAR_YEAR(CloseDate)
];
for( AggregateResult opportunityRecord : opportunityList ) {
if( opportunityRecord.get('YEAR').equals(System.today().year()) ) {
System.debug('Sum of all closed Opportunity amount for current fiscal year: '
+ opportunityRecord.get('SUM'));
}
opportunityMap.put((Integer)opportunityRecord.get('YEAR'), (Decimal)opportunityRecord.get('SUM'));
}
System.debug(opportunityList);
System.debug(opportunityMap);
return opportunityMap;
}
}
  • August 07, 2018
  • Like
  • 0
Actually my scenario is 
In vf page shows picklist values are account names and onchange the page shows contact picklist values are child contacts names of above account names. Finally onchange the page shows another picklist option & value of this is opportunity names of above selected contact name. 
Shows the errors if no contact of account and no opportunity of contact when really does not have child record in parent level 
Please provide some basic, advance level scenerio in triggers. 
How can i convert the below string in the  web service class in JSON..

please help..

@RestResource(urlMapping='/Account/*')
 global with sharing class NewCustCreation
 {
    //public String Status {get;set;}
    //public List<Account> Data {get;set;}
    //public String Message {get;set;}
    //public String ErrorCode {get; set;}
    
     public class Account
     {

        public String Name;
     }

    @HttpPost
    global static String dopost(String Name)
    {
        system.debug('-----------Name----------------------'+Name);
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response; 
         Account account =  new Account();
         account.name=name;
         String success = 'Welcome to Salesforce';
         String error = 'Error';
         if(Name!= '')
         {
              return Name;
         }
         else
         {
              return error;   
         }
         

    }
Hi,
I am confused in what cases should we use apex:pageMessages, apex:pageMessage, apex:Message and apex:Messages? 

Thanks.
Harshit