• Dmitry Ofitserov
  • NEWBIE
  • 161 Points
  • Member since 2015


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 30
    Replies
Hi all,
I have created custom Account fields on several of my objects.
When an email is created on these objects, the Account field need to be automatically populated. To do so, I have created an APEX trigger which is working perfectly fine for 5 of my objects (I give only 2 examples in my code below) but it does not work for Case. I cannot understand why. Any thought?
trigger UpdateAccountonEmail on EmailMessage (before insert, before update) {
    
    for(EmailMessage em : trigger.new){
        
        if(em.RelatedToId != null){ 
            
            List<Account> accList = [select id, name from Account where id =: em.RelatedToId]; 
            List<Opportunity> oppList = [select id, name, AccountId from Opportunity where id =: em.RelatedToId];        
            List<Case> casList = [select id, CaseNumber, AccountId from Case where id =: em.RelatedToId];
            
         // Account field is populated when an email is created on Opportunity  
            ​if(oppList.size() > 0){
                for(Opportunity o : oppList){
                    em.Account__c = o.AccountId;                
                }
            }
          // Account field is populated when an email is created on Account
            else if(accList.size() > 0){
                for(Account a : accList){
                    em.Account__c = a.Id;
                }
            }
       // Account field is not populated when an email is created on Case       
            else if(casList.size() > 0){
                for(Case ca : casList){
                    em.Account__c = ca.AccountId;                
                }
            }
            else{
                em.Account__c = null; 
            }            
        }
    }
}

I have also noted a very strange behaviour, when I create an email into a case sometimes it stays as an email (test email case 3 below), sometimes it creates a task (Email: test email case 2 below) with the type email. How to avoid or streamline this?

User-added image

Thank you for your help.
Sylvie

 
hi all,

i want to create a custom metadata object then i want to add fields to it
the fields which are added to that object should become required 
can you please help me
Hi Gurus, 

I have a Visualforce page for a Survey form that saves entry in to a custom object (Survey) in Salesforce. Within this VF page, I have images of different countries flags which are links to the same survey but in a different language. i.e the french flag with be a link to another VF page but will be the same survey but in french.

Now my problem is that when the flag is click and goes to the different language page, the Survey ID in the web address bar is removed therefore the entry wouldnt be saved into the correct place in Salesforce.

So does any one please know I can transfer the ID from one VF page to another?

This is the Div Class for my UK Flag linking to the english version;
<div class="UK_Flag">
                   <a href="/apex/CustomerSatisfaction_EN"><apex:image id="UK_Flag" value="
                   {!URLFOR($Resource.UK_Flag)}" /></a>
       	 </div>

This is my Apex Class for keeping the ID in the address bar after clicking on the UK Flag but its not working:
public with sharing class CustomerSurvey{
public CustomerSurvey() {

}
 public PageReference UK_Flag () {
           PageReference pageref = new PageReference('/apex/CustomerSurvey_UK'); 
           pageref.getParameters().put('recordID', 'a0C3E000001yarn' + ''); 
           pageref.setRedirect(true); return pageref;
           return pageref;
}

}

Please if anyone know how I can resolve this issue, please let me know please!
Thanks!
 
Hi All,
           How can I find all the user's who are assigned with a particular permission set ?
Hello,
Is there any way to query the "Approval History" related list on custom object ?
The fields I need to query are :"Actual Approver","Overall Status" and "Date".

Thanks
Under personnal preference, you see timezone Names like --

Line Is. Time (Pacific/Kiritimati)
Phoenix Is.Time (Pacific/Enderbury)
Tonga Time (Pacific/Tongatapu)
...
Eastern Daylight Time (America/Indiana/Indianapolis)
Eastern Daylight Time (America/New_York)

But User.TimeZoneSidKey has only the ISO timezone name like "America/New_York".

Is there any place in SF where Apex code can get the fullname like like "Eastern Daylight Time (America/New_York)"?
 
Hi, 
 
 I am trying to update quoteline fields from quote using a trigger and helper class it is not getting updated I am not get getting any error please suggest me what is the issue in below code. 

