• Kumaresan.Manickam
  • NEWBIE
  • 85 Points
  • Member since 2017
  • Salesforce Consultant
  • Over the moon..

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 24
    Replies
Hello All,
The 'Save' button on my VF page is inactive if a user does not complete all of the required field.  
Also, can I chnage the location of the error message?  The Save button is at the bottom the screen(mobile) and the user will not see the error at the top of the page.
Thanks,
M

VF Page
<apex:page docType="html-5.0" standardController="Account" extensions="SourcingAuditAccountController"  standardStylesheets="true" lightningStylesheets="true" showheader="false">
  
<div id="startLat">
</div>

<div id="startLon">
</div>

 <script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude;
            document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude;
            //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value);
           document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude;
           document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude;

        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
  </script>
  
    <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>  
    <script>
        Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel", onData:function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"true"}); 
        }});

        Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"false"}); 
            saveActivity();
        }});
    </script>
    
    <div>
        <apex:form id="inpform" >
            <apex:outputPanel id="out">           
                
             <apex:actionFunction action="{!Save}"  name="saveActivity" rerender="out"/> 

             <div style="display: none;">
                <apex:inputField value="{!SourcingAudit.Account__c}" />
                 ['Name'='Sourcing Audit for {!Account.Name} on system.today().format())' ], true)}">
             </div>
              
              <apex:outputPanel >  
                    <label style="display:block;margin-top:12px;margin-left:10px" for="account_name">Account</label>
                    <span style="margin-left:10px;" id="account_name">{!Account.Name}</span>
                    
                     <label style="display:block;margin-top:12px;margin-left:10px;" for="Contact__c">Select a Contact</label>
                    <apex:inputField style="margin-left:10px;" id="Contact__c" value="{!SourcingAudit.Contact__c}" required="true"/>
                </apex:outputPanel> 
               
                <br></br>
                     
                <apex:outputLabel style="margin-left:10px;"  value="Bale Quality Issue"/>            
                <apex:selectRadio required="true" value="{!SourcingAudit.Quality_Bale_Issue__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>  
                
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Bale Inspected"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Bales_Inspected__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                 <br></br>
            
                 <apex:outputLabel style="margin-left:10px;" value="Volume Review"/>
                <apex:selectRadio required="true"  value="{!SourcingAudit.Volume_Reviewed__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Weight Issue"/> 
                <apex:selectRadio required="true"   value="{!SourcingAudit.Weight_Issues__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Admin Review"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Admin_review__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Referral"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Referral__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
    
                <apex:outputPanel >
                    <label style="display:block;margin-top:12px;margin-left:10px;" for="comments">Comment</label>
                    <apex:inputTextarea style="margin-left:10px;" id="Audit_Comment__c" rows="3" cols="30" value="{!SourcingAudit.Audit_Comment__c}" />
                    
              </apex:outputPanel>
  
            </apex:outputPanel> 
        </apex:form>
    </div>
</apex:page>
 
public class SourcingAuditAccountController{
    private Sourcing_Audit__c  SourcingAudit;
    private Account Account;
    public String defaultCheck{get;set;}
    public string calljavascript {get; set;}
    public string message {get; set;} 

    public SourcingAuditAccountController(ApexPages.StandardController controller) 
    {
        Account = [SELECT Id, Name FROM Account WHERE Id =: controller.getId()];
        SourcingAudit = new Sourcing_Audit__c();
        SourcingAudit.Account__c = Account.Id;
     
    if(defaultCheck==NULL)
    {defaultCheck='Winchester';}
    
    }    

    public string PostSaveMessage {get; set;}
    public string Close {get; set;}

   
    public Sourcing_Audit__c  getSourcingAudit() {
        return SourcingAudit ;
    }    

    public Account getAccount() {
        return Account;
    }
   
    public PageReference Save()
    
    {
             
     RecordType rt;
        if(SourcingAudit.Audit_Location__c!= null)
            rt = [Select Id From RecordType Where DeveloperName = 'Warehouse' And sObjectType = 'Sourcing_Audit__c'];
        else
            rt = [Select Id From RecordType Where DeveloperName = 'Facility' And sObjectType = 'Sourcing_Audit__c'];
        SourcingAudit.RecordTypeId = rt.Id;
        
        System.debug('In Save method.');
        
        try {
        
        Insert SourcingAudit;
        PageReference pg = new PageReference('/'+SourcingAudit.Id);
        pg.setRedirect(true);  
        return pg;  
                    
        } 
        catch (Exception ex) {
            string message = ex.getMessage();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Fatal, message));
            return null;
        }
    }
   
}

 
Hi guys.

