+ Start a Discussion
Diwakar GDiwakar G 
Hi,

In Setup->Users->Fields->Lanuage only field information is available. How to see the picklist values?
Thanks in advance.
Best Answer chosen by Diwakar G
Sohan Raj GuptaSohan Raj Gupta
Hi Diwakar,

You can manage Language filed values from "Language Settings".

Go to Steup->Language Settings



Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
PRADEEP YADAV 5PRADEEP YADAV 5 
List<Student__c>obj1 = [Select Name,Student_Name__c From Student__c  Where  Student_Name__c Like '_r%' And
                               isDeleted = true All Rows];
        Database.emptyRecycleBin(obj1);
Best Answer chosen by PRADEEP YADAV 5
SwethaSwetha (Salesforce Developers) 
HI Pradeep,

I tried something like this and it initially threw me the same error message you posted when there are no deleted records.

List<Account> a=[Select id,Name From Account Where Name Like '_r%' and isDeleted=true ALL ROWS];
system.debug(a+'===');
Database.emptyRecycleBin(a);
system.debug(a+'===');

However, after deleting a record that satisfied the SOQL condition , and running this same code in the dev console, it ran without error message showing the deleted record in system.debug.

I believe there were no records to be deleted from recyclebin which caused the error.Can you check the recycle bin and confirm?
 
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.
 
Thank you
GAURAV SETHGAURAV SETH 
Hi,

I am creating a event object using apex trigger

if(eightAM == 'true') {
                                                      DateTime startDateTime = kstartDate;
                                                    DateTime ednDateTime = kendDate;
                                                        Event eventObject = new Event();
                                                        eventObject.OwnerId = userID;
                                                        eventObject.Location = location; 
                                                        eventObject.StartDateTime = startDateTime.addHours(8);
                                                        eventObject.EndDateTime =startDateTime.addHours(9);
insert eventObject;
}

If it is 8 AM, I am adding 8 hours to create event entry and it is getting inserted but Calendar always show time 4 hours less.

I have check the settings , my time zone and company profile time zone is same.How can I resolve this issue ?

Thanks,
Best Answer chosen by GAURAV SETH
SidPSidP
@GAURAV SETH

Where these (kstartDate, kendDate ) are coming from? I am assuming somewhere you are creating an new instance using Datetime.now()
This method creates the current DateTime as per GMT and not the user's local timezone, that's how you see the difference in hours. You can use the following two ways to return the new instance in the user's local timezone.

1) Datetime.now().format() ==> this returns the  a local time in the String datatype
2) 
Datetime dt = Datetime.now();
Integer offset = UserInfo.getTimezone().getOffset(dt);
Datetime localDT = dt.addSeconds(offset/1000);
System.debug ('local ==> ' + localDT);


You have to use convert kstartDate and kendDate into the local timezone before using them.

Mark this as answer if this resolve your issue! 
Prady01Prady01 
Hi Forum.

     I am working on some development and I am facing few hicups with creating an algorithm for it. Please let me know if anyone has done this.

I have a list of object and this list contains object with duplicate values, I would like to eliminate the duplicates based on the Created date. Example imagine in the list I have two entity like this
Record1==> {obj.Name: Kat, Created Date: 6th july 2015}
Record2==>{obj.Name: Kat, Created Date: 7th july 2015}.
I would like to eliminate Record1 and keep Record2.

Many thanks
Prady01
 
Best Answer chosen by Prady01
Krishna SambarajuKrishna Sambaraju
If this List is created through a custom class you need to implement Comparable interface on that class and then sort the list in descending order of Created Date. Here is an example of implementing Comparable interface.
public class Employee implements Comparable{    
    public string employeeName;
    public date dateOfEmployment;
    public Employee(string name, Date empDate)
    {
        employeeName = name;
        dateOfEmployment = empDate;
    }
    public integer compareTo(object compareTo)
    {
        Employee emp = (Employee)compareTo;
        if (dateOfEmployment <= emp.dateOfEmployment) return 1;
        if (dateOfEmployment > emp.dateOfEmployment) return 0;
        return -1;
    }
}
Here is the example of using the above class to sort the records and eliminate duplicates.
List<Employee> employees = new List<Employee>();
employees.add(new Employee('Kat', Date.today().addDays(-2)));
employees.add(new Employee('Kat', Date.today()));
employees.sort();

Map<string, Employee> empMap = new Map<string, Employee>();
for (Employee emp : employees)
{
    if (empMap.get(emp.employeeName) == null)
    {
    	empMap.put(emp.employeeName, emp);
    }
}
system.debug('empMap : ' + empMap);
Hope this helps.

 
SandrineSandrine 
Hello,

I have a map with Name(String) and Ranks(Integer),
Name is the Pricebook name and Rank is Order by.
map<String,Integer> mapOfNameAndRank = new map<String,Integer>();

