• Molson94
  • NEWBIE
  • 100 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 16
    Replies
Hello,

Looking for some help/direction on the best way to handle file uploads in a Visualforce page.
I have a page that works fine using <apex:inputFile> but as we know this only supports 1 file at a time.
This creates a poor user experience for my use case since the users will have to click "browse" for each <apex:inputFile> on the page.

Has anyone been able to solve for multiple files being uploaded by use the REST API and jQuery/XHR in a visualforce page?
I have only seen a few raw examples but nothing complete to be able to research.

Thanks in advance.
Hello,

I am losing my mind trying to sort out why apex:repeat is not working on my visualforce page.
I've used apex:repeat before and never had any issue.

The VF page is loading, and the logs show that the SOQL list "repeatedList" has values.
The page loads fine, and nothing is shown in the apex:repeat section of the page.

Are there any other considerations I may be missing that will prevent apex:repeat from working?

VF Page:
<apex:repeat value="{!repeatedList}" var="a">
                <apex:outputText value="{!a.id}" />
</apex:repeat>
Controller:
public class cb_controller {
    public list<object__c> repeatedList {get; set;}
    
 public cb_controller(){
    list<object__c> repeatedList = new list<object__c>();
                
                List<object__c> soqlList = new List<object__c>([
                    SELECT id
                    FROM Object__c 
                    ]);
                
                for(Object__c x : soqlList){
                    repeatedList.add(x);
                    system.debug(x);
                }
                
}

Thanks in advance!
 
Hello All,

Looking for some examples people may have used on their own to format decimal places in Wave analytics.
the documentation is not clear since it contains sample code from both WMD 1.0 and 2.0.

What I am trying to do it show 2 decimal places in my measures for specific fields.
The fields that are coming from Salesforce are formula fields, that return a 2 decimal place number.

Inside wave this data appears to be getting rounded, and/or decimal places are getting dropped.

Does anyone have advice/guidance on the syntax that needs to be used to formatt number fields?
"measures":[
   {
      "field": "Field_Name__c",
      "format": {
// What goes here? What is the proper syntax to simply enable that values hold their decimal places in the UX?
      }
    }

 
Hi All,

I am working with dahsboards in Wave Analytics and am running into some issues with editing the XMD file to reflect a custom color on the chart.
Ive input the below json into the XMD file and it validates and shows the change to the label, and name, but the color is not changing.

Is there some other setting or piece of the metadata that needs to be changed in order to show a custom color?
The documentation isnt very specific for what i think would be a rather popular use case.
 
{
	"dataset":{},
	"dates":[],
	"derivedDimensions":[],
	"derivedMeasures":[],
	"dimensions":[
	{
		"field": "Custom_Field__c",
		"members": [
			{
				"member": "High", 
				"label": "1H",
				"color": "#ff0000"
			},
			{
				"member": "Medium", 
				"label": "2M",
				"color": "#0000ff"
			}
			{
				"member": "Low", 
				"label": "2L",
				"color": "#ff3ff"
			},
		]
	}
	],
	"measures":[],
	"organizations":[],
	"showDetailsDefaultFields":[]}





Thanks in advance!
Hey Everyone,

Having some issues with the use of a Visualforce Component, and how inputField reacts to styling.
On the current project, I have a parent Visualforce page, which contains a series of components.
The component contains form elements, that have the correct styleClass associated (even tried html-class, and wrapping the elements in span) but are not respecting the style sheet definitions.

I have a previous project that has inputFields that DID reflect the proper styles in the CSS sheet, so this feels inconsistent, and i may be doing something incorrect, or missing some sort of exception.

Questions for anyone who has encountered this before, or is well versed in :
1. Do styles need to be referenced inline, or local to the component, not the parent?
2. The form elements are apart of a dependant picklist, does this have an impact? There was some old documentation about this being a bug, but when I look at the source of the page the class is being passed through correctly, and it appears to not be the issue.
3. This is only appearing to affect how inputField for picklists is rendering, inputTextArea and inputText render fine.
4. One time I was able to refresh the page and the styles appeared correct for a fraction of a second, before "switching" back to the incorrect way. Whats this about? Using Firefox to view the page.

Thanks in advance for taking a look!
Hello,

I am trying to calculate the delta between two date fields on 2 different records. The list of records is sorted in in order by the date field, and i would like the currentRecord, to compare date fields to the previous record before it. Something like:

List of Cases specific to a custom Object:
Case1 CreatedDate Delta
Case2 CreatedDate Delta
Case3 CreatedDate Delta

If Case3 is being looked at in the trigger, i want to be able to compute the delta between 2 and 3, and 2 and 1 and so on, since they are in that chronological order.
I thought this may be possible iterating through a sorted list (in the more detailed use case I have I am sorting the list by 2 fields), and looking at the current list index, and then comparing it to the next index, but it doesnt seem you can check within a loop what index you are currently on.

Anyone else run into this sort of issue and have a solution?

Thanks!
Hey Everyone,

I am trying to retrieve a PDF from an external site.
I have been able to grab the PDF using this tutorial as a start. (link below)

What i am trying to do after the fact is to save each page of the grabbed PDF as an image (jpg, png) to then save as a salesforce attachment.
Searches have come up empty, but does anyone have any ideas on how to solve for saving the individual pdf pages as image?

Tutorial being used to save the pdf: https://www.sundoginteractive.com/blog/saving-the-contents-of-an-image-or-file-url-and-saving-to-an-attachment-or

Thanks!
Hello,

I am creating a CSV file to email and attach to the parent object.
What I am running into is that any fields without values are being added to the csv file in the email as "null".

This makes sense since not all fields will have values.
Is there a way around this? Ideally the csv file would show blank instead of null.

Thanks!
Hello,

Banging my head against the wall trying to figure out why "System.NullPointerException: Attempt to de-reference a null object" error is occuring on an After Update trigger. For the 200 records that are not being updated because of this trigger's error, i am stumped because those records do not meet the criteria in the initial for loop (line 7) to even be included in the list of recrods i am targeting. Does anyone know why this error is being thrown on line 68 (bolded).

Thanks in advance.
 
trigger PrintJobCreate on Title__c (after update) {
    List<Title__c> ProductionTitles = new List<Title__c>();
    List<masterID__c> masterIDs = new List<masterID__c>();
    List<Print_Job__c> NewJobs = new List<Print_Job__c>();
    List<Vendor__c> printer = new List<Vendor__c>([SELECT id FROM Vendor__c WHERE Name = 'Printer' LIMIT 1]);
    
    for (Title__c t : Trigger.new) { //all titles that were updated
        if (t.status__c != Trigger.oldMap.get(t.Id).status__c) { //only look at titles that had a status change
            if (t.Status__c == 'Production' || t.Status__c == 'Art In Progress') { //isolate titles that have moved into production or art creation
                ProductionTitles.add(t);
            }
            
        } 
    }
    if (!ProductionTitles.isEmpty()) {
        //Get current list of masterIDs to avoid duplicates
        //compare masterIDs in OpenJobs with masterIDs in ProductionTitles
        system.debug(ProductionTitles);
        Set<String> OJ = new Set<String>();
        Set<Print_job__c> OpenJobs = new Set<Print_Job__C>([SELECT masterID_Format__c FROM Print_Job__c WHERE Print_Job_Status__c != 'Complete']);
        
        Set<String> OA = new Set<String>();
        //
        Set<masterID__c> OpenmasterIDs = new Set<masterID__c>([SELECT id, Name FROM masterID__c WHERE Name NOT IN ('Digital', 'Digital Audio', 'Physical Audio') AND x3p__c = false  AND Title__r.id IN:ProductionTitles]);
        //Grab all masterID Ids of all open jobs
        for(Print_Job__c OJS : OpenJobs){
            OJ.add(String.valueOf(OJS.masterID_Format__c));
            //system.debug('Open Print Job '+ OJ);
        }
        
        //Grab all masterID Ids of triggered masterIDs that meet print criteria
        for(masterID__c OAS : OpenmasterIDs){
            OA.add(String.valueOf(OAS.Id));
            system.debug('masterID Matching Criteria: '+ OA);
            
        }
        
        //Remove current open jobs from list of masterIDs that meet criteria
        for(String job : OJ){
            if (OA.contains(job)){
                OA.remove(job);
                system.debug('Remaining DeDuped masterIDS ' +OA);
            }
        }
        
        //Requery the list for the 
        masterIDs = [SELECT id, Name, masterID__c, x3p__c, Color_BW_Interior__c, pub_Publish_Date__c, title__r.id, title__r.internal_imprint__c 
                 FROM masterID__c 
                 WHERE
                 id IN :OA ];
        system.debug(masterIDs);
    }
    if (!masterIDs.isEmpty()) {
        for (masterID__c a : masterIDs) {
            Print_Job__c pj = new Print_Job__c();
            
            pj.Title__c = a.Title__c;
            pj.masterID_Format__c = a.Id;
            pj.Job_Type__c = 'Initial Print Run';
            pj.Print_Job_Status__c = 'Pending';
            pj.Printer__c = printer.get(0).id;
            
            if(a.Color_BW_Interior__c == '1/1' && a.Name == 'Paperback'){ //standard pub paperback
                //standard location
                pj.Print_Location__c = 'Printer US';
                //standard schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 56;
                pj.Files_Due_At_Printer__c = a.
                    _Publish_Date__c - 56;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 35;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c == '1/1' && a.Name == 'Hardcover'){ //1C Hardcover
                //standard location
                pj.Print_Location__c = 'Printer US';
                //standard hc schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 84;
                pj.Files_Due_At_Printer__c = a.pub_Publish_Date__c - 63;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 35;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c != '1/1' && a.Color_BW_Interior__c != '' && a.Name == 'Hardcover' && a.Title__r.Internal_imprint__c == 'Two Lions'){ //TL Hardcover
                //standard location
                pj.Print_Location__c = 'Printer China';
                //standard TL schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 140;
                pj.Files_Due_At_Printer__c = a.pub_Publish_Date__c - 126;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 84;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c != '1/1' && a.Color_BW_Interior__c != '' && a.Name == 'Paperback' && a.Title__r.Internal_imprint__c == 'Two Lions'){ //TL Paperback
                //standard location
                pj.Print_Location__c = 'Printer China';
                //standard TL schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 140;
                pj.Files_Due_At_Printer__c = a.pub_Publish_Date__c - 126;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 84;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c != '1/1' && a.Color_BW_Interior__c != '' && a.Title__r.Internal_imprint__c == 'Jet City Comics'){
                //standard location
                pj.Print_Location__c = 'Printer US';
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                pj.Print_Job_Status__c = 'Attention Required';
                pj.Schedule_Exception__c = true;
                
                pj.notes__c = 'Jet City 4-Color Project. Confirm with JCC tracker for initial schedule.';
                
                Newjobs.add(pj);
                
            }else{
                pj.Print_Job_Status__c = 'Attention Required';
                pj.Schedule_Exception__c = true;
                pj.notes__c = 'Error regarding masterID Spec. Consult with PXM / AE to confirm spec and schedule.';
                Newjobs.add(pj);
            }
            
        }
        
        
    }
    if (!NewJobs.isEmpty()){
        insert(NewJobs);
    }
    
}

 
Hey Everyone,

I have an inputfield that is a defined as a multiselect picklist on the object.
By default that inputfield is displayed as a multiselect picklist on the form.

The problem is that the inputfield breaks my custom form layout when it is revealed/rendered. and overall is rather gaudy. Is there any way to have that field display as a selectList, with the ability to select multiple options? It does not appear that "multiselect" is an attribute available on inputfield.

The only thing I can think of is going back through the controller to build out the selectlist dynamically. Id rather not have to do that.

Thanks!
Hey Everyone,

Banging my head against the wall as i cannot figure out why this exception is being thrown.
I am getting the following error:

Attempt to de-reference a null object
Error is in expression '{!LookupTitleID}' in component <apex:commandButton> in page espcreate: Class.ESPController1.LookupTitleID: line 80, column 1

I am querying Vendor based on param V at the beginning when the page loads, so Vendor should never be null when "LookupTitleID" fires.

Any thoughts?
Thanks!

Here is the code:
Line 80 is: newEsp.Vendor__c = Vendor.get(0).id;
 
public class ESPController1 {

     //url parameters
    public String v = ApexPages.currentPage().getParameters().get('v');
    public String esp = ApexPages.currentPage().getParameters().get('esp');
    
    //lists
    public List<Vendor__c> Vendor = new list<vendor__c>([SELECT id FROM Vendor__c WHERE id = :v LIMIT 1]);
    public List<Title__c> Title = new List<Title__c> ();
    public List<ESP__c> ESPList = new List<ESP__C> ([SELECT id FROM ESP__c WHERE id = :esp LIMIT 1]);
    
    //sObjects
    public ESP__c newEsp;
    
    //Create Inputs
    public String TitleID { get; set; }
    public string martyid;
    
    //Key Page References
    public PageReference booter = new PageReference('http://www.google.com'); 
    
    /////Footer Links/////
    public String getV() {
        return v;
    }
    //////////////////////
    
    /////Nav Page Refs/////
    
    public PageReference goCreate() {
        PageReference goCreate = Page.espcreate;
        goCreate.getParameters().put('v',v);
        goCreate.setRedirect(true);
        return goCreate;
    }
    
    public PageReference goDash() {
        PageReference goDash = Page.espdashboard;
        goDash.getParameters().put('v',v);
        goDash.setRedirect(true);
        return goDash;
    }
    
    ////////////////////////
    
    public PageReference LookupVendor() {//function to check the url contains the correct vendor id, set as action for all pages to enable a check when the page is loaded!!!
        if (String.isEmpty(v)) {
            booter.setRedirect(true);
            return booter;
            
        }
        
        if (vendor.size() != 1) {
            booter.setRedirect(true);
            return booter;
            
        }
        return null;
    }
    
    
    
    /////ESP Create Page///// 
    
    public PageReference LookupTitleID(){ //check that the supplied title ID works, if it does, create a new esp, and move to next step
        
        if (String.isEmpty(TitleID) || !TitleId.isNumeric()){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Title ID is a required input. Please enter a valid Title ID.'));
            return null;
        }
        
        if(TitleId!=null){
            Title = [SELECT Id, Marty_Title_Id__c FROM Title__c WHERE Marty_Title_ID__c = :TitleId LIMIT 1];
            if (Title.size() == 1) { //valid title id, create the esp, insert, and move to the full form. 
                newEsp.Vendor__c = Vendor.get(0).id;
                newEsp.Title__c = Title.get(0).id;
                
                try {
                    insert(newEsp);
                } catch(DmlException e) {
                    System.debug('The following exception has occurred: ' + e.getMessage());
                }
                
                PageReference redirect = Page.esp;
                redirect.getParameters().put('v',vendor.get(0).Id);
                redirect.getParameters().put('esp',newEsp.id);
                redirect.setRedirect(true);
                return redirect;
            }   
        }else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Not a valid Title ID. Please enter a valid Title ID.'));
            return null;
        }
        return null;
    }
}



 
Hi EVeryone,

Stumped on why i keep getting the following error when testing my code block: System.NullPointerException: Attempt to de-reference a null object
I understand the reason for the error, but cannot seem to figure out why the code is throwing it. the Feedback object should be initialized and be able to be added to the feedbackList.

Appreciate the help!
 
String d = 'a0G190000015uMg'; //for testing

//containers for querys
Deliverable__c deliverable;
List<Feedback_Survey_Question__c> questionList;
List<Feedback_Responses__c> responseList;
List<Feedback__c> feedbackList;
List<Approver__c> approverList;

//query db for lists
deliverable = [SELECT id, type__c, milestone__c, Number_of_Concepts__c, Status__c FROM Deliverable__c WHERE id = :d];
approverList = [SELECT id, name, Approver__c, Approver_Role__c FROM Approver__c WHERE Deliverable__r.id = :d];
//assign pieces of delvierable

decimal concepts = deliverable.Number_of_Concepts__c;
string milestone = deliverable.milestone__c;

System.debug(deliverable);
System.debug(concepts);
System.debug(milestone);

for (Integer i = 1; i <= concepts; i++){ 
    for (Approver__c a : approverList) { 
    
    String role = a.Approver_Role__c;
    String aid = a.id;
    
    Feedback__c Feedback = new Feedback__c();
    Feedback.Name = 'Concept ' + i;
    Feedback.Deliverable__c = d;
    Feedback.Approver__c = aid;
    feedbackList.add(Feedback); //ERROR BEING THROWN HERE
    
    }
    
}


 
Hi Everyone,

I am attempting to send templated email through SendMail method.
When i was testing individual mails for functionality it worked perfectly fine. Now that i have looped out multiple mails, and want to send from a list i am getting an error.

Here is the error in detail when i try to run the script:
Line: 57, Column: 1
System.EmailException: SendEmail failed. First exception on row 1; first error: INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []


Here is the script that i am trying to run:
 
// Promo/Contact Objects
        List<Promotion__c> PromoList = new List<Promotion__c>(); // list of promo/title
        List<Title_Contact__c> ContactList = new List<Title_Contact__c>(); // list of title/contact
        List<String> TitleList = new List<String> (); //list to use to bind title contacts and titles needed (used to manage record size out of Title_Contact__c)
        Map<String, String> MailingList = new Map <String, String> (); //List of Promo/Contact that need to be mailed
        // Mailer Objects
        OrgWideEmailAddress Orgid = [SELECT Id FROM OrgWideEmailAddress WHERE displayname = 'APub Promo Notify']; //select the correct send from address
        EmailTemplate template = [SELECT id FROM EmailTemplate WHERE developerName = 'Ebook_PBook_Deals']; //get the standard template to be used        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); //initialize the individual emails
        List<Messaging.SingleEmailMessage> emails2send = new List<Messaging.SingleEmailMessage>(); //list of 'mail' to be sent through sendMail
        List<List<String>> MailList = new List<List<String>>();
        