Trigger
trigger QuoteTrigger on Quote (before  insert, Before Update, After Insert) {

   if(Trigger.isAfter && Trigger.isInsert){
      system.debug('After update calling...');
      QuoteTriggerUtils.updateQlineDecimals(Trigger.new); 
    } 

}
Helper Class 
public static void updateQlineDecimals(List<Quote> qList){
        List<id> QtIds = new List<id>();
        List<QuoteLineItem> Qtlinlst = new List<QuoteLineItem>();        
        for(Quote quote:qList){
            QtIds.add(quote.id);
        }       
        List<QuoteLineItem> Qtlines = [select id, Reseller_Discount__c, Disti_Discount__c from QuoteLineItem where quoteid in :QtIds];
        
        for(QuoteLineItem Qtl : Qtlines){        
          //Qtl.Disti_Discount__c = String.Valueof(Decimal.Valueof(Qtl.Disti_Discount__c).setscale(2));
          //Qtl.Reseller_Discount__c = String.Valueof(Decimal.Valueof(Qtl.Reseller_Discount__c).setscale(2));
          system.debug('Disti Discount  ' + Qtl.Disti_Discount__c);
          system.debug('Reseller Discount ' + Qtl.Reseller_Discount__c);
          Qtl.Disti_Discount__c = '1';
          Qtl.Reseller_Discount__c = '2';
          Qtlinlst.add(Qtl);
         }        
         update Qtlinlst;
    }
Thanks
Sudhir
 
  • March 22, 2018
  • Like
  • 0
I am looking to set a variable depending on the value of a field.

EmailTemplate template = 
    if(a__c == 'a' || a__c == 'b'){
    [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'ab_Email']}
    else {
    [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'c_Email']};

Please can someone show me the correct way to do this?

Thank you
Joe
Hi all,
I have created custom Account fields on several of my objects.
When an email is created on these objects, the Account field need to be automatically populated. To do so, I have created an APEX trigger which is working perfectly fine for 5 of my objects (I give only 2 examples in my code below) but it does not work for Case. I cannot understand why. Any thought?
trigger UpdateAccountonEmail on EmailMessage (before insert, before update) {
    
    for(EmailMessage em : trigger.new){
        
        if(em.RelatedToId != null){ 
            
            List<Account> accList = [select id, name from Account where id =: em.RelatedToId]; 
            List<Opportunity> oppList = [select id, name, AccountId from Opportunity where id =: em.RelatedToId];        
            List<Case> casList = [select id, CaseNumber, AccountId from Case where id =: em.RelatedToId];
            
         // Account field is populated when an email is created on Opportunity  
            ​if(oppList.size() > 0){
                for(Opportunity o : oppList){
                    em.Account__c = o.AccountId;                
                }
            }
          // Account field is populated when an email is created on Account
            else if(accList.size() > 0){
                for(Account a : accList){
                    em.Account__c = a.Id;
                }
            }
       // Account field is not populated when an email is created on Case       
            else if(casList.size() > 0){
                for(Case ca : casList){
                    em.Account__c = ca.AccountId;                
                }
            }
            else{
                em.Account__c = null; 
            }            
        }
    }
}

I have also noted a very strange behaviour, when I create an email into a case sometimes it stays as an email (test email case 3 below), sometimes it creates a task (Email: test email case 2 below) with the type email. How to avoid or streamline this?

User-added image

Thank you for your help.
Sylvie

 
We have a unique field on an object, populated by workflow (datestamp + userId), which prevents a user from submitting two records on the same day. I'd like to display an error message on the visualforce input page, but the normal error message approaches don't seem to be working. Is there some special way I need to display this error? Here is my controller:
public class NewDailyForecast {
           
            public Daily_Forecast__c fc {get;set;}
            public String userId {get;set;}
            public Date todayDate {get;set;}
            public String dailyType {get;set;}
            public String weeklyType {get;set;}
            public String fName {get;set;}
            public double fAmount {get;set;}
            public String recType {get;set;}
            public List<Daily_Forecast__c> thisWeekDaily {get;set;}
            public List<Daily_Forecast__c> thisWeekWeekly {get;set;}
            public List<Daily_Forecast__c> checkUnique {get;set;}