I'm struggling with a formula:

IF( Sales_Company__c = "FI", MID(ProductCode, 4, 12), ProductCode)

Now I need to add in another parameter in Sales Company. It should be both A1 and FI. 

I think I'm blanking out here.
  • September 12, 2019
  • Like
  • 0
If i need to creat an Order , I need to first creat an Account and then assign the AccountId to the Order, like the following
 Account a = new Account();
 a.Name = 'Test';
 insert a;    

 Order order = new Order(     
        AccountId = a.Id,
        Status='Draft',
        EffectiveDate = Date.today());
 insert order;

Is there a way to create an Order and the required fields will be populated including the AccountId that is linked to the Account?
Reason is that I am looking at dynamically crating tests for my SObjects.
So if i have a trigger on Order (after insert) , I want to create a test for this but do it through a dynamic templating that I can use for al SObjects .

Thanks
Use Case:-
Our system is designed to work with opportunity and its products to service our customers. Now we are planning to enable customers to self login and update created the opportunity by their own & asking them to add/remove products they want. Since customer community license doesn't support opportunity object to work with as per the profile I was thinking to use apex and Visual force page to create custom pages and perform DML via system context. is this something going to be an issue with salesforce audit if we do? If its an issue, how to get this mov forward?


My Research:- 
I was able to create VF page to display opportunity data with the use of wrapper classes (having primitive data type variables) & able to map the wrapper variables into opportunity fields via apex using system context. 

 
Dear Community,

I understand that SOQL for loops greatly helpful to avoid heap size problems while handling large set of records as it works via processing batch of request at a runtime instead of pulling whole large data at a time. But Is it best to use same SOQL for loop queries multiple times in the apex when i want to iterate a list more than once in the same context? I was concerned about performance problem if i repeat same queries more than once. Any suggestions & best practices would be very helpful

Thanks
Hello All,
The 'Save' button on my VF page is inactive if a user does not complete all of the required field.  
Also, can I chnage the location of the error message?  The Save button is at the bottom the screen(mobile) and the user will not see the error at the top of the page.
Thanks,
M

VF Page
<apex:page docType="html-5.0" standardController="Account" extensions="SourcingAuditAccountController"  standardStylesheets="true" lightningStylesheets="true" showheader="false">
  
<div id="startLat">
</div>

