• Ansh Coder
  • NEWBIE
  • 215 Points
  • Member since 2016

  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 18
    Replies

I have attempted to piece together a VF Log a Call page but I am having trouble populating the VF page with an Account values while using the ApexPages.currentPage().getParameters().get('custom-field-goes-here'); None of the fields populate. I am I mssing something??

 

ControllerExtenstion

public with sharing class LogACallControllerExtension {

    public Task task {get; set;}

    public LogACallControllerExtension(ApexPages.StandardController controller) {
            this.task = (Task)controller.getRecord();
            this.task.whatId = ApexPages.currentPage().getParameters().get('what_id'); 
            this.task.AMarket_Segment__c = ApexPages.currentPage().getParameters().get('Market_Segment_Copy__c');    
            this.task.subject = 'Outside Sales Call'; 
            this.task.type = 'Call';
            this.task.status = 'Completed';
            this.task.activitydate = Date.today();
    }
    
    
}

Visualforce Page

<apex:page standardController="Task" extensions="LogACallControllerExtension" docType="html-5.0" showHeader="false" standardStylesheets="false">


<div class="bootstrap" columns="1">
<apex:form >
   <div>
           <label>Related To</label><br />
            <apex:inputField style="form-control" value="{!Task.WhatId}" /><br /><br />
            
            </div>
            
            <label>Market Segment</label><br />
            <apex:inputField value="{!Task.AMarket_Segment__c }" /><br /><br />
            
            <label>Classification</label><br />
            <apex:inputField value="{!Task.Classification__c}" /><br /><br />
            
            <label>Call Type</label><br />
            <apex:inputField value="{!Task.Call_Type__c}" /><br /><br />
            
            <label>Sales Objective</label><br />
            <apex:inputField value="{!Task.All_Communities_Objective__c}" /><br /><br />
            
            <label>Accomplished</label><br />
            <apex:inputField style="form-control" value="{!Task.Accomplished__c}" />  <br/><br />
            
            <label>Next Steps</label><br />
            <apex:inputField style="form-control" value="{!Task.Next_Steps__c}" /><br /><br/>
            
            <label>Relevant Notes</label><br />
            <apex:inputField value="{!Task.Relevant_Notes__c}" /><br /><br />
            
<div id="formControls" >
<apex:commandButton action="{!quickSave}" value="Save"/>  </div>  
</apex:form>
</div>
</body>
</apex:page>

  • February 26, 2016
  • Like
  • 0
Hi,

I found this URL that shows how refresh token. However, it does not work for me
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_refresh_token_oauth.htm

I have this message error: 
Resfresh token error message
There are my request entries:
endpoint: https://test.salesforce.com/services/oauth2/token
grant_type: refresh_token,
client_id :
CLIENT_ID,
client_secret: CLIENT_SECRET,
 refresh_token: my_last_token,
 format :
 json


 
Hi 
can I change my site domain http:/test-developer-edition.ap2.force.com/  to something like www.devtest.force.com or Any easy name.
Thanks 
Abhilash Mishra 
Hi I have created a trigger that should add an email as a ticket comment but it appears not to work. Can you review and let me know where the issue lies? Or if you have a better trigger to do this please let me know

trigger CaseEmails on Case (after insert, before insert) {

List<EmailMessage> emails;

List<CaseComment> comments = new List<CaseComment>();

for (EmailMessage email:emails)

{

Id CaseId = email.ParentId;

CaseComment comment = new CaseComment(ParentId=caseId);

String header = 'From: ' + email.FromName + ' <' + email.FromAddress + '>\n';

header += email.CcAddress!=null?'CC: '+ email.CcAddress + '\n\n':'\n';

if (email.TextBody!=null){

comment.CommentBody = header + email.TextBody; }

else if (email.HtmlBody!=null){

comment.CommentBody = header + email.TextBody; }

comments.add(comment);

}

if (!Comments.isEmpty())

{

insert comments;

}

}
Hi All,

I got nice little Opportunity Product application from Michaelforce which I've modified to suit our business and it's been fine till now.  Our Sales Reps have requested the ability to be able to add multiple search result lines to the "shopping cart" when adding products with a "Select All" button.

