• Terri Henry
  • NEWBIE
  • 50 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies
Hi Everyone,

I've got a class that uses Box's Toolkit to make a callout to change a folder's name - it's invocable and is triggered on Salesforce record name change (and works!)

Coming into difficultly running the test class as I'm getting the error message of "System.TypeException: Supplied type is not an interface" when running the test class with the Stack Trace of "(System Code)
Class.BoxFolderRenamerTest.testRenameBoxFolder: line 34, column 1"

Any ideas how to change the test class to provide coverage?
 
public class BoxFolderRenamer {
    
    @InvocableMethod(label='Rename Box Folder' description='Renames a Box folder')
    public static void renameBoxFolder(List<BoxFolderRenameRequest> requests) {
        
        // Instantiate the Toolkit object
        box.Toolkit boxToolkit = new box.Toolkit();
        
        for (BoxFolderRenameRequest request : requests) {
            // Prepare the API endpoint URL for folder renaming
            String endpointUrl = 'https://api.box.com/2.0/folders/' + request.folderId;
            
            // Create a Map for the new folder name
            Map<String, Object> folderUpdate = new Map<String, Object>();
            folderUpdate.put('name', request.newName);
            
           // Create a new HttpRequest object and set appropriate values
            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setHeader('Content-Type', 'application/json');
            httpRequest.setEndpoint(endpointUrl);
            httpRequest.setMethod('PUT');
            httpRequest.setBody(JSON.serialize(folderUpdate));
            
            //HttpResponse httpResponse = new Http().send(httpRequest);
            // Send the HttpRequest through the generic Toolkit method, which will handle the authentication details
            HttpResponse httpResponse = boxToolkit.sendRequest(httpRequest);
            
            // Handle the response as needed
            if (httpResponse.getStatusCode() != 200) {
                System.debug('Response Code: ' + httpResponse.getStatusCode() + '. Response Status: ' + httpResponse.getStatus());
                system.debug('most recent error: ' + boxToolkit.mostRecentError);
            }
        }
        
        // ALWAYS call this method when finished. Since salesforce doesn't allow http callouts after dml operations, we need to commit the pending database inserts/updates or we will lose the associations created
        boxToolkit.commitChanges();
    }
    
    // Wrapper class for the Box folder rename request - variables to be passed from Flow
    public class BoxFolderRenameRequest {
        @InvocableVariable(label='Folder ID' required=true)
        public String folderId;
        
        @InvocableVariable(label='New Folder Name' required=true)
        public String newName;
    }
}

Test Class
@isTest
public class BoxFolderRenamerTest {
    // Create a mock HTTP callout response
    public class MockHttpResponse implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest request) {
            HttpResponse httpResponse = new HttpResponse();
            httpResponse.setHeader('Content-Type', 'application/json');
            httpResponse.setBody('{"status": "success"}');
            httpResponse.setStatusCode(200);
            return httpResponse;
        }
    }
    @isTest
    public static void testRenameBoxFolder() {
        // Create test data
        List<BoxFolderRenamer.BoxFolderRenameRequest> testRequests = new List<BoxFolderRenamer.BoxFolderRenameRequest>();
        // Add test request(s)
        BoxFolderRenamer.BoxFolderRenameRequest request1 = new BoxFolderRenamer.BoxFolderRenameRequest();
        request1.folderId = 'folderId';
        request1.newName = 'New Folder Name';
        testRequests.add(request1);
        // Set the mock HTTP callout response
        Test.setMock(HttpCalloutMock.class, new MockHttpResponse()); 
        // Invoke the renameBoxFolder method
        Test.startTest();  
        BoxFolderRenamer.renameBoxFolder(testRequests); 
        Test.stopTest();
    }
}


 
Hi All, 

I have created a trigger to prevent the deactivation of a user if they own any Accounts, Contacts or unconverted leads - as this causes issues with the Pardot sync (the Marketing team lead me to believe)

The trigger works as expected, though I'm aware that with containing SOQL queries within the FOR loop I'm breaking best practice - but would there be a performance issue on taking this out of the loop and running them on every update (even when they are not needed)

Constructive criticism welcomed

Thanks
 
//Trigger to prevent deactivation of user if they own any records referenced by Pardot.
//Deactivating a user while they still own these records (accounts, contacts, uncoverted leads) will cause issues with Pardot sync