            //set up controller & extension for vf page
            ApexPages.StandardSetController setCon;

            public NewDailyForecast(ApexPages.StandardSetController controller) {
                setCon = controller;
            }

            public void getValues(){
                //get logged in user
                userId = UserInfo.getUserId();
                system.debug('userId '+userId);
                
                //get today's date
                todayDate = system.today();
                system.debug('todayDate '+todayDate);
                
                //get record type
                dailyType = [SELECT Id FROM RecordType WHERE Name = 'Daily Forecast'].Id;
                weeklyType = [SELECT Id FROM RecordType WHERE Name = 'Weekly Forecast'].Id;
                system.debug('dailyType '+dailyType);
                system.debug('weeklyType '+weeklyType);
                    
                fName = userId + todayDate;
                    
                fAmount=0;

                //new forecast record on page
                fc = new Daily_Forecast__c (RecordTypeId = dailyType, Date__c = todayDate, Forecast_Amount__c = fAmount, User__c = userId);
                system.debug('fc '+fc);
                
                //list of related forecast records
                thisWeekDaily = new List<Daily_Forecast__c>([SELECT Id, Date__c, User__c, User__r.UserRole.Name, User__r.Territory__c, Forecast_Amount__c, RecordTypeId, RecordType.Name 
                        FROM Daily_Forecast__c WHERE User__c = :userId AND Date__c = THIS_WEEK AND RecordTypeId = :dailyType ORDER BY Date__c ASC]);
                system.debug('thisWeekDaily '+thisWeekDaily);
                thisWeekWeekly = new List<Daily_Forecast__c>([SELECT Id, Date__c, User__c, User__r.UserRole.Name, User__r.Territory__c, Forecast_Amount__c, RecordTypeId, RecordType.Name 
                        FROM Daily_Forecast__c WHERE User__c = :userId AND Date__c = THIS_WEEK AND RecordTypeId = :weeklyType ORDER BY Date__c ASC]);        
                system.debug('thisWeekWeekly '+thisWeekWeekly);        
            }
            
            public PageReference saveRecord(){
            //error catching method 1: build list to match existing and throw error if list>0
            //this doesn't work
                checkUnique = new List<Daily_Forecast__c>([SELECT Id, Date__c, User__c FROM Daily_Forecast__c WHERE Date__c = :fc.Date__c AND User__c = :fc.User__c]);
        /*        if(checkUnique.size()>0){
                    system.debug('checkUnique '+checkUnique);
                    ApexPages.Message myFatalMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Duplicate record created. Please try again');
                    ApexPages.addMessage(myFatalMsg);
                    system.debug('fatal error '+myFatalMsg);
                    ApexPages.Message myErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message');
                    ApexPages.addMessage(myErrorMsg);
                    system.debug('error '+myErrorMsg);
                }
                insert fc;
        */
                //error catching method 2: try insert and catch exception
                //This doesn't work either
                try {
                    insert fc;
                }
                catch(DMLException e)
                {
                    for(Daily_Forecast__c df :thisWeekDaily){
                        df.addError('Duplicate entry not allowed');
                    }
                    system.debug(e);
                    ApexPages.addMessages(e);
                    ApexPages.Message myFatalMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Duplicate record created. Please try again');
                    ApexPages.addMessage(myFatalMsg);
                    return null;
                }
                return new pageReference( '/' + fc.id );
            }
        }

And vf page:
 