I have the following codes below, but my coding experience is minimal. 

Class Snippet:
public void addToShoppingCart(){
    
        // This function runs when a user hits "select" button next to a product
    
        for(PricebookEntry d : AvailableProducts){
            if((String)d.Id==toSelect){
                shoppingCart.add(new opportunityLineItem(OpportunityId=theOpp.Id, PriceBookEntry=d, PriceBookEntryId=d.Id, UnitPrice=d.UnitPrice));
                break;
            }
        }
        
        updateAvailableList();  
    }
    
    public void addAllToShoppingCart(){
    
        // This function runs when a user hits "add all" button
    
        for(PricebookEntry d : AvailableProducts){
                shoppingCart.add(new opportunityLineItem(OpportunityId=theOpp.Id, PriceBookEntry=d, PriceBookEntryId=d.Id, UnitPrice=d.UnitPrice));
        }
        
        updateAvailableList();  
    }

I was advised to add the "add all" method by a Java developer at our company.

VF Page Snippet:
<apex:column>
                            <apex:facet name="header"><apex:CommandButton value="Select All" action="{!addToShoppingCart}" reRender="selected,searchResults" immediate="true">
                                </apex:commandButton>
                            </apex:facet>                                                             
                            <!-- command button in a column... neato -->
                            <apex:CommandButton value="Select" action="{!addToShoppingCart}" reRender="selected,searchResults" immediate="true">
                                <!-- again we use apex:param to be able to tell the controller which row we are working with -->
                                <apex:param value="{!a.Id}" assignTo="{!toSelect}" name="toSelect"/>
                            </apex:commandButton>
                        </apex:column>

I can't seem to get the button to add any lines, I'm not sure if I'm missing apex:param values liek on the other standard select buttons, and if so, what would I use as a value to select all search result lines?

I know I can go the route of using checkboxes and wrappers to do this, but it woul dbe nice if it could be done with the button.

If anyone has any suggestions or can point me in the right direction, it would be appreciated.
how to update a custom field into the activity history related list when an email is added?  There is a custom field that I added to the activity history related list and I want it to populate based on what was documented in the comments field (Standard field).  I've realized that using a workflow rule triggers something to go wrong with the salesforce connector from outlook so that didn't work for me.  Are there any other ways and what options do I have?

Thanks,

Jay Singh
Hi Folks, I am trying to modify a class to include and additional profile (profile name is Procurement). This is the snippet I am attempting to modify.
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer'];
        return !profiles.isEmpty();

I append ,'Procurement' to the line as such:
        profiles = [select Id from Profile where Id = :Userinfo.getProfileId() and  Name = 'Engineering- Apps Engineer','Procurement'];
        return !profiles.isEmpty();

But I get the error: Error: Compile Error: expecting right square bracket, found ',' at line 72 column 119. Can someone help me out with what I'm missing here? Thanks!
Hi all,
List<List<Integer>> listOfListInt = new List<Integer> { {0, 1, 2, 3}, {3, 2, 1, 0}, {3, 5, 6, 1}, {3, 8, 3, 4} };  After executeig the code in developer console i am getting follwing error
Line: 1, Column: 56
expecting right curly bracket, found '{'
Please help me fix error
Thanks

 
public class logView3Controller {

   
    public Boolean searched { get; set; }
   
    public List<Weeks__c> weekList = Weeks__c.getAll().values();
    public Map<Integer, Weeks__c> weekMap = new Map<Integer, Weeks__c>();
    public Map<String, Integer> weekMapGetIntWithWeek = new Map<String, Integer>();    
    public Map<String, Subjects_and_Levels__c> subjectLevelMap =  Subjects_and_Levels__c.getAll();
    public List<Subjects_and_Levels__c> subjectLevelList = subjectLevelMap.values();
    public Map<String, Subjects_and_Levels__c> levelMap = new Map<String, Subjects_and_Levels__c>();
       