trigger UserPreventDeactivation on User (before update) {
  
    for(User u : Trigger.new){
        User oldU = Trigger.oldMap.get(u.Id);  
        
        //Check if user has changed from active to inactive
        if(!u.IsActive && oldU.IsActive){
            
            //Query number of Accounts, Contacts and Unconverted Leads in User's Name
        	//SHOULD BE OUTSIDE OF LOOP TO BE BULKIFIED? but don't want to run these queries on every update to user if not needed.
        	//but as have only internal users, not likely to deactivate users in bulk
        	Integer contactCount = [SELECT count()
                                      FROM Contact
                                     WHERE ownerId = :u.id
                                     LIMIT 1]; 
        	Integer accountCount = [SELECT count()
                                      FROM Account
                                     WHERE ownerId = :u.id
                                     LIMIT 1];
        	Integer leadCount = [SELECT count()
                                   FROM Lead
                                  WHERE ownerId = :u.id
                                    AND isConverted = FALSE
                                  LIMIT 1];
            
            //add error to screen alerting user
            if( (contactCount + accountCount + leadCount) > 0){
            	u.addError('This user may own accounts, contacts, or unconverted leads.' +
                          'Ensure that these records are transferred to a different owner ' +
                          'before deactivating this user. This is due to issues it will cause ' +
                          'with the Pardot sync.');    
            }     
        }
    }
}



 
Racking my brains as to why I can't get the final two lines to pass and hit 100% coverage

It's both branches of the IF statement outstanding, but I thought I had captured that with generating 2 different account records

Any pointers much appreciated!

CLASS
public without sharing class lastViewedAccount{
    public Datetime cDT;
    public String LongDate;
    public String firstname;
    public String lastname;
    public String existinglastviewed;
    public String userid;
    private final Account acc;
    
    public lastViewedAccount(ApexPages.StandardController stdController) {
        this.acc = (Account)stdController.getRecord();
    }
    
    public String getLongDate() {
        cDT = System.now();
        //Formats the datetime value to locale
        LongDate = cDT.format('dd/MM/yyyy HH:mm');
        return LongDate;
    }
    
    
    public void updateField() {
        //Get the user info from the current user
        firstname = System.Userinfo.getFirstName();
        lastname = System.Userinfo.getLastName();
        userid = System.Userinfo.getUserId();
        //Get the Opportunity record to be updated
        Account a = [select Last_Viewed_By__c, Track_Record__c from Account where id = :acc.id limit 1];
        //get existing string of the record, so that new view can be appended to the end of this
        existinglastviewed = a.Last_Viewed_By__c;
        //check to see if the Opportunity has been flagged for tracking
        if(a.Track_Record__c){
            //Assign values to Last Viewed By field and update the record - only concatenate if there is a value there already
            if(existinglastviewed != null){
                a.Last_Viewed_By__c = (existinglastviewed + '; \n' + firstname + ' ' + lastname + ' ' + getLongDate());
            }
            else a.Last_Viewed_By__c = (firstname + ' ' + lastname + ' ' + getLongDate());
            update a;
        }    
    }
    
}

TEST CLASS
@isTest
public with sharing class lastViewedAccountTest {


    static testMethod void triggerTest() {
        
        //Create Account1 - with pre-existing 'Last Viewed By' populated - to test if statement
        Account testAccount1 = new Account(Name = 'testAccount');
        testAccount1.Company_Registered_Number_SOC__c = '00000000';
        testAccount1.Primary_Sector__c = 'Business Goods & Services';
        testAccount1.Sub_Sector__c = 'Point of Sale';
        testAccount1.Organisation_type_SOC__c = 'Limited Company'; 
        testAccount1.Street_Head_Office_SOC__c = 'Test Street'; 
        testAccount1.City_Head_Office_SOC__c = 'London'; 
        testAccount1.Country_Head_Office_SOC__c = 'United Kingdom';
        testAccount1.Last_Viewed_By__c = 'Example User';
        insert testAccount1;
 
 
        ApexPages.StandardController sc1 = new ApexPages.StandardController(testAccount1);
        lastViewedAccount lastViewedAcc1 = new lastViewedAccount(sc1);
        
        System.assert(!String.isEmpty(lastViewedAcc1.getLongDate()));
        lastViewedAcc1.updateField();
        
        
              
        //Create Opportunity 2 - with no 'Last Viewed By' data - to check 2nd branch of if statement
        Account testAccount2 = new Account(Name = 'testAccount');
        testAccount2.Company_Registered_Number_SOC__c = '00000000';
        testAccount2.Primary_Sector__c = 'Business Goods & Services';
        testAccount2.Sub_Sector__c = 'Point of Sale';
        testAccount2.Organisation_type_SOC__c = 'Limited Company'; 
        testAccount2.Street_Head_Office_SOC__c = 'Test Street'; 
        testAccount2.City_Head_Office_SOC__c = 'London'; 
        testAccount2.Country_Head_Office_SOC__c = 'United Kingdom';
        insert testAccount2;
 
 
        ApexPages.StandardController sc2 = new ApexPages.StandardController(testAccount2);
        lastViewedAccount lastViewedAcc2 = new lastViewedAccount(sc2);
        
        System.assert(!String.isEmpty(lastViewedAcc2.getLongDate()));
        lastViewedAcc2.updateField();
        
        
    }   

}