        ///////////////////Create the MailingList MAP
        
        PromoList = [SELECT id, Title__r.id FROM Promotion__c  WHERE Notification_Status__c = 'Queued']; //;AND Start_Date__c = NEXT_N_DAYS:1
        if (!PromoList.isEmpty()){ //check if we have promos to act on
            for (Promotion__c title : PromoList) { //loop through to isolate the titles needed
                TitleList.add(title.Title__r.id); // build the list of titles in the title list string
            }
            System.debug('We have ' + PromoList.size()+' promotions to act on.');
            ContactList = [SELECT Legal_Name__r.Id, Title__r.Id 
                           FROM Title_Contact__c 
                           WHERE Title__r.Id IN :TitleList 
                           AND Role__c IN ('Author', 'Agent')]; //grab the recipients from the needed titles and the specific roles
            
            for (Title_Contact__c tc : ContactList) { //loop through lists to find matches on each level
                for (Promotion__c p : PromoList){
                    if(tc.Title__r.id == p.Title__r.id) { // have a match? add it to the map
                        MailingList.put(tc.Legal_Name__r.id, p.id);
                        
                    }              
                }
            }
            System.debug(MailingList);
        }else{
            System.debug('No Promotions to act on.');
            //No promotions in PromoList to send on.
        }
        
        
        ///////////////////Use the MailingList to create the individual email, and add to emails2send
        //If we have people to mail, compile mails, if not dont send
        if (!MailingList.isEmpty()){
            for (String c : MailingList.keySet()) {
                System.debug(c);
                System.debug(MailingList.get(c));
                String Contact = c;
                String Promotion = MailingList.get(c);
                mail.setOrgWideEmailAddressId(Orgid.id); //from address
                mail.setTemplateId(template.id); //standard template
                mail.setWhatId(Promotion); // what promo to merge
                mail.setTargetObjectId(Contact); // Specify who the email should be sent to.
                
                emails2send.add(mail);
            }
            Messaging.sendEmail(emails2send);
        }

The error is referencing fields that i am not attempting to alter in the building of "mail".
Thoughts?

Thanks in advance!
 
Morning Everyone,

Thank you in advance for the insights to this problem.
I posted a related question here: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AxSXIA0
Where i thought i would be able to get the list of IDs through 1 query. After going back and forth all week i have come to the realization that i cannot query at once since the relationships do not align.

But I do think i can query 2 lists through Product__c and do some comparing to create the third list for emailing. Problem is I cannot find the right code to do it.

List 1: List of Promotion Id and related Product Id (based on criteria of the promotion)
List 2: List of Product Id and related Product Contact Id (based on criteria of the Product Contact Role ' Manager' or 'Rep')

I would like to do a comparison between List 1 & 2.
If the Product ID in L2 exists in L1, add the Promotion ID and Product Contact ID together in L3.

So List 3 would be: Promotion ID | Product Contact ID

Thoughts on the best practice to tackle this?

Thanks!

 
Hi Everyone,

I am looking at writing a class that auto sends a templated notification to a custom list of contacts. I am struggling to get a query that correctly cascades the relationships between 4 custom objects. In my head i think this should be doable, but I cant seem to get it right on paper. The relationships are as follows:

Contact --LookUp--> Product_Contacts__c --LookUp--> Product__c --LookUp--> Promotion__c

I need to be able to tie Contact.Id, and Promotion__c.Id for use on the email template. But only where the Status__c of the Promotion__c is "Approved", and where the Product_Contact__c.Role is 'Manager' or 'Rep'.

In my head I keep thinking that this can be done with 1 query/list, but I may just be getting burned out thinking about it and require some additional feedback from the community.
Hey Everyone,

I've grabbed some trigger code from another forum to solve my main issue of new emails coming into a already closed case. What I would like to also accomplish in this trigger is have the incoming EmailMessage be related to the cloned case, and it's original parent case. Is it possible to reassign the EmailMessages ParentID after insert?

Here is my current code for the trigger:
 
trigger CloneClosedCase on EmailMessage (after insert) {
Set<ID> caseSet = new Set<ID>();
List<Case>cloneList = new List<Case>();
Map<Id, String> emailMap = new Map<Id, String>{};
for (EmailMessage so : Trigger.new) {
    if(so.ParentId.getSObjectType() == Case.sObjectType && so.Incoming){
        caseSet.add(so.parentid);
        emailMap.put(so.ParentId, so.TextBody);
    } 
}
Map<Id,case> caseMAP = new Map<Id,case>([SELECT id, [OTHER FIELDS]   FROM Case WHERE id in:caseSet]);  
for(Case c:caseMAP.values()){
    if(c.Status=='Closed') {
        Case cloneCase = c.clone(false,true);
        cloneCase.parentid=c.id;
        cloneCase.Status='New';
        cloneCase.Description=emailMap.get(c.Id);
        cloneCase.Subject = 'C: '+c.Subject;
        cloneList.add(cloneCase);
    }
}
try { 
    insert cloneList;      
} catch(DMLException e) {   
     System.debug('The following exception has occurred: ' + e.getMessage()); 
}
}
I cant seem to figure out if 1) it is possible to change the parent Id of an EmailMessage or 2) if i am going about it the right way.