    public Date StartDate {get;set;}
    public Date EndDate {get;set;}
    public String selectedLocation {get;set;}
    public String selectedDay {get;set;}
    public List<Log_Book__c> logBookEntries {get;set;}
    public List<studentsWithWeeks> studentsWithWeeksList {get;set;} 
    public studentsWithWeeks newSWW {get;set;}
    public String domain {get;set;}
    public List<integer> indexNums {get;set;}
    public List<String> weekTableHeader {get;set;}
    public List<String> subjectTableHeader {get;set;}
    
    public  List<Log_Book__c> relatedLogs{get;set;}
    
    //Jagadeesh
    public String selectedTeacher{get;set;}
    public String selectedDays{get;set;}
    
 
    public Id recordToUpdateId {get;set;} 
    public Id recordToUpdateIdStudent {get;set;} 
    
    
    public log_Book__c logObj {get;set;}
    public Student__c studentObj {get;set;}
    public boolean displayPopup {get; set;}
    public boolean displayPopupStudent {get; set;}
    public String exportToExcelURL {get;set;}
    public log_Book__c newLevel{get;set;}
    public log_Book__c newWeek{get;set;}
    List<Log_Book__c> lbjump{get;set;}
    // 2.  a,b,c,d - a,j,k,l,m - changing the complete series
    // Written by Jagadeesh(New code for skip records) 
    public List<Log_Book__c> jump{get;set;}
    public Log_Book__c jump1{get;set;}
    public List<Log_Book__c> lblist{get;set;}
    
     List<Log_Book__c> updateLogs = new List<Log_Book__c>();
     
     
      public logView3Controller () 
      {    
        domain = ApexPages.currentPage().getHeaders().get('Host'); 
        //exportToExcelURL = '/apex/logView3ExportToExcel?startDate='+startDate+'&endDate='+endDate+'&selectedLocation='+selectedLocation;
        exportToExcelURL = '/apex/logView3ExportToExcel?startDate='+startDate+'&endDate='+endDate+'&selectedLocation='+selectedLocation+'&selectedTeacher='+selectedTeacher;
        weekTableHeader = new List<String>();
        relatedLogs = new List<Log_book__c>();
        searched = false;
        
      
     }
      public String getEnglishColor() {
        return Colr;
      }
   