Hi All, 

I've amended a solution for tracking page views I found here:
https://success.salesforce.com/answers?id=9063A000000Dq6MQAS

I'm using it to track who has viewed an Opportunity record page - however I have no idea where to start with the test class - I'm currently working through a couple of trailhead modules, though any pointers would be greatly appreciated

Thanks

Terri 
 
public without sharing class lastViewedOpportunity{
    public Datetime cDT;
    public String LongDate;
    public String firstname;
    public String lastname;
    public String existinglastviewed;
    public String userid;
    private final Opportunity opp;
    
    public lastViewedOpportunity(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
    }
    
    public String getLongDate() {
        cDT = System.now();
        //Formats the datetime value to locale
        LongDate = cDT.format('dd/MM/yyyy HH:mm');
        return LongDate;
    }
    
    
    public void updateField() {
        //Get the user info from the current user
        firstname = System.Userinfo.getFirstName();
        lastname = System.Userinfo.getLastName();
        userid = System.Userinfo.getUserId();
        //Get the Opportunity record to be updated
        Opportunity o = [select Last_Viewed_By__c, Track_Record__c from Opportunity where id = :opp.id limit 1];
        //get existing string of the record, so that new view can be appended to the end of this
        existinglastviewed = o.Last_Viewed_By__c;
        //check to see if the Opportunity has been flagged for tracking
        if(o.Track_Record__c){
            //Assign values to Last Viewed By field and update the record - only concatenate if there is a value there already
            if(existinglastviewed != null){
                o.Last_Viewed_By__c = (existinglastviewed + '; \n' + firstname + ' ' + lastname + ' ' + getLongDate());
            }
            else o.Last_Viewed_By__c = (firstname + ' ' + lastname + ' ' + getLongDate());
            update o;
        }    
    }
    
}

 
Hi All, 

Process Builder can of course create Chatter Posts from record changes - but I'm interested in doing it the other way round; can a Chatter Post (where @[Salesforce Support] is mentioned) create a Case Record (of a specific record type)?

How easy would this be?
I have a button that launches a flow (flow has a single step to trigger class to run assignment rule)
 
/flow/LeadAssignmentRuleRun?SingleLead={!Lead.Id}&retURL=%2F{!Lead.Id}

This works perfectly in Classic UI, however when launched through the Service Console it renders the classic UI as an iframe before reloading again as Console (not great UX):

SCREENSHOT: Prior to clicking button that launches above URL

Correct render of Service Console before pressing button

SCREENSHOT: After flow finishes and Classic UI is rendered as iframe before reloading as Service Console

Classic UI rendered as iframe within Cosole

The console will then rerender and go back to the correct service console styling

Do I need to change this into a javascript button to handle Classic UI and Service Console separately?

Thanks in advance
Does anyone have any interesting ideas for making the most of the new increased limit amount of Developer Sandboxes?

Our org has a 100 developer sandboxes, with only 7 being actively used for development.

An idea I had would be to use them for weekly metadata backups - monthly/weekly refreshes would hardly make a dent in the total available

It would remove the requirement to use a paid back up service OR remove the security concerns about backing up data to an external source

Any other ideas?
Hi All,

I need to create a trigger that "rolls up" the field Amount__c from a custom object Sessions to a custom object called Session_Invoice to a field called Invoice_Amount - I can't use a rollup summary field unfortunately as it's just a lookup relationship.

I'm quite new to Salesforce and Coding, so struggling where to start!

Any help would be much appreciated
 
trigger SessionAmountRollup on Session__c (after insert, after update, after delete, after undelete) {
  
}

 
Hi All!

I currently have a button on the 'Lead' page, that opens a VF page with a Flow inside:

VF Page:
<apex:page standardController="Lead"> <h1>Create A Premier Quick Task</h1> <flow:interview name="QuickPremierTask" finishLocation="/{!id}"> <apex:param name="LeadID" value="{!ID}"/> <apex:param name="UserID" value="{!$User.Id}"/> </flow:interview> </apex:page>

I want to add Validation in the button code that will only allow the button to be clicked (to launch the VF page flow) if the fields 'Lead Source' or 'Initial Lead Source' are equal to the text 'Premier 1'

Normally I would simlpy exclude the button from the page layout with the use of a new Record Type, however this is not an option in this instance.

Can this be done using Javascript in the button code? (Or an alternate option)

Winning answer gets 10 internets!
Hi Everyone,

I've got a class that uses Box's Toolkit to make a callout to change a folder's name - it's invocable and is triggered on Salesforce record name change (and works!)

Coming into difficultly running the test class as I'm getting the error message of "System.TypeException: Supplied type is not an interface" when running the test class with the Stack Trace of "(System Code)
Class.BoxFolderRenamerTest.testRenameBoxFolder: line 34, column 1"

Any ideas how to change the test class to provide coverage?
 
public class BoxFolderRenamer {
    
    @InvocableMethod(label='Rename Box Folder' description='Renames a Box folder')
    public static void renameBoxFolder(List<BoxFolderRenameRequest> requests) {
        
        // Instantiate the Toolkit object
        box.Toolkit boxToolkit = new box.Toolkit();
        
        for (BoxFolderRenameRequest request : requests) {
            // Prepare the API endpoint URL for folder renaming
            String endpointUrl = 'https://api.box.com/2.0/folders/' + request.folderId;
            
            // Create a Map for the new folder name
            Map<String, Object> folderUpdate = new Map<String, Object>();
            folderUpdate.put('name', request.newName);
            
           // Create a new HttpRequest object and set appropriate values
            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setHeader('Content-Type', 'application/json');
            httpRequest.setEndpoint(endpointUrl);
            httpRequest.setMethod('PUT');
            httpRequest.setBody(JSON.serialize(folderUpdate));
            
            //HttpResponse httpResponse = new Http().send(httpRequest);
            // Send the HttpRequest through the generic Toolkit method, which will handle the authentication details
            HttpResponse httpResponse = boxToolkit.sendRequest(httpRequest);
            
            // Handle the response as needed
            if (httpResponse.getStatusCode() != 200) {
                System.debug('Response Code: ' + httpResponse.getStatusCode() + '. Response Status: ' + httpResponse.getStatus());
                system.debug('most recent error: ' + boxToolkit.mostRecentError);
            }
        }
        
        // ALWAYS call this method when finished. Since salesforce doesn't allow http callouts after dml operations, we need to commit the pending database inserts/updates or we will lose the associations created
        boxToolkit.commitChanges();
    }
    
    // Wrapper class for the Box folder rename request - variables to be passed from Flow
    public class BoxFolderRenameRequest {
        @InvocableVariable(label='Folder ID' required=true)
        public String folderId;
        
        @InvocableVariable(label='New Folder Name' required=true)
        public String newName;
    }
}

Test Class
@isTest
public class BoxFolderRenamerTest {
    // Create a mock HTTP callout response
    public class MockHttpResponse implements HttpCalloutMock {
        public HTTPResponse respond(HTTPRequest request) {
            HttpResponse httpResponse = new HttpResponse();
            httpResponse.setHeader('Content-Type', 'application/json');
            httpResponse.setBody('{"status": "success"}');
            httpResponse.setStatusCode(200);
            return httpResponse;
        }
    }
    @isTest
    public static void testRenameBoxFolder() {
        // Create test data
        List<BoxFolderRenamer.BoxFolderRenameRequest> testRequests = new List<BoxFolderRenamer.BoxFolderRenameRequest>();
        // Add test request(s)
        BoxFolderRenamer.BoxFolderRenameRequest request1 = new BoxFolderRenamer.BoxFolderRenameRequest();
        request1.folderId = 'folderId';
        request1.newName = 'New Folder Name';
        testRequests.add(request1);
        // Set the mock HTTP callout response
        Test.setMock(HttpCalloutMock.class, new MockHttpResponse()); 
        // Invoke the renameBoxFolder method
        Test.startTest();  
        BoxFolderRenamer.renameBoxFolder(testRequests); 
        Test.stopTest();
    }
}


 
Hi All, 