<div id="startLon">
</div>

 <script>
    window.onload = function() {
        var startPos;
        var geoSuccess = function(position) {
            startPos = position;
            document.getElementById('{!$Component.inpform.pb.pbs.startLat}').value=startPos.coords.latitude;
            document.getElementById('{!$Component.inpform.pb.pbs.startLon}').value=startPos.coords.longitude;
            //alert('@@@ ' + document.getElementsByClassName('findclass')[0].value);
           document.getElementsByClassName('Latclass')[0].value =startPos.coords.latitude;
           document.getElementsByClassName('Lonclass')[0].value =startPos.coords.longitude;

        };
        navigator.geolocation.getCurrentPosition(geoSuccess);
    };
  </script>
  
    <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>  
    <script>
        Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel", onData:function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"true"}); 
        }});

        Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e) { 
            Sfdc.canvas.publisher.publish({name:"publisher.setValidForSubmit", payload:"false"}); 
            saveActivity();
        }});
    </script>
    
    <div>
        <apex:form id="inpform" >
            <apex:outputPanel id="out">           
                
             <apex:actionFunction action="{!Save}"  name="saveActivity" rerender="out"/> 

             <div style="display: none;">
                <apex:inputField value="{!SourcingAudit.Account__c}" />
                 ['Name'='Sourcing Audit for {!Account.Name} on system.today().format())' ], true)}">
             </div>
              
              <apex:outputPanel >  
                    <label style="display:block;margin-top:12px;margin-left:10px" for="account_name">Account</label>
                    <span style="margin-left:10px;" id="account_name">{!Account.Name}</span>
                    
                     <label style="display:block;margin-top:12px;margin-left:10px;" for="Contact__c">Select a Contact</label>
                    <apex:inputField style="margin-left:10px;" id="Contact__c" value="{!SourcingAudit.Contact__c}" required="true"/>
                </apex:outputPanel> 
               
                <br></br>
                     
                <apex:outputLabel style="margin-left:10px;"  value="Bale Quality Issue"/>            
                <apex:selectRadio required="true" value="{!SourcingAudit.Quality_Bale_Issue__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>  
                
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Bale Inspected"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Bales_Inspected__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                 <br></br>
            
                 <apex:outputLabel style="margin-left:10px;" value="Volume Review"/>
                <apex:selectRadio required="true"  value="{!SourcingAudit.Volume_Reviewed__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Weight Issue"/> 
                <apex:selectRadio required="true"   value="{!SourcingAudit.Weight_Issues__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
                <br></br>
                
                <apex:outputLabel style="margin-left:10px;" value="Admin Review"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Admin_review__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>      
                
                 <br></br>
                
                 <apex:outputLabel style="margin-left:10px;" value="Referral"/> 
                <apex:selectRadio required="true"  value="{!SourcingAudit.Referral__c}" >
                <apex:selectOption itemValue="Yes" itemlabel="Yes"/>
                <apex:selectOption itemValue="No" itemlabel="No"/>
                </apex:selectRadio>
    
                <apex:outputPanel >
                    <label style="display:block;margin-top:12px;margin-left:10px;" for="comments">Comment</label>
                    <apex:inputTextarea style="margin-left:10px;" id="Audit_Comment__c" rows="3" cols="30" value="{!SourcingAudit.Audit_Comment__c}" />
                    
              </apex:outputPanel>
  
            </apex:outputPanel> 
        </apex:form>
    </div>
</apex:page>
 
public class SourcingAuditAccountController{
    private Sourcing_Audit__c  SourcingAudit;
    private Account Account;
    public String defaultCheck{get;set;}
    public string calljavascript {get; set;}
    public string message {get; set;} 

    public SourcingAuditAccountController(ApexPages.StandardController controller) 
    {
        Account = [SELECT Id, Name FROM Account WHERE Id =: controller.getId()];
        SourcingAudit = new Sourcing_Audit__c();
        SourcingAudit.Account__c = Account.Id;
     
    if(defaultCheck==NULL)
    {defaultCheck='Winchester';}
    
    }    

    public string PostSaveMessage {get; set;}
    public string Close {get; set;}

   
    public Sourcing_Audit__c  getSourcingAudit() {
        return SourcingAudit ;
    }    

    public Account getAccount() {
        return Account;
    }
   
    public PageReference Save()
    
    {
             
     RecordType rt;
        if(SourcingAudit.Audit_Location__c!= null)
            rt = [Select Id From RecordType Where DeveloperName = 'Warehouse' And sObjectType = 'Sourcing_Audit__c'];
        else
            rt = [Select Id From RecordType Where DeveloperName = 'Facility' And sObjectType = 'Sourcing_Audit__c'];
        SourcingAudit.RecordTypeId = rt.Id;
        
        System.debug('In Save method.');
        
        try {
        
        Insert SourcingAudit;
        PageReference pg = new PageReference('/'+SourcingAudit.Id);
        pg.setRedirect(true);  
        return pg;  
                    
        } 
        catch (Exception ex) {
            string message = ex.getMessage();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Fatal, message));
            return null;
        }
    }
   
}

 
This is driving me nuts because I know it should be pretty simple but my brain is having a moment. I have a field that is "today's date" so it updates every day. When that date is 1/1/XXXX, I want my process builder process to trigger. 

Process builder isn't giving me a option for "starts with", so I need a formula that will equal 1/1/current year.

Will DATE(year,1,1) work? I feel like I'm missing something here.

Thanks!
Hi,

I am trying to resolve a conflict from the existing Apex code. We have enrolments coming in from a different system but some of these are not being pushed to salesforce because of Apex CPU time limit exceeded error. it is identified that these are coming from one of the codes. Any recommendations to improve the code to avoid this error?