    public PageReference doUpdateLogObj2()
    {  
      
        String lv =  logObj.Week__c.split('-')[0];
       if(logObj.Subject__c == 'Math' && logObj.Level__c == 'Level 5B' && Integer.valueOf(lv) > 17){
           
          logObj.Week__c.addError('For Math Level 5B week should not exceed 17');
            return null;
        }
        system.debug('hii');
      
        relatedLogs = [SELECT Id FROM Log_Book__c WHERE Student__r.Id =: logObj.Student__r.Id AND Subject__c =: logObj.Subject__c AND Class_Scheduled_Date__c >=: logObj.Class_Scheduled_Date__c and isSkipped__c=false];        
        System.debug(' relatedLogs.Size()'+ relatedLogs.Size());
       
        Log_Book__c lb = new Log_Book__c();
        
        Integer levelOrder = Integer.valueof(subjectLevelMap.get(logObj.Subject__c +':'+logObj.Level__c).Order__c);
        Integer weekOrder;
            System.Debug('levelOrder :' + levelOrder);
            System.Debug('weekList :' + weekList);
            for(Weeks__c week : weekList)
            {
                weekMap.put((Integer)week.Order__c, week);
                weekMapGetIntWithWeek.put(week.Name, (Integer)week.Order__c);
            }
            System.Debug('weekMap :' + weekMap);
            System.Debug('weekMapGetIntWithWeek :'+ weekMapGetIntWithWeek);
            for(Subjects_and_Levels__c level: subjectLevelList)
            {
                levelMap.put(level.subject__c+Integer.valueof(level.Order__c), level);
            }
            System.Debug('levelMap :' + levelMap);
          Integer totalLevels = 0;
          if(logObj.Subject__c == 'English')
            totalLevels = 16;
          else if(logObj.Subject__c == 'Abacus')
            totalLevels = 11;
          else if(logObj.Subject__c == 'Math')
            totalLevels = 14;
          else if(logObj.Subject__c == 'G.K')
            totalLevels = 3;
         
        System.Debug('Total Logs :'+ relatedLogs.Size());
        lb = logObj.clone(false, true, false, false);
        updateLogs.add(lb);
        
        for(Integer i=1; i<relatedLogs.Size(); i++)
        {
                lb = new Log_Book__c();
                
                System.Debug('lblblblblblblb :' + lb);
                
                lb = updateLogs[i-1].clone(false, true, false, false);
                weekOrder = Integer.ValueOf(weekMapGetIntWithWeek.get(lb.Week__c));
                System.Debug('weekOrder : ' + weekOrder);                
                lb.Class_Scheduled_Date__c = lb.Class_Scheduled_Date__c.addDays(7);
                
                System.Debug('weekMapGetIntWithWeek.get(lb.Week__c) :'+ weekMapGetIntWithWeek.get(lb.Week__c));
                System.Debug('weekMapGetIntWithWeek.get(lb.Week__c)+i :'+ Integer.ValueOf(weekMapGetIntWithWeek.get(lb.Week__c))+i);
                if( weekOrder < 26 )
                {
                weekOrder = weekOrder+1;
                lb.Week__c = weekMap.get(weekOrder).Name;
                System.Debug('@@@@@@ lb.Week__c = ' + lb.Week__c);
                }
                else
                {
                  if(lb.week__c == '26-Z')
                  {
                    if(levelOrder < totalLevels)
                    {
                        levelOrder = levelOrder +1;
                        System.Debug('lb.Subject__c+levelOrder : '+ lb.Subject__c+levelOrder);
                        lb.level__c = levelMap.get(lb.Subject__c+levelOrder).Level__c;
                        lb.Week__c = '1-A';
                    
                    }
                  
                  }
                    else
                    if(lb.Subject__c == 'Math' && lb.Level__c == 'Level 5B' && lb.Week__c == '17-Q')
                    {
                        if(levelOrder != null && levelOrder < totalLevels){
                        
                            levelOrder = levelOrder +1;
                        
                         lb.level__c = levelMap.get(lb.Subject__c+levelOrder).Level__c;
                         lb.Week__c = '1-A';
                           
                        
                        
                        }
                    }
                    
                    else
                    {
                    i = relatedLogs.Size();
                    
                    }
                }
           
                 System.Debug('lblblblblblblb :' + lb);
                
                        
                updateLogs.add(lb);
                System.Debug('updateLogs : '+ updateLogs);        
        }
        
         System.debug('--->related logs are--->'+relatedLogs);
         delete relatedLogs;
         System.debug('--->related logs are after delete--->'+relatedLogs);
         insert updateLogs;
         
      
           
         //insertLogs();
              
        System.debug('@@@@@updated logs@@@'+updateLogs.size()+'----------->'+updateLogs[0]);
        
        displayPopup = false;
        doSearch();
        
   
       return null;      
    }
    
   /*public void deleteLogs()
    {
      
         if(relatedLogs.size()>0 && relatedLogs!=null){
        
        System.debug('@@@@@relatedlogs@@@'+relatedLogs.size());
        try{
        delete relatedLogs; 
         } catch(exception e)
             {
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,e.getMessage()));

             } 
        }
           
    }
    
    public void insertLogs()
    {
        if(updateLogs.size()>0 && updateLogs!=null){
        
            System.debug('@@@@@relatedlogs@@@'+relatedLogs.size());
            try{
            insert updateLogs; 
            }catch(exception e)
             {
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,e.getMessage()));

             } 
           }
         
    }*/
    