<apex:page standardController="Daily_Forecast__c" extensions="NewDailyForecast" recordSetVar="forecasts" tabStyle="Daily_Forecast__c" sidebar="false" action="{!getValues}">
            <apex:form >
            <apex:pageblock >
              <apex:messages />

            </apex:pageblock>        
            <apex:pageBlock title="Create New Forecast" mode="edit">
                    <apex:pageBlockButtons >
                        <apex:commandButton value="Save" action="{!saveRecord}" rerender="error"/>
                        <apex:commandButton value="Cancel" action="{!cancel}"/>
                    </apex:pageBlockButtons>
                <apex:pageBlockSection >
                    <apex:inputField label="Forecast Type" value="{!fc.RecordTypeId}" id="recType" />
                    <apex:inputField label="Amount" value="{!fc.Forecast_Amount__c}" id="fAmount" />
                    <apex:inputField label="User Name" value="{!fc.User__c}" id="fUser" />
                    <apex:inputField label="Date" value="{!fc.Date__c}" id="fDate" />
                </apex:pageBlockSection>
            </apex:pageBlock>
            <apex:pageBlock title="This Week's Forecast">
                <apex:pageBlockSection >
                    <apex:pageBlockTable id="thisWeek" value="{!thisWeekDaily}" var="d" >
                        <apex:column headerValue="Day"><apex:outputText value="{0, date, EEEE}">
                                <apex:param value="{!d.Date__c}" /> 
                            </apex:outputText></apex:column>
                        <apex:column headerValue="Forecast Amount"><apex:outputField value="{!d.Forecast_Amount__c}"/></apex:column>
                        <apex:column headerValue="Type"><apex:outputField value="{!d.RecordType.Name}" /></apex:column>
                    </apex:pageBlockTable>
                    <apex:pageBlockTable id="thisWeekWeekly" value="{!thisWeekWeekly}" var="w" >
                        <apex:column headerValue="Day"><apex:outputText value="{0, date, EEEE}">
                                <apex:param value="{!w.Date__c}" /> 
                            </apex:outputText></apex:column>
                        <apex:column headerValue="Forecast Amount"><apex:outputField value="{!w.Forecast_Amount__c}"/></apex:column>
                        <apex:column headerValue="Type"><apex:outputField value="{!w.RecordType.Name}" /></apex:column>
                    </apex:pageBlockTable>            
                </apex:pageBlockSection>
            </apex:pageBlock>
            </apex:form>
        </apex:page>

What is the correct way to catch and display the unique/duplicate error message on the vf page? Without any error handling i get the expected INSERT FAILED error screen, which is not user-friendly. With the exception catching above, no message shows at all. How can I program the exception handling to display a user-friendly error message? Thanks in advance.
I'm trying to run test from dev console and getting error "Failed to run tests synchronously.: admin operation already in progress".
Can any one help, as how to resolve it?

Thanks
Hi Team,

I have a requirement to import data into some particular objects from CSV which are placed at particular path at particular time.

Request you to kindly help in that.

Thanks,
  Vishnu
I'm looking for a way to populate a lookup field based on a similar text value on the source and target object.

I have an object child__c with a lookup to parent__c and a field color__c. The field color__c is also available on the parent__c object with unique values.

How can I query the child__c records and populate the lookup with the parent__c record with the same color in color__c in APEX?
hi all,

i want to create a custom metadata object then i want to add fields to it
the fields which are added to that object should become required 
can you please help me
Hi Gurus, 

I have a Visualforce page for a Survey form that saves entry in to a custom object (Survey) in Salesforce. Within this VF page, I have images of different countries flags which are links to the same survey but in a different language. i.e the french flag with be a link to another VF page but will be the same survey but in french.

Now my problem is that when the flag is click and goes to the different language page, the Survey ID in the web address bar is removed therefore the entry wouldnt be saved into the correct place in Salesforce.

So does any one please know I can transfer the ID from one VF page to another?

This is the Div Class for my UK Flag linking to the english version;
<div class="UK_Flag">
                   <a href="/apex/CustomerSatisfaction_EN"><apex:image id="UK_Flag" value="
                   {!URLFOR($Resource.UK_Flag)}" /></a>
       	 </div>

This is my Apex Class for keeping the ID in the address bar after clicking on the UK Flag but its not working:
public with sharing class CustomerSurvey{
public CustomerSurvey() {

}
 public PageReference UK_Flag () {
           PageReference pageref = new PageReference('/apex/CustomerSurvey_UK'); 
           pageref.getParameters().put('recordID', 'a0C3E000001yarn' + ''); 
           pageref.setRedirect(true); return pageref;
           return pageref;
}

}

Please if anyone know how I can resolve this issue, please let me know please!
Thanks!