Trigger:
trigger UpdateLocalObjectsFromEnlighten on enlighten__Enrollment__c (after insert, after update) {
  if(TriggerUtilities.bPreventTriggers == true)
  {
    return;
  }
    
  UpdateLocalObjectsFromEnHandler handler = new UpdateLocalObjectsFromEnHandler();
  handler.doIt(trigger.new, trigger.oldMap);
  
}

Handler:
public with sharing class UpdateLocalObjectsFromEnHandler {
    
    private string debugInfo = '';
    
    private void addDebug(string inf) {
        
        debugInfo += inf + '\n';
    }
    
    public void doIt(List<enlighten__Enrollment__c> newVals, Map<id, enlighten__Enrollment__c> oldVals) {
        // all items to update
        
        // we need the first and last activities related to each enrolment, if available
        Map<string, ActivityInfo> activities = new Map<string, ActivityInfo>();
        
        enlighten__Course_Activity__c[] cas = 
        [select enlighten__Activity_Time__c, enlighten__Enrollment__c, enlighten__Module__r.name
        from enlighten__Course_Activity__c
        where enlighten__Enrollment__c in :newVals
        and (enlighten__Module__r.name = 'Module 1 Quiz' or
            enlighten__Module__r.name like '%final exam%')];
        
        addDebug('found ' + cas.size() + ' records');
        
        for(enlighten__Course_Activity__c ca : cas) {
            addDebug(ca.enlighten__Enrollment__c);
            if(!activities.containsKey(ca.enlighten__Enrollment__c)) {
                activities.put(ca.enlighten__Enrollment__c, new ActivityInfo());
            }
            
            if(ca.enlighten__Module__r.name == 'Module 1 Quiz') {
                activities.get(ca.enlighten__Enrollment__c).Started = ca.enlighten__Activity_Time__c;
                addDebug('Module 1 Quiz @ ' + ca.enlighten__Activity_Time__c);
            } else if(ca.enlighten__Module__r.name.toLowerCase().contains('final exam')) {
                activities.get(ca.enlighten__Enrollment__c).Completed = ca.enlighten__Activity_Time__c;
                addDebug('Final Exam @ ' + ca.enlighten__Activity_Time__c);
            } else {
                addDebug(ca.enlighten__Module__r.name + ' not found');
            }
        }
        
        Set<id> toFind = new Set<id>();
        //System.debug('-------------- start');
        for(enlighten__Enrollment__c i : newVals) {
            if(!toFind.contains(i.id)) {
                toFind.add(i.id);
                System.debug('********* ' + i.id);
            }
        }
        
        enlighten__Enrollment__c[] recs = 
        [select id, enlighten__Contact__c, enlighten__Course_Score__c, enlighten__Percent_Complete__c, 
            enlighten__Course_Enroll_Date__c, enlighten__Course_Complete_Date__c, enlighten__Status__c, 
            enlighten__Course__r.enlighten__Course_ID__c, enlighten__Enroll_End_Date__c, enlighten__Course_Complete__c,
            enlighten__Last_Access__c
        from enlighten__Enrollment__c 
        where id in: toFind];
        
        //System.debug('-------------- ' + recs.size());
        
        Set<string> CourseNames = new Set<string>();
        Set<id> contacts = new Set<id>();
        
        // Loop and find all the SF course names (removing dash as needed)
        // and related contacts
        
        for(enlighten__Enrollment__c e : recs) {
            
            if(e.enlighten__Course__c == null) {
                //System.debug('enlighten__Course__c does not have a value (1)');
                continue;
            }
                    
            string CourseName = e.enlighten__Course__r.enlighten__Course_ID__c;
            
            if(CourseName != '' && CourseName != null) {
                //System.debug('enlighten course name:' + CourseName);
                integer dash = CourseName.lastIndexOf('-');
                if(dash > -1) {
                   CourseName = CourseName.substring(0, dash).trim();
                }
              
                if(!CourseNames.contains(CourseName)) {
                   CourseNames.add(CourseName);
                   //System.debug(CourseName);
                }
            
                if(!contacts.contains(e.enlighten__Contact__c)) {
                   contacts.add(e.enlighten__Contact__c);
                }
            } else {
                //System.debug('CourseName from enlighten is empty or null');
            }
        }
        
        // now get potential matches -- this might retrieve more than needed but will be filtered below
        List<Student_Course_List__c> scls = 
            [select id, Student__c, course__c, course__r.name, Percent_Complete1__c, Percent_Grade__c,
                Number_Grade__c, Actual_End_Date__c, Actual_Start_Date__c, Scheduled_End_Date__c,
                Last_Access__c, Enlighten_Enrollment_ID__c, Course_Status__c
            from student_course_list__c 
            where Course__r.name in:  CourseNames
            and   Student__c in: contacts];
        
        //System.debug('=============SCL ==' + scls.size());
        
        // create a composite key of student+course name
        Map<string, Student_Course_List__c> sclLookup = new Map<string, Student_Course_List__c>();
        for(Student_Course_List__c scl: scls) {
            sclLookup.put(scl.Student__c + scl.course__r.name, scl);
        }
        
        Map<id, Student_course_list__c> toUpdate = new Map<id, Student_Course_List__c>();
        // loop again and find any student courses registrations that match the enlighted update
        for(enlighten__Enrollment__c e : recs) {
            
            if(e.enlighten__Course__c == null) {
                //System.debug('enlighten__Course__c does not have a value (2)');               
                continue;
            }
            
            string cn = e.enlighten__Course__r.enlighten__Course_ID__c;

            if(cn != '' && cn != null) {            
                integer dash = cn.lastIndexOf('-');
              
                if(dash > -1) {
                   cn = cn.substring(0, dash).trim();
                }
                //System.debug('***********************************updating ' + cn);
                // update the fields
                if(sclLookup.containsKey(e.enlighten__Contact__c + cn)) {
                    Student_Course_List__c item = sclLookup.get(e.enlighten__Contact__c + cn);
                    addDebug('found ' + e.enlighten__Contact__c + cn + ' status is ' + item.Course_Status__c);
                    if(item.Course_Status__c != 'Released') {
                        item.Percent_Complete1__c = e.enlighten__Percent_Complete__c;
                        item.Percent_Grade__c = e.enlighten__Course_Score__c;
                        item.Number_Grade__c = e.enlighten__Course_Score__c;
                        //item.Enrollment_Status__c = e.enlighten__Status__c;
                        item.Actual_Start_Date__c = e.enlighten__Course_Enroll_Date__c;
                        item.Scheduled_End_Date__c = e.enlighten__Enroll_End_Date__c;
                        //item.Course_Completed__c = e.enlighten__Course_Complete__c; 
                        //item.Last_Access__c = e.enlighten__Last_Access__c; // not being used
                        //item.Percent_Complete__c = e.enlighten__Percent_Complete__c;
                        item.Enlighten_Enrollment_ID__c = e.id;
                        //item.Course_Complete__c = e.enlighten__Course_Complete__c; // handled by formula
                        
                        ActivityInfo act = activities.get(e.id);
                        
                        if(act != null) {
                            if(act.Started != null) {
                                item.Activity_Started__c = act.Started;
                                addDebug('setting Activity_Started__c ' + act.Started);
                            } else {
                                addDebug('no start date for ' + e.id);
                            }
                            if(act.Completed != null) {
                                item.Activity_Completed__c = act.Completed;
                                addDebug('setting Activity_Completed__c ' + act.Completed);                         
                            } else {
                                addDebug('no end date for ' + e.id);
                            }
                        } else {
                            addDebug('not found for ' + e.id);
                        }
                        
                        // if more than one update for this student course registration, use the most recent one
                        toUpdate.put(item.id, item);
                        //System.debug('updating SCR ' + item.id + ' contact ' + e.enlighten__Contact__c + ' ' + cn);
                    }
                } else {
                    
                    addDebug('did not find ' + e.enlighten__Contact__c + cn);
                }
            }
        } // end for

        update toUpdate.values();
        
        // now update number of courses on this day
        
        List<Student_Course_List__c> countCoursesEnrolled = new List<Student_Course_List__c>();
        Map<string, integer> sums = new Map<string, integer>();
        string lastKey = '';
        string key = '';
        integer courseCount = 0;
        
        scls = 
            [select id, Student__c, Count_of_Courses_Enrolled__c, 
             Enlighten_Enrollment_ID__r.enlighten__Course_Enroll_Date__c,
             Full_Time__c, Course__r.Course_Length_Days__c
            from student_course_list__c 
            where Student__c in: contacts
            and Enlighten_Enrollment_ID__r.enlighten__Course_Enroll_Date__c != null
            and Asynchronous__c = true
            order by Student__c, Enlighten_Enrollment_ID__r.enlighten__Course_Enroll_Date__c];      
        
        integer totalRecs = scls.size();
        integer recCount = 0;
        
        //System.debug('----totalRecs ' + totalRecs);
        
        // summarize by student + date + course length  
        for(Student_Course_List__c s2 : scls) {
            Date dt = s2.Enlighten_Enrollment_ID__r.enlighten__Course_Enroll_Date__c;
            
            key = s2.student__c + String.valueOf(dt) + String.valueOf(s2.Course__r.Course_Length_Days__c);
            //System.debug('key=' + key);
            recCount++;
            
            if(key != lastKey || recCount == totalRecs) {
                if(key == lastKey) {
                    courseCount++;
                }
                sums.put(lastKey, courseCount);
                courseCount = 0;
            }
            
            lastKey = key;
            //System.debug('lastKey=' + lastKey);
            courseCount++;
        }
        
        //System.debug('doing updates, if any===============');
        // now go through and see if any of the values need to be updated
        for(Student_Course_List__c s2 : scls) {
            Date dt = s2.Enlighten_Enrollment_ID__r.enlighten__Course_Enroll_Date__c;           
            key = s2.student__c + string.valueOf(dt) + String.valueOf(s2.Course__r.Course_Length_Days__c);  
            //System.debug('key=' + key);       
            integer sumVal = sums.get(key);
            //System.debug('sumVal=' + sumVal);
            if(s2.Count_of_Courses_Enrolled__c != sumVal) {
                s2.Count_of_Courses_Enrolled__c = sumVal;
                countCoursesEnrolled.add(s2);
            }
        }
        
        // Count_of_Courses_Enrolled
        if(countCoursesEnrolled.size() > 0) {
            update countCoursesEnrolled;
        }
        
        System.debug(debugInfo);
    }
    
    private class ActivityInfo {
        public string EnrolmentId { get; set;}
        public DateTime Started { get; set;}
        public DateTime Completed { get; set;}
    }
}

 
Hi All,