    public void closePopup()
    {        
        displayPopup = false; 
    }
    public void closePopupStudent()
    {        
        displayPopupStudent = false; 
    }     
    public void showPopup() 
    {    
        logObj = new log_Book__c();
        try
        {
            system.debug('recordToUpdateId : '+recordToUpdateId);
            logObj = [SELECT Id, Name,Start_Time__c,End_Time__c, Color_Code__c, Comment_on_LogBook__c, Subjects_Registered__c, Student__c, Student__r.Id, Student__r.Color_Code__c, Student__r.Name, Student__r.Last_Name__c, Subject__c, Level__c, Week__c, Week_Day__c, Class_Scheduled_Date__c,Subjects_Registered__r.Teacher__c, Student__r.Location__r.Name FROM Log_Book__c WHERE Id =:recordToUpdateId  ];    
            system.debug('old name : '+logObj.Name+' old week : '+logObj.Week__c+' old Level : '+logObj.Level__c+' id '+logObj.id);
            system.debug('teacher name '+logObj.Subjects_Registered__r.Teacher__c);
        }
        catch(exception e)
        {
        System.Debug(e.getMessage());
        }
        displayPopup = true;    
    }
    public void showPopupForStudent() 
    {    
        studentObj = new Student__c();
        try
        {
        studentObj = [SELECT Id, Color_Code__c, Comment_on_LogBook__c, Name, Last_Name__c FROM Student__c WHERE Id =:recordToUpdateIdStudent];    
        }
        catch(exception e)
        {
        System.Debug(e.getMessage());
        }
        displayPopupStudent = true;    
    }
I am currently using this formula in a checkbox field:
(TODAY() - LastActivityDate) <= 30

Is it possible to do this with the Notes & Attachments related list?

I have attempted to piece together a VF Log a Call page but I am having trouble populating the VF page with an Account values while using the ApexPages.currentPage().getParameters().get('custom-field-goes-here'); None of the fields populate. I am I mssing something??

 

ControllerExtenstion

public with sharing class LogACallControllerExtension {

    public Task task {get; set;}

    public LogACallControllerExtension(ApexPages.StandardController controller) {
            this.task = (Task)controller.getRecord();
            this.task.whatId = ApexPages.currentPage().getParameters().get('what_id'); 
            this.task.AMarket_Segment__c = ApexPages.currentPage().getParameters().get('Market_Segment_Copy__c');    
            this.task.subject = 'Outside Sales Call'; 
            this.task.type = 'Call';
            this.task.status = 'Completed';
            this.task.activitydate = Date.today();
    }
    
    
}

Visualforce Page

<apex:page standardController="Task" extensions="LogACallControllerExtension" docType="html-5.0" showHeader="false" standardStylesheets="false">


<div class="bootstrap" columns="1">
<apex:form >
   <div>
           <label>Related To</label><br />
            <apex:inputField style="form-control" value="{!Task.WhatId}" /><br /><br />
            
            </div>
            
            <label>Market Segment</label><br />
            <apex:inputField value="{!Task.AMarket_Segment__c }" /><br /><br />
            
            <label>Classification</label><br />
            <apex:inputField value="{!Task.Classification__c}" /><br /><br />
            
            <label>Call Type</label><br />
            <apex:inputField value="{!Task.Call_Type__c}" /><br /><br />
            
            <label>Sales Objective</label><br />
            <apex:inputField value="{!Task.All_Communities_Objective__c}" /><br /><br />
            
            <label>Accomplished</label><br />
            <apex:inputField style="form-control" value="{!Task.Accomplished__c}" />  <br/><br />
            
            <label>Next Steps</label><br />
            <apex:inputField style="form-control" value="{!Task.Next_Steps__c}" /><br /><br/>
            
            <label>Relevant Notes</label><br />
            <apex:inputField value="{!Task.Relevant_Notes__c}" /><br /><br />
            
<div id="formControls" >
<apex:commandButton action="{!quickSave}" value="Save"/>  </div>  
</apex:form>
</div>
</body>
</apex:page>