Thoughts?

Thanks in advance!
 
Hi all,

Simple question I hope.

I have a custom controller that after creating a new custom object, redirects to the second page in the series.

This is the code i am using for moving to the next page:
public PageReference step2() {
        //when submitted, check the title id against the title records
        tidL = [SELECT id FROM Title__c WHERE Title_ID__c = :tID LIMIT 1];
        if (!tidL.isEmpty()){
            cc.Vendor__c = vendor.get(0).id;
            cc.Title__c = tidL.get(0).id;
            cc.Status__c = 'Open';
            upsert(cc);
            
            PageReference redirect = Page.cc2;
            redirect.getParameters().put('v',vendor.get(0).id);
            redirect.getParameters().put('cc',cc.id);
            redirect.setRedirect(true);
            return redirect;
        }

The end result i am trying to achieve is the next pages url is appended with the following: ?v=VENDORID?cc=CCID
So i can then pull those parameters and do some other validation etc..

What the application is doing however is returning the following:

?cc=a07e0000001qHsNAAU&v=a09e0000002k5ueAAA

The italicized portions are the correct ID fields that i am looking to identify, but the  bolded portions are causing errors when the second page grabs the parameters.

Can anyone help explain why this is the case and/or advise on how to acheive the desired result?

or

If it is simpler, what would be the correct syntax to build out these URLs via string?

Thank you all for your help!
Hi All,

I am looking to create a series of pages that allow for creation of multiple custom objects. The first step however before anything can be rendered or created is to check the 'v' parameter in the URL to ensure that the vendor exists.

i keep running into problems when i look to inslude the logic in the controller constructor. It is my understanding from the documentation that the controller constructor will be processed first, then getter, then actions etc...

The below logic either will not compile, because the contrstor cannot return a value, and thus not redirect the page. Or calling the PageReference method booter() does not do anything.

Below is the controller code i have currently:

public class ccController {
    public List<Vendor__c> vendor;

 //Redirects
    PageReference booted = new PageReference ('http://www.google.com');
    
    
    //controller constructor
    public ccController() {
        vendor = [SELECT id, name FROM Vendor__c WHERE id = :ApexPages.currentPage().getParameters().get('v') LIMIT 1];
        if (vendor.size() == 1){
            //vendor is valid do some stuff
            
        }else{
            //vendor is not valid, redirect to another page
            //booted.setRedirect(true);
            //return booted;
            booter();
        }
  
    public PageReference booter() {
        booted.SetRedirect(true);
        return booted;
        }
       
    public PageReference save() {
           return null;
    }
    
    public PageReference nextStep(){
        return null;
    }
    
}

Many thanks in advance for any feedback and nudges in the right direction.
Hello,

Looking for some help/direction on the best way to handle file uploads in a Visualforce page.
I have a page that works fine using <apex:inputFile> but as we know this only supports 1 file at a time.
This creates a poor user experience for my use case since the users will have to click "browse" for each <apex:inputFile> on the page.

Has anyone been able to solve for multiple files being uploaded by use the REST API and jQuery/XHR in a visualforce page?
I have only seen a few raw examples but nothing complete to be able to research.

Thanks in advance.
Hello,

I am losing my mind trying to sort out why apex:repeat is not working on my visualforce page.
I've used apex:repeat before and never had any issue.

The VF page is loading, and the logs show that the SOQL list "repeatedList" has values.
The page loads fine, and nothing is shown in the apex:repeat section of the page.

Are there any other considerations I may be missing that will prevent apex:repeat from working?

VF Page:
<apex:repeat value="{!repeatedList}" var="a">
                <apex:outputText value="{!a.id}" />
</apex:repeat>
Controller:
public class cb_controller {
    public list<object__c> repeatedList {get; set;}
    
 public cb_controller(){
    list<object__c> repeatedList = new list<object__c>();
                
                List<object__c> soqlList = new List<object__c>([
                    SELECT id
                    FROM Object__c 
                    ]);
                
                for(Object__c x : soqlList){
                    repeatedList.add(x);
                    system.debug(x);
                }
                
}

Thanks in advance!
 
Hello,

I am creating a CSV file to email and attach to the parent object.
What I am running into is that any fields without values are being added to the csv file in the email as "null".

This makes sense since not all fields will have values.
Is there a way around this? Ideally the csv file would show blank instead of null.

Thanks!
Hello,

Banging my head against the wall trying to figure out why "System.NullPointerException: Attempt to de-reference a null object" error is occuring on an After Update trigger. For the 200 records that are not being updated because of this trigger's error, i am stumped because those records do not meet the criteria in the initial for loop (line 7) to even be included in the list of recrods i am targeting. Does anyone know why this error is being thrown on line 68 (bolded).

Thanks in advance.
 
trigger PrintJobCreate on Title__c (after update) {
    List<Title__c> ProductionTitles = new List<Title__c>();
    List<masterID__c> masterIDs = new List<masterID__c>();
    List<Print_Job__c> NewJobs = new List<Print_Job__c>();
    List<Vendor__c> printer = new List<Vendor__c>([SELECT id FROM Vendor__c WHERE Name = 'Printer' LIMIT 1]);
    
    for (Title__c t : Trigger.new) { //all titles that were updated
        if (t.status__c != Trigger.oldMap.get(t.Id).status__c) { //only look at titles that had a status change
            if (t.Status__c == 'Production' || t.Status__c == 'Art In Progress') { //isolate titles that have moved into production or art creation
                ProductionTitles.add(t);
            }
            
        } 
    }
    if (!ProductionTitles.isEmpty()) {
        //Get current list of masterIDs to avoid duplicates
        //compare masterIDs in OpenJobs with masterIDs in ProductionTitles
        system.debug(ProductionTitles);
        Set<String> OJ = new Set<String>();
        Set<Print_job__c> OpenJobs = new Set<Print_Job__C>([SELECT masterID_Format__c FROM Print_Job__c WHERE Print_Job_Status__c != 'Complete']);
        
        Set<String> OA = new Set<String>();
        //
        Set<masterID__c> OpenmasterIDs = new Set<masterID__c>([SELECT id, Name FROM masterID__c WHERE Name NOT IN ('Digital', 'Digital Audio', 'Physical Audio') AND x3p__c = false  AND Title__r.id IN:ProductionTitles]);
        //Grab all masterID Ids of all open jobs
        for(Print_Job__c OJS : OpenJobs){
            OJ.add(String.valueOf(OJS.masterID_Format__c));
            //system.debug('Open Print Job '+ OJ);
        }
        
        //Grab all masterID Ids of triggered masterIDs that meet print criteria
        for(masterID__c OAS : OpenmasterIDs){
            OA.add(String.valueOf(OAS.Id));
            system.debug('masterID Matching Criteria: '+ OA);
            
        }
        
        //Remove current open jobs from list of masterIDs that meet criteria
        for(String job : OJ){
            if (OA.contains(job)){
                OA.remove(job);
                system.debug('Remaining DeDuped masterIDS ' +OA);
            }
        }
        
        //Requery the list for the 
        masterIDs = [SELECT id, Name, masterID__c, x3p__c, Color_BW_Interior__c, pub_Publish_Date__c, title__r.id, title__r.internal_imprint__c 
                 FROM masterID__c 
                 WHERE
                 id IN :OA ];
        system.debug(masterIDs);
    }
    if (!masterIDs.isEmpty()) {
        for (masterID__c a : masterIDs) {
            Print_Job__c pj = new Print_Job__c();
            
            pj.Title__c = a.Title__c;
            pj.masterID_Format__c = a.Id;
            pj.Job_Type__c = 'Initial Print Run';
            pj.Print_Job_Status__c = 'Pending';
            pj.Printer__c = printer.get(0).id;
            
            if(a.Color_BW_Interior__c == '1/1' && a.Name == 'Paperback'){ //standard pub paperback
                //standard location
                pj.Print_Location__c = 'Printer US';
                //standard schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 56;
                pj.Files_Due_At_Printer__c = a.
                    _Publish_Date__c - 56;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 35;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c == '1/1' && a.Name == 'Hardcover'){ //1C Hardcover
                //standard location
                pj.Print_Location__c = 'Printer US';
                //standard hc schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 84;
                pj.Files_Due_At_Printer__c = a.pub_Publish_Date__c - 63;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 35;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c != '1/1' && a.Color_BW_Interior__c != '' && a.Name == 'Hardcover' && a.Title__r.Internal_imprint__c == 'Two Lions'){ //TL Hardcover
                //standard location
                pj.Print_Location__c = 'Printer China';
                //standard TL schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 140;
                pj.Files_Due_At_Printer__c = a.pub_Publish_Date__c - 126;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 84;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c != '1/1' && a.Color_BW_Interior__c != '' && a.Name == 'Paperback' && a.Title__r.Internal_imprint__c == 'Two Lions'){ //TL Paperback
                //standard location
                pj.Print_Location__c = 'Printer China';
                //standard TL schedule
                pj.Units_Spec_Due_Date__c = a.pub_Publish_Date__c - 140;
                pj.Files_Due_At_Printer__c = a.pub_Publish_Date__c - 126;
                pj.Estimated_Ship__c = a.pub_Publish_Date__c - 84;
                pj.BPI_Forecast_Due__c = pj.Units_Spec_Due_Date__c - 7;
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                NewJobs.add(pj);
            }else if(a.Color_BW_Interior__c != '1/1' && a.Color_BW_Interior__c != '' && a.Title__r.Internal_imprint__c == 'Jet City Comics'){
                //standard location
                pj.Print_Location__c = 'Printer US';
                
                pj.Standard_CPU__c = false;
                pj.RFQ_Required__c = true;
                pj.Print_Job_Status__c = 'Attention Required';
                pj.Schedule_Exception__c = true;
                
                pj.notes__c = 'Jet City 4-Color Project. Confirm with JCC tracker for initial schedule.';
                
                Newjobs.add(pj);
                
            }else{
                pj.Print_Job_Status__c = 'Attention Required';
                pj.Schedule_Exception__c = true;
                pj.notes__c = 'Error regarding masterID Spec. Consult with PXM / AE to confirm spec and schedule.';
                Newjobs.add(pj);
            }
            
        }
        
        
    }
    if (!NewJobs.isEmpty()){
        insert(NewJobs);
    }
    
}

 
Hey Everyone,

Banging my head against the wall as i cannot figure out why this exception is being thrown.
I am getting the following error:

Attempt to de-reference a null object
Error is in expression '{!LookupTitleID}' in component <apex:commandButton> in page espcreate: Class.ESPController1.LookupTitleID: line 80, column 1

I am querying Vendor based on param V at the beginning when the page loads, so Vendor should never be null when "LookupTitleID" fires.

Any thoughts?
Thanks!

Here is the code:
Line 80 is: newEsp.Vendor__c = Vendor.get(0).id;
 
public class ESPController1 {

     //url parameters
    public String v = ApexPages.currentPage().getParameters().get('v');
    public String esp = ApexPages.currentPage().getParameters().get('esp');
    
    //lists
    public List<Vendor__c> Vendor = new list<vendor__c>([SELECT id FROM Vendor__c WHERE id = :v LIMIT 1]);
    public List<Title__c> Title = new List<Title__c> ();
    public List<ESP__c> ESPList = new List<ESP__C> ([SELECT id FROM ESP__c WHERE id = :esp LIMIT 1]);
    
    //sObjects
    public ESP__c newEsp;
    
    //Create Inputs
    public String TitleID { get; set; }
    public string martyid;
    
    //Key Page References
    public PageReference booter = new PageReference('http://www.google.com'); 
    
    /////Footer Links/////
    public String getV() {
        return v;
    }
    //////////////////////
    
    /////Nav Page Refs/////
    
    public PageReference goCreate() {
        PageReference goCreate = Page.espcreate;
        goCreate.getParameters().put('v',v);
        goCreate.setRedirect(true);
        return goCreate;
    }
    
    public PageReference goDash() {
        PageReference goDash = Page.espdashboard;
        goDash.getParameters().put('v',v);
        goDash.setRedirect(true);
        return goDash;
    }
    
    ////////////////////////
    
    public PageReference LookupVendor() {//function to check the url contains the correct vendor id, set as action for all pages to enable a check when the page is loaded!!!
        if (String.isEmpty(v)) {
            booter.setRedirect(true);
            return booter;
            
        }
        
        if (vendor.size() != 1) {
            booter.setRedirect(true);
            return booter;
            
        }
        return null;
    }
    
    
    
    /////ESP Create Page///// 
    
    public PageReference LookupTitleID(){ //check that the supplied title ID works, if it does, create a new esp, and move to next step
        
        if (String.isEmpty(TitleID) || !TitleId.isNumeric()){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Title ID is a required input. Please enter a valid Title ID.'));
            return null;
        }
        
        if(TitleId!=null){
            Title = [SELECT Id, Marty_Title_Id__c FROM Title__c WHERE Marty_Title_ID__c = :TitleId LIMIT 1];
            if (Title.size() == 1) { //valid title id, create the esp, insert, and move to the full form. 
                newEsp.Vendor__c = Vendor.get(0).id;
                newEsp.Title__c = Title.get(0).id;
                
                try {
                    insert(newEsp);
                } catch(DmlException e) {
                    System.debug('The following exception has occurred: ' + e.getMessage());
                }
                
                PageReference redirect = Page.esp;
                redirect.getParameters().put('v',vendor.get(0).Id);
                redirect.getParameters().put('esp',newEsp.id);
                redirect.setRedirect(true);
                return redirect;
            }   
        }else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Not a valid Title ID. Please enter a valid Title ID.'));
            return null;
        }
        return null;
    }
}



 
Hi Everyone,

I am attempting to send templated email through SendMail method.
When i was testing individual mails for functionality it worked perfectly fine. Now that i have looped out multiple mails, and want to send from a list i am getting an error.

Here is the error in detail when i try to run the script:
Line: 57, Column: 1
System.EmailException: SendEmail failed. First exception on row 1; first error: INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []


Here is the script that i am trying to run:
 
// Promo/Contact Objects
        List<Promotion__c> PromoList = new List<Promotion__c>(); // list of promo/title
        List<Title_Contact__c> ContactList = new List<Title_Contact__c>(); // list of title/contact
        List<String> TitleList = new List<String> (); //list to use to bind title contacts and titles needed (used to manage record size out of Title_Contact__c)
        Map<String, String> MailingList = new Map <String, String> (); //List of Promo/Contact that need to be mailed
        // Mailer Objects
        OrgWideEmailAddress Orgid = [SELECT Id FROM OrgWideEmailAddress WHERE displayname = 'APub Promo Notify']; //select the correct send from address
        EmailTemplate template = [SELECT id FROM EmailTemplate WHERE developerName = 'Ebook_PBook_Deals']; //get the standard template to be used        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); //initialize the individual emails
        List<Messaging.SingleEmailMessage> emails2send = new List<Messaging.SingleEmailMessage>(); //list of 'mail' to be sent through sendMail
        List<List<String>> MailList = new List<List<String>>();
        
        ///////////////////Create the MailingList MAP
        
        PromoList = [SELECT id, Title__r.id FROM Promotion__c  WHERE Notification_Status__c = 'Queued']; //;AND Start_Date__c = NEXT_N_DAYS:1
        if (!PromoList.isEmpty()){ //check if we have promos to act on
            for (Promotion__c title : PromoList) { //loop through to isolate the titles needed
                TitleList.add(title.Title__r.id); // build the list of titles in the title list string
            }
            System.debug('We have ' + PromoList.size()+' promotions to act on.');
            ContactList = [SELECT Legal_Name__r.Id, Title__r.Id 
                           FROM Title_Contact__c 
                           WHERE Title__r.Id IN :TitleList 
                           AND Role__c IN ('Author', 'Agent')]; //grab the recipients from the needed titles and the specific roles
            
            for (Title_Contact__c tc : ContactList) { //loop through lists to find matches on each level
                for (Promotion__c p : PromoList){
                    if(tc.Title__r.id == p.Title__r.id) { // have a match? add it to the map
                        MailingList.put(tc.Legal_Name__r.id, p.id);
                        
                    }              
                }
            }
            System.debug(MailingList);
        }else{
            System.debug('No Promotions to act on.');
            //No promotions in PromoList to send on.
        }
        
        
        ///////////////////Use the MailingList to create the individual email, and add to emails2send
        //If we have people to mail, compile mails, if not dont send
        if (!MailingList.isEmpty()){
            for (String c : MailingList.keySet()) {
                System.debug(c);
                System.debug(MailingList.get(c));
                String Contact = c;
                String Promotion = MailingList.get(c);
                mail.setOrgWideEmailAddressId(Orgid.id); //from address
                mail.setTemplateId(template.id); //standard template
                mail.setWhatId(Promotion); // what promo to merge
                mail.setTargetObjectId(Contact); // Specify who the email should be sent to.
                
                emails2send.add(mail);
            }
            Messaging.sendEmail(emails2send);
        }

The error is referencing fields that i am not attempting to alter in the building of "mail".
Thoughts?

Thanks in advance!
 
Morning Everyone,

Thank you in advance for the insights to this problem.
I posted a related question here: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AxSXIA0
Where i thought i would be able to get the list of IDs through 1 query. After going back and forth all week i have come to the realization that i cannot query at once since the relationships do not align.

But I do think i can query 2 lists through Product__c and do some comparing to create the third list for emailing. Problem is I cannot find the right code to do it.

List 1: List of Promotion Id and related Product Id (based on criteria of the promotion)
List 2: List of Product Id and related Product Contact Id (based on criteria of the Product Contact Role ' Manager' or 'Rep')

I would like to do a comparison between List 1 & 2.
If the Product ID in L2 exists in L1, add the Promotion ID and Product Contact ID together in L3.

So List 3 would be: Promotion ID | Product Contact ID

Thoughts on the best practice to tackle this?

Thanks!

 
Hi Everyone,

I am looking at writing a class that auto sends a templated notification to a custom list of contacts. I am struggling to get a query that correctly cascades the relationships between 4 custom objects. In my head i think this should be doable, but I cant seem to get it right on paper. The relationships are as follows:

Contact --LookUp--> Product_Contacts__c --LookUp--> Product__c --LookUp--> Promotion__c

I need to be able to tie Contact.Id, and Promotion__c.Id for use on the email template. But only where the Status__c of the Promotion__c is "Approved", and where the Product_Contact__c.Role is 'Manager' or 'Rep'.

In my head I keep thinking that this can be done with 1 query/list, but I may just be getting burned out thinking about it and require some additional feedback from the community.
Hi all,

Simple question I hope.

I have a custom controller that after creating a new custom object, redirects to the second page in the series.

This is the code i am using for moving to the next page:
public PageReference step2() {
        //when submitted, check the title id against the title records
        tidL = [SELECT id FROM Title__c WHERE Title_ID__c = :tID LIMIT 1];
        if (!tidL.isEmpty()){
            cc.Vendor__c = vendor.get(0).id;
            cc.Title__c = tidL.get(0).id;
            cc.Status__c = 'Open';
            upsert(cc);
            
            PageReference redirect = Page.cc2;
            redirect.getParameters().put('v',vendor.get(0).id);
            redirect.getParameters().put('cc',cc.id);
            redirect.setRedirect(true);
            return redirect;
        }

The end result i am trying to achieve is the next pages url is appended with the following: ?v=VENDORID?cc=CCID
So i can then pull those parameters and do some other validation etc..

What the application is doing however is returning the following:

?cc=a07e0000001qHsNAAU&v=a09e0000002k5ueAAA

The italicized portions are the correct ID fields that i am looking to identify, but the  bolded portions are causing errors when the second page grabs the parameters.

Can anyone help explain why this is the case and/or advise on how to acheive the desired result?

or

If it is simpler, what would be the correct syntax to build out these URLs via string?

Thank you all for your help!
Hi All,

I am looking to create a series of pages that allow for creation of multiple custom objects. The first step however before anything can be rendered or created is to check the 'v' parameter in the URL to ensure that the vendor exists.

i keep running into problems when i look to inslude the logic in the controller constructor. It is my understanding from the documentation that the controller constructor will be processed first, then getter, then actions etc...

The below logic either will not compile, because the contrstor cannot return a value, and thus not redirect the page. Or calling the PageReference method booter() does not do anything.

Below is the controller code i have currently:

public class ccController {
    public List<Vendor__c> vendor;

 //Redirects
    PageReference booted = new PageReference ('http://www.google.com');
    
    
    //controller constructor
    public ccController() {
        vendor = [SELECT id, name FROM Vendor__c WHERE id = :ApexPages.currentPage().getParameters().get('v') LIMIT 1];
        if (vendor.size() == 1){
            //vendor is valid do some stuff
            
        }else{
            //vendor is not valid, redirect to another page
            //booted.setRedirect(true);
            //return booted;
            booter();
        }
  
    public PageReference booter() {
        booted.SetRedirect(true);
        return booted;
        }
       
    public PageReference save() {
           return null;
    }
    
    public PageReference nextStep(){
        return null;
    }
    
}

Many thanks in advance for any feedback and nudges in the right direction.
I have some code in a class that is called by a triffer that sends emails. I am intermittently receiving exceptions when the code is called. The exceptions only happen about 10% of the time or less (Making it very difficult to set up debug logging for a number of users to try and perhaps catch when the exception occurs). I can't work out what is causing the exception as the error message does not make sense in context of the code.

Exception caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []

The code on the line specified in the exception:
//Add emails to the list of emails to be sent
                                  Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                                  message.setOrgWideEmailAddressId(emailAddress.Id);
                                  message.setTargetObjectId(c.ContactId);
                                  message.setWhatId(c.Id);
                                  message.setTemplateId(inttemplate.Id);
                                  messages.add(message);
                          }
Messaging.sendEmail(messages);
                     
Clearly it doesn't specify plain text body, html body, subject or charset.