I have a read only lookup field on Opportunity Page layout.
I am cloning the record so loosing the data of this field that is expected behavior of alesforce but on production it is copying the read only field value on cloning the record.
I compared profile on QA and Prod. It has same access on both environment.
Can any one help me to find out the reason that why it is working on Prod?
 
I have an apex extension controller that i need to write a test class, but I'm not sure how to write a test class for this type of controller. Any help would be greatly appreciated. My code is below.
 
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id,IsAddedToPDF__c,Customer__r.Service_Agreement_Verbiage__c,Site__c,Site__r.Contract_Start_Date__c,Site__r.Contract_End_Date__c,Site__r.Customer_Location_ID__c,Service_Year__c,Customer__r.Contract_Start_Date__c,Name,Customer__r.Contract_End_Date__c,Site__r.Name,Customer__r.Name,Primary_Contact__r.FirstName,Site__r.BillingCity,Site__r.BillingState,Site__r.BillingStreet,Site__r.BillingPostalCode  FROM Bids_Sent__c WHERE Awarded__c =: acc.Id AND IsAddedToPDF__c=true];
    
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__r.Name,Site__c,Contract_Start_Month__c,Site__r.Customer_Location_ID__c,Cost__c,Customer__r.Contract_Month__c,Increment__c,Total__c,Price__c,Scope__c,Bid_Name__r.Service_Type__c,Number_of_Months__c,Retainer_Fee__c,Monthly_Payment__c,UOM__c  FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        
        if(bidsMap.containsKey(bd.Bid_Name__r.Name)){
  System.debug('CONTAINS KEY: ' + bd.Bid_Name__r.Name);
  bidsMap.get(bd.Bid_Name__r.Name).add(bd);
} else { 
  System.debug('CREATE: ' + bd.Bid_Name__r.Name);
  bidsMap.put(bd.Bid_Name__r.Name,new List<Site_Bid_Details__c>{bd}); 
}
    } 

}

}

 
  • September 12, 2019
  • Like
  • 0