  • February 26, 2016
  • Like
  • 0
Hi,

I found this URL that shows how refresh token. However, it does not work for me
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_refresh_token_oauth.htm

I have this message error: 
Resfresh token error message
There are my request entries:
endpoint: https://test.salesforce.com/services/oauth2/token
grant_type: refresh_token,
client_id :
CLIENT_ID,
client_secret: CLIENT_SECRET,
 refresh_token: my_last_token,
 format :
 json


 
I'm not sure if this is the right place to post this question, but here goes:

I'm trying to set up a Workflow process that will generate a New Task when an Account field is altered.  My question is whether I can pass a parameter to the Subject line of the New Task that is the value of one of the Account fields.  So if someone types in "Contacted client and asked for case details"  in field X, I want to pass the value of X to the Subject line of the New Task.  

If this is the wrong place for this question, if someone could point me in the right direction, I'd appreciate it. 
Hi 
can I change my site domain http:/test-developer-edition.ap2.force.com/  to something like www.devtest.force.com or Any easy name.
Thanks 
Abhilash Mishra 
Hi,

Is it possible to create a trigger or schedule that will allow saleforce to change a picklist value after a certain period of time?

The scenario I can give is that some of our business users have requested if an account that has been closed can be re-opened as an outbound opportunity after it has been left dorment for 9 months?

Just looking to see if this is possible before I invest time in writing a script.

Thanks in advance!
Hello,

I have a pretty simple test class on a controller, which worked fine in my developer environment. However, I am now moving it to a sandbox and I'm running into an error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountTrigger: execution of BeforeInsert caused by: System.NullPointerException: Argument cannot be null.
Class.TriggerHandlerAccount.mapRegions: line 94, column 1
Class.TriggerHandlerAccount.beforeInsert: line 19, column 1
Trigger.AccountTrigger: line 6, column 1:


I know it's being caused by a trigger class that was created by a vendor for my organization, but I can'f figure out what I need to change in my test classes to avoid the error. Can anyone help?

Test Class for Controller:
@Istest
private class TestControllerShortForm
{
    static testMethod void testSFController1()
    {    
        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;

        Opportunity opp1 = TestCreateRecords.createOppNewSF(acct1.Id);
        insert opp1;

        Short_Form__c ESF1 = new Short_Form__c();
            ESF1.Sales_Representative__c = acct1.AM_owner__c;
            ESF1.Opportunity__c = opp1.Id;
            ESF1.Partner_Contact__c = '00337000006fBvQ';
            ESF1.Term_Length__c = 12;
            ESF1.Term_Metric__c = 'Months';
            ESF1.Additional_Terms__c = 'Test Test Test';

        ApexPages.StandardController SF1 = new ApexPages.standardController(opp1);
        VF_ShortFormController SFCont1 = new VF_ShortFormController(SF1);
        SFCont1.ESF.add(ESF1);
        SFCont1.ShortForm();
        SFCont1.save();

    }
}
Class Creating Records for Test Class:
// create and insert a new Account record.
    public static Account createAcct(Integer i){ 

    Account acct = new Account();
        acct.Name = 'Test' + i;
        acct.Language__c = 'English';
        acct.Industry = 'Automotive';
        acct.CurrencyIsoCode = 'USD';
        acct.Legal_Name__c = 'Test' + i;
        acct.Region__c = 'NA-US-NE';
        acct.BillingCity = 'New York';
        acct.BillingState = 'New York';
        acct.BillingCountry = 'United States';

    return acct;

    }


// create and insert a new Opportunity record that has the newly created Account record as its master record.
    public static Opportunity createOppNew (Id acctId){ 
        Opportunity opp2 = new Opportunity();
            opp2.AccountId = acctId;
            opp2.Name = 'Test Opportunity - ';
            opp2.StageName = System.Label.Eng_OppStage3;
            opp2.CloseDate = date.newinstance(2020,1,31);
            opp2.Amount = 1000;
            opp2.Region__c = 'NA-US-NE';
            opp2.Type = 'New Customer';
            opp2.Website_s__c = 'www.test.com; www.test2.com; www.test3.com';
        return opp2;
    }

// create and insert a new Opportunity record that has the newly created Account record as its master record. Used for Short Form.
    public static Opportunity createOppNewSF (Id acctId){ 
        Opportunity opp2a = new Opportunity();
            opp2a.AccountId = acctId;
            opp2a.Name = 'Test Opportunity - ';
            opp2a.StageName = System.Label.Eng_OppStage3;
            opp2a.CloseDate = date.newinstance(2020,1,31);
            opp2a.Amount = 1000;
            opp2a.Region__c = 'NA-US-NE';
            opp2a.Type = 'New Customer';
            opp2a.Website_s__c = 'www.test.com; www.test2.com; www.test3.com';
        return opp2a;
    }
}