I have created a trigger to prevent the deactivation of a user if they own any Accounts, Contacts or unconverted leads - as this causes issues with the Pardot sync (the Marketing team lead me to believe)

The trigger works as expected, though I'm aware that with containing SOQL queries within the FOR loop I'm breaking best practice - but would there be a performance issue on taking this out of the loop and running them on every update (even when they are not needed)

Constructive criticism welcomed

Thanks
 
//Trigger to prevent deactivation of user if they own any records referenced by Pardot.
//Deactivating a user while they still own these records (accounts, contacts, uncoverted leads) will cause issues with Pardot sync

trigger UserPreventDeactivation on User (before update) {
  
    for(User u : Trigger.new){
        User oldU = Trigger.oldMap.get(u.Id);  
        
        //Check if user has changed from active to inactive
        if(!u.IsActive && oldU.IsActive){
            
            //Query number of Accounts, Contacts and Unconverted Leads in User's Name
        	//SHOULD BE OUTSIDE OF LOOP TO BE BULKIFIED? but don't want to run these queries on every update to user if not needed.
        	//but as have only internal users, not likely to deactivate users in bulk
        	Integer contactCount = [SELECT count()
                                      FROM Contact
                                     WHERE ownerId = :u.id
                                     LIMIT 1]; 
        	Integer accountCount = [SELECT count()
                                      FROM Account
                                     WHERE ownerId = :u.id
                                     LIMIT 1];
        	Integer leadCount = [SELECT count()
                                   FROM Lead
                                  WHERE ownerId = :u.id
                                    AND isConverted = FALSE
                                  LIMIT 1];
            
            //add error to screen alerting user
            if( (contactCount + accountCount + leadCount) > 0){
            	u.addError('This user may own accounts, contacts, or unconverted leads.' +
                          'Ensure that these records are transferred to a different owner ' +
                          'before deactivating this user. This is due to issues it will cause ' +
                          'with the Pardot sync.');    
            }     
        }
    }
}



 
Racking my brains as to why I can't get the final two lines to pass and hit 100% coverage

It's both branches of the IF statement outstanding, but I thought I had captured that with generating 2 different account records

Any pointers much appreciated!

CLASS
public without sharing class lastViewedAccount{
    public Datetime cDT;
    public String LongDate;
    public String firstname;
    public String lastname;
    public String existinglastviewed;
    public String userid;
    private final Account acc;
    
    public lastViewedAccount(ApexPages.StandardController stdController) {
        this.acc = (Account)stdController.getRecord();
    }
    
    public String getLongDate() {
        cDT = System.now();
        //Formats the datetime value to locale
        LongDate = cDT.format('dd/MM/yyyy HH:mm');
        return LongDate;
    }
    
    
    public void updateField() {
        //Get the user info from the current user
        firstname = System.Userinfo.getFirstName();
        lastname = System.Userinfo.getLastName();
        userid = System.Userinfo.getUserId();
        //Get the Opportunity record to be updated
        Account a = [select Last_Viewed_By__c, Track_Record__c from Account where id = :acc.id limit 1];
        //get existing string of the record, so that new view can be appended to the end of this
        existinglastviewed = a.Last_Viewed_By__c;
        //check to see if the Opportunity has been flagged for tracking
        if(a.Track_Record__c){
            //Assign values to Last Viewed By field and update the record - only concatenate if there is a value there already
            if(existinglastviewed != null){
                a.Last_Viewed_By__c = (existinglastviewed + '; \n' + firstname + ' ' + lastname + ' ' + getLongDate());
            }
            else a.Last_Viewed_By__c = (firstname + ' ' + lastname + ' ' + getLongDate());
            update a;
        }    
    }
    
}