User-added imageHi Friends,
We are unable to convert the lead to contact, getting an error.
Please give me the valuable suggestions.

Thanks in Advance
  • September 12, 2019
  • Like
  • 0
Hi Team
can anyone provide code for below scenario by using Triggers:
When all child cases  closed/ cancelled / Completed, then parent case also be Closed /Cancelled / Completed...
Can you pls provide code for this ...........Thanks
  • September 12, 2019
  • Like
  • 0
Hi guys.

I'm struggling with a formula:

IF( Sales_Company__c = "FI", MID(ProductCode, 4, 12), ProductCode)

Now I need to add in another parameter in Sales Company. It should be both A1 and FI. 

I think I'm blanking out here.
  • September 12, 2019
  • Like
  • 0
Hi All,
Need help in creating Visualforce Page for the below scenario.
OutOftheBox, we can only add one Product to a Case. In my Case I have to add multiple Products to a Case, so I have created the Junction object and I can able to add the Multiple Products to case. Adding Multiple Products to a case is taking more time. 
I have create a Custom Button, which will popup all the Products and I should able to select the Products and Save those.
We have this kind of Functionality in Opportunity-->Products by using Add Products Button. I have to mimic below kind of page.

User-added imageUser-added imageAs of now, I am able to create a button and invoked the VFpage and it looks like below
User-added imageBelow is my Code:
<apex:page standardController="Product2" recordSetVar="accounts">
         <apex:form >
        <apex:pageBlock title="Product List">
        <apex:commandLink action="{!Next}">Next</apex:CommandLink>
            <apex:pageBlockTable value="{!accounts}" var="a">
                      <apex:column >
                        <apex:facet name="header">
                            Account Name
                        </apex:facet>
                        <apex:facet name="footer">
                            End Of table
                        </apex:facet>
                    <apex:outputField value="{!a.Name}"/>
                </apex:column>
                <apex:column >
                <apex:facet name="header">
                            Account Type
                        </apex:facet>
                        <apex:facet name="footer">
                            End Of table
                        </apex:facet>
                    <apex:outputText value="{!a.ProductCode}"/>
                </apex:column>
                </apex:pageBlockTable>
            <apex:commandLink action="{!previous}">Previous</apex:CommandLink>&nbsp;
                </apex:pageBlock>
        </apex:form>