Class Throwing Error:​
public with sharing class TriggerHandlerAccount {
    private boolean isExecuting = false;

    public TriggerHandlerAccount(boolean initIsExecuting) {
        isExecuting = initIsExecuting;
    }

    public void beforeInsert(List<Account> newAccounts) {
        setType(newAccounts);
        mapRegions(newAccounts);
        UpdateEnglishName(newAccounts, null);
    }

    public void beforeUpdate(List<Account> newAccounts, map<id, Account> oldAccountMap) {
        mapRegions(newAccounts);
        UpdateEnglishName(newAccounts, oldAccountMap);
    }

    public void afterInsert(List<Account> newAccounts) {
        updateRegionField(newAccounts, 'isInsert', newAccounts.size());
        accountHierarchyLeadSourceCalculation(new List<Account>(), newAccounts, 'isInsert', newAccounts.size());
    }


    private void UpdateEnglishName (List<Account> newAccounts, map<id, Account> oldAccountMap){
        for (Account account : newAccounts) {
            system.debug('oldAccountMap = ' + oldAccountMap);
            system.debug('oldAccountMap = ' + account.English_Account_Name__c);
            if ((oldAccountMap == null && account.English_Account_Name__c == null) ||
            (oldAccountMap != null && account.Name != oldAccountMap.get(account.id).Name && account.English_Account_Name__c == oldAccountMap.get(account.id).English_Account_Name__c))
            FillUpEnglishName(account);
        }
    }

    private void FillUpEnglishName (Account account) {
        if (account.Name == null || account.Name.trim() == '') return;
        String[] chars = account.Name.split('');
        // the 1st element in an Apex '' split is garbage; remove it:
        chars.remove(0);
        System.debug(chars);
        // change a char:
        string SC = SpecialCharacters__c.getInstance().Characters__c;
        boolean english = true;
        for (String c : chars) {
            if (!c.containsAny(SC))
                english = false;
        }
        system.debug('english = ' + english);
        if (english)
            account.English_Account_Name__c = account.Name;
    }


    private void setType(List<Account> newAccounts) {
        // If the Account is created with no Type but was converted from a Lead that had
        //    a Lead Type, set the Type from the Lead Type

        for (Account newAccount: newAccounts) {
            if (newAccount.Lead_Type__c != Null && newAccount.Type == Null) {
                newAccount.Type = newAccount.Lead_Type__c;
            }
        }
    }

    private void mapRegions(List<Account> newAccounts) {
        AccountRegionManager regionManager = new AccountRegionManager();
        Region_Mapper_Settings__c errorMessage = Region_Mapper_Settings__c.getInstance();
        for (Account newAccount: newAccounts) {
            String region = regionManager.getRegion(newAccount.BillingCountry, newAccount.BillingState);
            if (region != null) {
                newAccount.Region__c = region;
            } else {
                newAccount.addError(errorMessage.Invalid_Mapping_Message__c);
            }
        }
    }

    public static Boolean accountHierarchyLeadSourceCalculationEnable = true; 

     private void updateRegionField(List<Account> newAccounts, String triggerEvent, Integer triggerSize) {

        Boolean needUpdateRegion = false;
        map<Id , Account> accountsmap =  new map<Id, Account>();
        List<Account> accounts = new List<Account>();

         for(Integer i = 0; i < triggerSize; i++){
            Account tempaccount = new Account(id = newAccounts[i].id);
            if(triggerEvent == 'isInsert') 
                needUpdateRegion = newAccounts[i].Region__c == '' || newAccounts[i].Region__c == ' ' || newAccounts[i].Region__c == null;

            if (needUpdateRegion) 
            {
                accountsmap.put(newAccounts[i].OwnerId , newAccounts[i]);
            }
         }

         for(User u : [SELECT Id, Region__c FROM User WHERE Id IN :accountsmap.keyset()]){
                   Account tempaccount = new Account(id = accountsmap.get(u.id).id) ; 
                   tempaccount.Region__c = u.Region__c;
                   system.debug('Region to update: '+ tempaccount.Region__c);
                   accounts.add(tempaccount);
         }

         if (!accounts.isempty())
            update accounts;
     }
}

 
So I have a custom object standard controller and I want to auto-populate a field on a form from the users account record.

In preparation to build my controller I need a valid SOQL statement and I'm getting nested semi-join sub selects error on the Workbench.

I'm getting errors on the SOQL query:
 