Name1, 1
Name2, 2
Name3, 3
I am populating SelectOption in below manner: 
public list<SelectOption> listOfOpt {get;set;}
for(priceBook2 prc : [select id,Name from priceBook2 ){
            listOfOpt.add(new SelectOption(prc.Id,prc.Name));
        }

My usecase is that, the SelectOption should display the Name is the order defined in map.

How can i reiterate the SelectOption inorder to order it.

thank you for suggestion
Best Answer chosen by Sandrine
Maharajan CMaharajan C
Hi Sandrine,

Try like below:
 
map<String,Integer> mapOfNameAndRank = new map<String,Integer>();
Name1, 1
Name2, 2
Name3, 3

public list<SelectOption> listOfOpt {get;set;}

Map<String,Id> pricebookMap = new Map<String,Id>();
for(priceBook2 prc : [select id,Name from priceBook2 ){
    pricebookMap.put(prc.Name , prc.Id);        
    }	
for(String key : mapOfNameAndRank.keySet())
{
	if(pricebookMap.containsKey(key)){
       listOfOpt.add(new SelectOption(pricebookMap.get(key), key));
   }
}

Thanks,
Maharajan.C
James George 00700James George 00700 
Hi Friends,
Is it possible for APEX to refer formula fields for example refering to a roll-up summary field.

Please let me know your answers.

Thanks,
JG
Best Answer chosen by James George 00700
Ram Chand HeerekarRam Chand Heerekar
if you are asking regarding the access then yes we can access Roll-up summary fields in apex code in below mentioned code rc1__Count_of_opp__c is a rollup summary field.

if this answers your question Mark the solution as best
List<account> acc=[select id,rc1__Count_of_opp__c from account where id='0012v000030hjY3AAI'];
system.debug('acc'+acc);

Output:
USER_DEBUG [2]|DEBUG|acc(Account:{Id=0012v000030hjY3AAI, rc1__Count_of_contacts__c=1})
Carrie Nunemaker 10Carrie Nunemaker 10 
I am completely new to Apex and could really use some help with what seems to be a simple task.  I have a formula on the contact, Persona_True__c, that returns a 1 if the custom field "persona" is populated and a 0 if it is blank.

I would like to have a roll-up summary that sums this field at the account level in a field called Related_Personas__c.  

Because we can't roll-up from contact to account I'm reading that this type of action needs to be a trigger, but I don't even know where to start.  Does anyone have any thoughts or expertise they can share to help me out? 
Best Answer chosen by Carrie Nunemaker 10
Anthony McDougaldAnthony McDougald
Good Evening Carrie,
Hope that your day is off to an amazing start. We've constructed a trigger to your specifications. Please test and report back if anything. Hope this helps and may God bless you abundantly.
trigger ContactSumTrigger on Contact (after delete, after insert, after undelete, after update) {

Contact[] cons;
    if (Trigger.isDelete){ 
    cons = Trigger.old;
    }
    else{
    cons = Trigger.new;
    }
Set<ID> acctIds = new Set<ID>();
for (Contact con : cons) {
   acctIds.add(con.AccountId);
}

Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([SELECT Id, AccountId, Persona_True__c FROM Contact WHERE AccountId IN :acctIds]);

Map<ID, Account> acctsToUpdate = new Map<ID, Account>([SELECT Id, Related_Personas__c FROM Account WHERE Id IN :acctIds]);

for (Account acct : acctsToUpdate.values()) {
Set<Id> conIds = new Set<Id>();
Decimal totalValue = 0;
for (Contact con : contactsForAccounts.values()) {
    if (con.AccountId == acct.Id && con.Persona_True__c != NULL) {
        totalValue += con.Persona_True__c; 
    }
}
acct.Related_Personas__c = totalValue;
}
if(acctsToUpdate.values().size() > 0) {
    update acctsToUpdate.values();
}
}


Best Regards,
Anthony McDougald
Alex Von HasslerAlex Von Hassler 
Hi, I would like to update a field value when a user clicks on a link or button on a email sent out by salesforce. 

We have a workflow that sends out automatic reminders about certain jobs. I would like to setup a second workflow that sends an email 2 days later with a button or link (e.g. "Job completed? Yes, No?") for the user to click on. That button or link should then update a field value in salesforce to "Job completed" or "Job cannot be completed". It doesn't matter if it's a picklist or text field, - I just can't figure out a way to update a field by clicking on a button/link in an email. 

I greatly appreciate any help. 

Alex
Best Answer chosen by Alex Von Hassler
YogeshMoreYogeshMore
Alex,

You can achieve this requirement by using Salesforce Site. For this you have to create site, visualforc page, apex class and email template. Go through the following steps.
  • Firstly you have to create site. (Setup | Develop | Sites).
  • Then create Visualforce page and apex class to update the record.
    //Page Name - updateJobStatus
    
    //Page Code – 
    <apex:page controller="updateJobStatus" action="{!updateRec}" cache="false">
    	<apex:form>
    		Thank you for your custom.
    	</apex:form>
    </apex:page>
     
    //Apex class code–
    public class updateJobStatus{
    
    	public String recId {get;set;}
    	public String isJobCompleted {get;set;}
    
    	public updateJobStatus() {
    		recId = ApexPages.currentPage().getParameters().get('recId');
    		isJobCompleted = ApexPages.currentPage().getParameters().get('isJobCompleted');
    	}
    	public PageReference updateRec() {
    		
    		objectAPIName obj = new objectAPIName();
    		obj.Id = recId;
    		obj.fieldAPIName = isJobCompleted;
    		update obj;
    	}
    }
  • Then add created visualforce page in to site Visualforce Page (Setup | Develop | Sites | Default website | Site Visualforce Pages )
  • Create email template and add site link in email with parameters. refer following links​.
  •  
    http://mydomain.force.com/ updateJobStatus? recId =a1cN0000000Vr6R& isJobCompleted Yes
    http://mydomain.force.com/ updateJobStatus? recId =a1cN0000000Vr6R& isJobCompleted =No
     
     
    When user click on given link then visualforce page will open and record will update automatically.
     
    Regards,
    Yogesh More
    more.yogesh422@gmail.com || Skype:-yogesh.more44
Darryl Moyers 20Darryl Moyers 20 
Hi All,

We've setup a reasonably straightforward Apex Class that's running via a Lightning Component. Happy to share the code, eventually, but we seem to have narrowed down the specific scope of our problem... and we're stumped.

When we run our code and attach a debug/trace... It works correctly. All logic performs desirably.

When we run our code without a debug/trace... It performs incorrectly. We're not hitting errors, but our hypothesis is that collections that should have had, say, 3 items in them (when the code works properly, and/or when we attach a debug log/trace) may only contain 1 when we don't do the debug.

Does the problem we're describing above sound familiar to anyone? Our suspicion is that the debug logs / traces are either slowing down the code execution (in a way that's desirable for our code...) or holding onto simple collection variables in a way that they normally wouldn't.

Nothing makes sense, but it is repeatable. 

We're dealing with ~100 lines of Apex, 3 DML statements, and all code is properly bulkified. No callouts. Nothing asynchronous. Just vanilla.

When we run it with Debugs, it works fine; when we run it without debugs, it works incorrectly.

Any thoughts?
Best Answer chosen by Darryl Moyers 20
AnudeepAnudeep (Salesforce Developers) 
Hi Darryl,

I see some existing bugs today for example: https://success.salesforce.com/issues_view?id=a1p3A000001RXPlQAO with a workaround

There is a strange phenomenon called Heisenbug. In computer programming, heisenbug is a classification of an unusual software bug that disappears or alters its behavior when an attempt to isolate it. When we try to recreate the bug or use a debugger, the error may change or even vanish.
 
-In most of the cases the issue does not occur when we set the debug level of Apex to FINEST.
-When we reduce the debug level and try to replicate the issue, we will be able to replicate the issue and capture the debug logs.
-Such issue seems to occur when there is an issue with collections (list, set or map) in apex.
 
So, to find the exact error we can try reducing the debug level and capture the debug logs. Once we get the exact error we can work on the fix.
 
One possible workaround until the error is fixed is to add a simple debug statement in the code and the issue never occurs.
  
Anudeep
PRADEEP YADAV 3PRADEEP YADAV 3 
When an account is inserted or updated,check whether any opportunity is linked to it or not,if not then create one whose name is ‘First Opportunity -<Account Name>’
Best Answer chosen by PRADEEP YADAV 3
AnudeepAnudeep (Salesforce Developers) 
Hi Pradeep,
 
trigger AddOpportunity on Account(after insert, after update) {
 
    List<Opportunity> oppList = new List<Opportunity>();
    
    // Get the related opportunities for the accounts in the trigger
    Map<Id,Account> acctsWithOpps = new Map<Id,Account>(
        [SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);
    
    // Add an opportunity for each account if it doesn't already have one.
    // Iterate through each account. 
    for(Account acc : Trigger.New) {
                 
        // Check if the account already has a related opportunity.      
       if (acctsWithOpps.get(acc.Id).Opportunities.size() == 0) {
             
            // If it doesn't, add a opportunity
            oppList.add(new Opportunity(Name= 'First Opportunity - '+acct.Name,
                                       StageName='Prospecting',                 //set to Prospecting
                                       CloseDate=System.today().addMonths(1),   //set date to one month
                                       AccountId=acc.Id));
        }           
    }

   if (oppList.size() > 0) {
        insert oppList;
   }
}

Anudeep