</apex:page>
 
  • September 11, 2019
  • Like
  • 0
If i need to creat an Order , I need to first creat an Account and then assign the AccountId to the Order, like the following
 Account a = new Account();
 a.Name = 'Test';
 insert a;    

 Order order = new Order(     
        AccountId = a.Id,
        Status='Draft',
        EffectiveDate = Date.today());
 insert order;

Is there a way to create an Order and the required fields will be populated including the AccountId that is linked to the Account?
Reason is that I am looking at dynamically crating tests for my SObjects.
So if i have a trigger on Order (after insert) , I want to create a test for this but do it through a dynamic templating that I can use for al SObjects .

Thanks
Hi,

I'm not able to complete #2 Automate Accounts. It give me the following error.
"Challenge Not yet complete... here's what's wrong:
Please check the configuration of the custom fields on the Account object. The formulas, rollup summaries, etc. did not produce the expected outcome."


Can anyone tell me what went wrong? Thanks.

My Custom Fields configuration are as following:
  • Number of deals (Roll-Up Summary field): Count Opportunity. No filter criteria
  • Number of won deals (Roll-Up Summary field): Count Opportunity with filter criteria as "Stage equals Closed Won"
  • Last won deal date (Roll-Up Summary field): MAX(Opportunity: Close Date) with filter criteria as "Stage equals Closed Won"
  • Deal win % (Formula field): Number_of_won_deals__c / Number_of_deals__c
  • Total amount of won deals (Roll-Up Summary field): SUM(Opportunity: Amount) with filter criteria as "Stage equals Closed Won"
  • Call for Service (Formula field): IF( DATE( YEAR(Last_won_deal_date__c)+2 , MONTH(Last_won_deal_date__c) , DAY(Last_won_deal_date__c) ) <= TODAY(), 'YES', 'NO')