select agency_acronym__C from account 
   where id in (SELECT AccountId FROM Contact 
   where id in (SELECT ContactId FROM User 
   where id in (SELECT OwnerId FROM Application__c)))


if this where in SQL Syntax I'd just use joins. I'm new to SOQL
 
select agency_acronym__c from 
account inner join contact on account.accountID = contact.accountID
inner join user on contact.contactid = user.contactid
inner join application__c on user.id = application__c.ownerid

Thanks,
Joe
For instance,
I have a trigger on opportunity and i would like to fire it only when certain named line items are added.
Example:i wantt to fire this trigger when product named-'ABCD' is added to that opportunity.
(I also have other conditions to be considered along with this,But this is major condition)
please help 
How to tag mandatory fields as minOccurs = "1" in the custom WSDL file that's generated from Apex class. Thanks in advance.
Hi I have created a trigger that should add an email as a ticket comment but it appears not to work. Can you review and let me know where the issue lies? Or if you have a better trigger to do this please let me know

trigger CaseEmails on Case (after insert, before insert) {

List<EmailMessage> emails;

List<CaseComment> comments = new List<CaseComment>();

for (EmailMessage email:emails)

{

Id CaseId = email.ParentId;

CaseComment comment = new CaseComment(ParentId=caseId);

String header = 'From: ' + email.FromName + ' <' + email.FromAddress + '>\n';

header += email.CcAddress!=null?'CC: '+ email.CcAddress + '\n\n':'\n';

if (email.TextBody!=null){

comment.CommentBody = header + email.TextBody; }

else if (email.HtmlBody!=null){

comment.CommentBody = header + email.TextBody; }

comments.add(comment);

}

if (!Comments.isEmpty())

{

insert comments;

}

}
Hi All,

I got nice little Opportunity Product application from Michaelforce which I've modified to suit our business and it's been fine till now.  Our Sales Reps have requested the ability to be able to add multiple search result lines to the "shopping cart" when adding products with a "Select All" button.

I have the following codes below, but my coding experience is minimal. 

Class Snippet:
public void addToShoppingCart(){
    
        // This function runs when a user hits "select" button next to a product
    
        for(PricebookEntry d : AvailableProducts){
            if((String)d.Id==toSelect){
                shoppingCart.add(new opportunityLineItem(OpportunityId=theOpp.Id, PriceBookEntry=d, PriceBookEntryId=d.Id, UnitPrice=d.UnitPrice));
                break;
            }
        }
        
        updateAvailableList();  
    }
    
    public void addAllToShoppingCart(){
    
        // This function runs when a user hits "add all" button
    
        for(PricebookEntry d : AvailableProducts){
                shoppingCart.add(new opportunityLineItem(OpportunityId=theOpp.Id, PriceBookEntry=d, PriceBookEntryId=d.Id, UnitPrice=d.UnitPrice));
        }
        
        updateAvailableList();  
    }

I was advised to add the "add all" method by a Java developer at our company.

VF Page Snippet:
<apex:column>
                            <apex:facet name="header"><apex:CommandButton value="Select All" action="{!addToShoppingCart}" reRender="selected,searchResults" immediate="true">
                                </apex:commandButton>
                            </apex:facet>                                                             
                            <!-- command button in a column... neato -->
                            <apex:CommandButton value="Select" action="{!addToShoppingCart}" reRender="selected,searchResults" immediate="true">
                                <!-- again we use apex:param to be able to tell the controller which row we are working with -->
                                <apex:param value="{!a.Id}" assignTo="{!toSelect}" name="toSelect"/>
                            </apex:commandButton>
                        </apex:column>

I can't seem to get the button to add any lines, I'm not sure if I'm missing apex:param values liek on the other standard select buttons, and if so, what would I use as a value to select all search result lines?

I know I can go the route of using checkboxes and wrappers to do this, but it woul dbe nice if it could be done with the button.

If anyone has any suggestions or can point me in the right direction, it would be appreciated.
Hello,

I am new for apex classes. I was trying to create a trigger which replicate the account recorded to custom object. All account standard and custom field.

Could someone help me please?

Thanks
 
  • January 28, 2016
  • Like
  • 1