TEST CLASS
@isTest
public with sharing class lastViewedAccountTest {


    static testMethod void triggerTest() {
        
        //Create Account1 - with pre-existing 'Last Viewed By' populated - to test if statement
        Account testAccount1 = new Account(Name = 'testAccount');
        testAccount1.Company_Registered_Number_SOC__c = '00000000';
        testAccount1.Primary_Sector__c = 'Business Goods & Services';
        testAccount1.Sub_Sector__c = 'Point of Sale';
        testAccount1.Organisation_type_SOC__c = 'Limited Company'; 
        testAccount1.Street_Head_Office_SOC__c = 'Test Street'; 
        testAccount1.City_Head_Office_SOC__c = 'London'; 
        testAccount1.Country_Head_Office_SOC__c = 'United Kingdom';
        testAccount1.Last_Viewed_By__c = 'Example User';
        insert testAccount1;
 
 
        ApexPages.StandardController sc1 = new ApexPages.StandardController(testAccount1);
        lastViewedAccount lastViewedAcc1 = new lastViewedAccount(sc1);
        
        System.assert(!String.isEmpty(lastViewedAcc1.getLongDate()));
        lastViewedAcc1.updateField();
        
        
              
        //Create Opportunity 2 - with no 'Last Viewed By' data - to check 2nd branch of if statement
        Account testAccount2 = new Account(Name = 'testAccount');
        testAccount2.Company_Registered_Number_SOC__c = '00000000';
        testAccount2.Primary_Sector__c = 'Business Goods & Services';
        testAccount2.Sub_Sector__c = 'Point of Sale';
        testAccount2.Organisation_type_SOC__c = 'Limited Company'; 
        testAccount2.Street_Head_Office_SOC__c = 'Test Street'; 
        testAccount2.City_Head_Office_SOC__c = 'London'; 
        testAccount2.Country_Head_Office_SOC__c = 'United Kingdom';
        insert testAccount2;
 
 
        ApexPages.StandardController sc2 = new ApexPages.StandardController(testAccount2);
        lastViewedAccount lastViewedAcc2 = new lastViewedAccount(sc2);
        
        System.assert(!String.isEmpty(lastViewedAcc2.getLongDate()));
        lastViewedAcc2.updateField();
        
        
    }   

}

Hi All, 

I've amended a solution for tracking page views I found here:
https://success.salesforce.com/answers?id=9063A000000Dq6MQAS

I'm using it to track who has viewed an Opportunity record page - however I have no idea where to start with the test class - I'm currently working through a couple of trailhead modules, though any pointers would be greatly appreciated

Thanks

Terri 
 
public without sharing class lastViewedOpportunity{
    public Datetime cDT;
    public String LongDate;
    public String firstname;
    public String lastname;
    public String existinglastviewed;
    public String userid;
    private final Opportunity opp;
    
    public lastViewedOpportunity(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
    }
    
    public String getLongDate() {
        cDT = System.now();
        //Formats the datetime value to locale
        LongDate = cDT.format('dd/MM/yyyy HH:mm');
        return LongDate;
    }
    
    
    public void updateField() {
        //Get the user info from the current user
        firstname = System.Userinfo.getFirstName();
        lastname = System.Userinfo.getLastName();
        userid = System.Userinfo.getUserId();
        //Get the Opportunity record to be updated
        Opportunity o = [select Last_Viewed_By__c, Track_Record__c from Opportunity where id = :opp.id limit 1];
        //get existing string of the record, so that new view can be appended to the end of this
        existinglastviewed = o.Last_Viewed_By__c;
        //check to see if the Opportunity has been flagged for tracking
        if(o.Track_Record__c){
            //Assign values to Last Viewed By field and update the record - only concatenate if there is a value there already
            if(existinglastviewed != null){
                o.Last_Viewed_By__c = (existinglastviewed + '; \n' + firstname + ' ' + lastname + ' ' + getLongDate());
            }
            else o.Last_Viewed_By__c = (firstname + ' ' + lastname + ' ' + getLongDate());
            update o;
        }    
    }
    
}

 
Hi All,

I need to create a trigger that "rolls up" the field Amount__c from a custom object Sessions to a custom object called Session_Invoice to a field called Invoice_Amount - I can't use a rollup summary field unfortunately as it's just a lookup relationship.

I'm quite new to Salesforce and Coding, so struggling where to start!

Any help would be much appreciated
 
trigger SessionAmountRollup on Session__c (after insert, after update, after delete, after undelete) {
  
}

 
Hi All!

I currently have a button on the 'Lead' page, that opens a VF page with a Flow inside:

VF Page:
<apex:page standardController="Lead"> <h1>Create A Premier Quick Task</h1> <flow:interview name="QuickPremierTask" finishLocation="/{!id}"> <apex:param name="LeadID" value="{!ID}"/> <apex:param name="UserID" value="{!$User.Id}"/> </flow:interview> </apex:page>

I want to add Validation in the button code that will only allow the button to be clicked (to launch the VF page flow) if the fields 'Lead Source' or 'Initial Lead Source' are equal to the text 'Premier 1'

Normally I would simlpy exclude the button from the page layout with the use of a new Record Type, however this is not an option in this instance.

Can this be done using Javascript in the button code? (Or an alternate option)

Winning answer gets 10 internets!