• Heather_Hanson
  • NEWBIE
  • 55 Points
  • Member since 2017
  • Project Manager
  • Selectcom Telecom


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 29
    Questions
  • 54
    Replies
My case is:
When a user selects a product, I want my trigger to look at the add_for__c value on that product and if it equals 0 then it should look for all products where the add_for__c field value is equal to the lsrv_pk__c value of the initial product selected.

I'm still very new to writing triggers and only just starting the databese and SQL portion of my education, but need this trigger for work ASAP so any help would be appreciated!

I found some sample code through my research on this need and have attempted to re-work it to my need and managed to get the trigger to save, but when I test it, I'm getting this error: 

Product_Auto_Add: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.Product_Auto_Add: line 40, column 1


I'm looking for help resolving this issue and also to ensure I've created my trigger to execute what I need it to.  I have no loops in there...do I need a loop to ensure it gets ALL products that have the matching value I mentioned above?

Here's the trigger:
 
trigger Product_Auto_Add on OpportunityLineItem (before insert) {
    
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>(); 
    
    List<String> lstProduct = new List<String>();
    
    for(OpportunityLineItem optLineItem: Trigger.new)
    {
        if(optLineItem.add_for__c == '0')
        {
            lstProduct.add(optLineItem.add_for__c);
        }
    }
    
    //retrieve values of Product Selected
    List<OpportunityLineItem> lstOpptyLineItems = [SELECT OpportunityId, Name, PricebookEntryId, Quantity, add_for__c, lsrv_pk__c, UnitPrice
                                                   FROM    OpportunityLineItem
                                                   WHERE   Id = :Trigger.new 
                                                   AND add_for__c IN:lstProduct];
    
    //create a map which contains Product Name and OpportunityLineItem
    Map<String, OpportunityLineItem> mapOpptyLineItem = new Map<String, OpportunityLineItem>();
    for(OpportunityLineItem item:lstOpptyLineItems)
    {
        mapOpptyLineItem.put(item.lsrv_pk__c, item);
    }
    
    //retrieve PriceBookEntry of the Product B, this is most important
    PricebookEntry pbeProduct2 = [SELECT Id, Pricebook2Id, UnitPrice, Name, add_for__c
                                  FROM PricebookEntry 
                                  WHERE Pricebook2Id IN 
                                  (SELECT Id FROM PriceBook2 
                                   WHERE Name = 'Selectcom Telecom Pricing') 
                                  LIMIT 1];
    
    
    //retrieve Product A item from the map.         
    OpportunityLineItem itemProductA = mapOpptyLineItem.get('Product A');
    
    if(itemProductA.lsrv_pk__c == pbeProduct2.add_for__c){
        
        
        oliList.add(new OpportunityLineItem(
            OpportunityId = itemProductA.OpportunityId, 
            PricebookEntryId = pbeProduct2.Id,
        	Quantity = itemProductA.Quantity,
        	UnitPrice = pbeProduct2.UnitPrice)
                   );
        
        insert oliList;
    }
}

FYI Line 40 is:
if(itemProductA.lsrv_pk__c == pbeProduct2.add_for__c){

Thank you!
I've been working with the compent offered on this site:
https://sfdcmonkey.com/2017/04/19/download-csv-file-data-salesforce-lightning-component/

It's working perfectly, but one thing I missed is that it seems to pull all user records in my org, but really I just want to see those that are related to the Programming__c record where the button is clicked.

Is there a way to achieve this in my class?
 
public class User_List {
 
@AuraEnabled
   public static list <User_List__c> fetchList(){
      
      List <User_List__c> returnUserList = new List < User_List__c > ();
        
      for(User_List__c ul: [SELECT 	id, First_Name__c, Last_Name__c, Email__c, Extension_Number__c, Type_of_User_License__c, Phone_Model__c, Language__c, Outbound_Number_Display__c, Outbound_Name_Display__c, Voicemail_Option__c, CFNR_Number__c From User_List__c LIMIT 1000]) {
             returnUserList.add(ul);
          }
         return returnUserList;
   }
}

 
I wrote a test class for my class related to a lightning component, but when I run it I get 0 coverage.

Here is the class that needs to be tested:
public class User_List {
@AuraEnabled
   public static list <User_List__c> fetchList(){
      
      List <User_List__c> returnUserList = new List < User_List__c > ();
        
      for(User_List__c ul: [SELECT 	id, First_Name__c, Last_Name__c, Email__c, Extension_Number__c, Type_of_User_License__c, Phone_Model__c, Language__c, Outbound_Number_Display__c, Outbound_Name_Display__c, Voicemail_Option__c, CFNR_Number__c From User_List__c LIMIT 1000]) {
             returnUserList.add(ul);
          }
         return returnUserList;
   }
}

My test class basically has me creating a record of the objects needed before a User_List record is created and then it creates a User_List record.

This is my first time working with Lightning Components and alot of my test classes do the same thing so I'm wondering if I need to do something different here?

Help would be greatly appreciated!
Not sure if this is possible, but I want a trigger to fire when the Clone button on opportunity is clicked so that an alert will popup.  The alert is basic and the user can just click OK and move on to the standard clone create/edit page...I'd rather not override the standard edit page so that is why I'm hoping I can somehow achieve this in a trigger?

My trigger is below, but I'm thinking of all the actions available (before insert, after insert etc....) and none of them make logical sense so I'm not sure if what I want to do is possible. 

Worst case, I will just do it before insert, but the message will be telling them to NOT complete fields in the edit screen until after they save (loooong story) so it would be better for the user to get that message before they get to the edit screen.

Any help or suggestions would be appreciated!
 
trigger Clone_Popup on Opportunity (before insert) {
    for (Opportunity o : Trigger.new) {
  	if ( o.isclone() ) {
    o.addError('Warning...blah blah blah');
  }
}
}

 
Hi, I've spent the morning researching and am still stuck trying to figure out where to begin.

I found a great resource at: https://douglascayers.com/2016/03/20/salesforce-easy-ways-to-export-data-as-csv/ (https://douglascayers.com/2016/03/20/salesforce-easy-ways-to-export-data-as-csv/)

But I'm not sure how to work it to my purpose. I have a custom object: Programming__c and I want to pull the related list records of User_List__c as a CSV.  It doesn't need to be saved as a content delivery (I don't need that taking up my file storage) so I would like it to be accessed through a custom button / visualforce page where the user can download it and save to desktop.

So my two problems are this:
I'm not sure how to properly formulate the class to work for me. I know that is just a snippet so I likely need to wrap it in something like public class UserList{}, but I'm not sure what to do next because I'm still getting errors.  Any help adjusting this would be greatly appreciated.

Once I get my class working, I'm not sure exactly how to call it on my visualforce page to avoid any styling.  Any help would be so appreciated!

My code that I've been working on is below:

Class:
public class ExportUserList{

public String csv = 'Id,Name\n';
for ( List<User_List__c> ul : [ SELECT id, First_Name__c FROM User_List__c ] ) {
  for ( User_List__c ul : ul) {
    csv += ul.id + ',' + ul.First_Name__c.escapeCsv() + '\n';
  }
}
    
 
ContentVersion file = new ContentVersion(
  title = 'userList.csv',
  versionData = Blob.valueOf( csv ),
  pathOnClient = '/userList.csv'
);
 
insert file;
System.debug( file );
}


Visualforce (not much to show since I'm not sure what tags to use to avoid any styling)
 
<apex:page controller='ExportUserList' contentType='application/octet-stream#User_List.csv' showHeader="false">

</apex:page>




 
Hello, I'm working on a visualforce page and I can't seem to get my tables to line up the way I want them to. I've had some success, but am just having trouble finishing it off.

I need it to look like this:
User-added image
But so far I have only managed to make it look like this:
User-added image

Here is the HTML 
<table class="Cx" width="98.7%">
        <tr><td class="tac rPad" colspan="4"><strong>Telco Info</strong></td></tr>
        <tr><td class="tar rPad">Sales Order:</td><td>company name</td></tr>
        <tr><td class="tar rPad">Sales Rep:</td><td>Rebiller Group</td><td>TN:</td><td>1-800-555-5555</td></tr>
        <tr><td class="tar rPad">E-Mail:</td><td>ao@ao.ca</td></tr>
        <tr><td class="tar rPad">Original E-Mail:</td><td>ao@selectcomtelecom.ca</td></tr>
        <tr><td class="tar rPad">Original Fax:</td><td>555-555-5555</td></tr>
    </table>

    <br/>

    <div width="98.7%" class="col-container">
        
    
    <table class="Cx col" >
        <th><strong>Activty</strong></th>
        <tr><td>x</td><td>New</td><td>TF</td></tr>
        <tr><td>Add</td><td>Disc</td></tr>
		<tr><td>Change</td></tr>
        <tr><td>Seasonal Disc</td></tr>        
        <tr><td>Reconnect Date</td></tr>
     </table>

&nbsp;
    
      
    <table class="Cx col" >
		<th><strong>Service Type</strong></th>
        <tr><td>Service</td></tr>
        <tr><td>Cross Border-MCI</td></tr>
        <tr><td>Cross Border-AT&amp;T</td></tr>
        <tr><td>Other</td></tr>
        <tr><td><strong>Mass Calling</strong></td></tr>
        <tr><td>Yes</td><td>x</td><td>No</td></tr>
    </table>
    
    &nbsp;

    <table>
        <tr><td>
        <table width="100%" class="Cx col">

        <tr><td><strong>Dates</strong></td></tr>
        <tr><td>Application Date:</td>
            <td><apex:outputText value="{0,date,yyyy-MM-dd}"><apex:param value="{!Client_Line__c.LASTMODIFIEDDATE}" /></apex:outputText></td>
		</tr>
        <tr><td>Due Date: ??</td><td>what is the merge field?</td></tr>  

        </table>
        &nbsp;
        <table width="100%" class="Cx col">
        <tr><td><strong>Reference of Calls</strong></td></tr>
        <tr><td>Yes</td><td>x</td><td>No</td></tr>
        <tr><td>Refer Calls To</td></tr>
        </table>
            </td>
        </tr>
    </table>
    </div>

And the CSS is
.Cx{
    border: 1px solid #534e43;
}
.tac{
    text-align: center;
}
.tar{
    text-align: right;
}
.tal{
    text-align: left;
}
.rPad{
    padding-right: 10px;
}
.col-container {
  display: table;
  width: 98.7%;
}
.col {
  display: table-cell;
  padding: 16px;
}
Any help would be appreciated!  Been struggling with this for awhile now.
I have a Visualforce page that we render as PDF.  I need to have 14 full page images referenced at the beginning.  I've done some searching and found that the way to avoid the blank first page is to use the css: position: absolute;top:0;

This works at removing the leading blank page, but it also somehow messes with the images.  The first image referenced somes out fine, but you can see on the right that there is some of the second image and then there is no page with the second image.

I have tried a variety of different css and have yet to figure it out.  Is there a way to remove the leading blank page and keep all image tags working properly?
I'm working on a custom classic email template using HTML and when I see the preview and when I test it in my browser, my alignment is good, but when I send a test email, the alignment is off.  

Any suggestions what I can do to resolve this?

Here is what it looks like in preview:
User-added image

Here is the email test:

User-added image
Here is a bit of my code:
<body style="font-family: Montserrat, sans-serif;">
<style>
	.progress{width: 80%; height: auto; margin:0 auto 0 auto; color: #404040; font-size: 14px; }
	.p{font: Montserrat, sans-serif; text-align: left; }
</style>

<table class="progress" cellpadding="2px">
	<tr>
		<td style="vertical-align: bottom; text-align: center;" >
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCE&oid=00DA0000000gd8G&lastMod=1581343779000" alt="orange-circle" height:20 ></td>
		<td style="">
			<p><strong>Site Survey Scheduled</strong></p>
		</td>
	</tr>

	<tr>
		<td style="vertical-align: top; text-align: center;">
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCJ&oid=00DA0000000gd8G&lastMod=1581343802000" alt="orange-line" height="120" ></td>
		<td style="vertical-align: top; font-size: 12px;">
			<p>Friday, February 7</p>
		</td>
	</tr>

	<tr>
		<td style="vertical-align: top; text-align: center;">
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCO&oid=00DA0000000gd8G&lastMod=1581343827000" alt="grey-circles" height="20" ></td>
		<td style="vertical-align: top;">
			<p><strong>Order Received</strong></p>
		</td>
	</tr>

	<tr>
		<td style="vertical-align: top; text-align: center;">
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCT&oid=00DA0000000gd8G&lastMod=1581343849000" alt="grey-lines" height="20" ></td>
		<td style="vertical-align: top;">
			<p></p>
		</td>
	</tr>

 
I’m having trouble with my test class…not sure what I’m doing wrong, but I’m getting the following errors:
Illegal assignment from Map to List (line 6)
Method does not exist or incorrect signature: void getRecTypeId(String) from the type RecordTypeSelector (line 11)

My test class is for a custom record type selector component on my Asset object for my customer object OrderProject__c.

Any help would be appreciated!!
 
@isTest
public class TestRecordTypeSelector {


static testmethod void testFetchRecordTypes() {
    List<String> value = RecordTypeSelector.fetchRecordTypeValues('Asset');
  }

 static testmethod void testgetRecordTypeId() {
    String recordTypeLabel = 'Avaya';
    ID testId = RecordTypeSelector.getRecTypeId(recordTypeLabel);
    System.assert(testId != null);
  }
}

 
I'm using apex:datatable for my Visualforce page when rendered as PDF.

I want to visually separate the rows based on the value of a specific field.

The datatable provides the opportunitylineitems and I'm trying to organize the results using "render" on the columns, which seems to work, but I also want a break between certain rows.

Here is an image of what I'm TRYING to do:
User-added image

I have tried simply adding the <br/> between columns in the datatable, but that didn't work.

I have also tried creating multiple datatables and wrapping them in an output panel so that I could then add a <br/>, but the PDF generation failed when I tried that.

I also tried using apex:repeat to see if I could solve the problem with that tag, but couldn't figure it out.

Any help would be appreciated!
Trying to make updates to an existing form that we also render as PDF.  The HTML version of the form worked fine with my changes, but as usual, I'm having trouble with rendering as PDF.

I basically want to group products in their own box based on the Product Type. 

An example is below, but when I add the second datatable with the new category, I get the PDF generation error message.  I checked to make sure I didn't make a mistake somewhere by duplicating the first one and that worked (so I had two groups with the same set of products), so it seems just when I try to pull a different batch of products that the error message occurs.  

My product type name is correct and there are values available (as I know if there is no value sometimes this also causes a generation fail).

Does anyone have any suggestions as to how I can fix this?
<apex:dataTable value="{!Opportunity.opportunityLineItems}" var="OP" style="width:98.7%">
                  <apex:column rendered="{!OP.Product_Type__c = 'Mandatory'}" headerValue="Item" value="{!OP.ProductCode}" headerClass="column_ttl tal" styleClass="tbl_bdr tal" style="width:8%;"></apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Mandatory'}" headerValue="{!set}" value="{!OP.Set__c}" headerClass="column_ttl tal" styleClass="tbl_bdr tal" style="width:5%;"></apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Mandatory'}" headerValue="{!lblQty}" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OP.Quantity}" /></apex:outputText></apex:column>
                  <apex:column headerValue="Description" value="{!OP.PriceBookEntry.Name}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.Product_Type__c = 'Mandatory' && Opportunity.Language__c = 'ENGLISH'}"></apex:column>
                  <apex:column headerValue="Description" value="{!OP.Product2.Product_name_french__c}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.Product_Type__c = 'Mandatory' && Opportunity.Language__c = 'FRENCH'}"></apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Mandatory'}" headerValue="{!lblMonthPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;">
                	<apex:outputText value="{0, number,###,###,##0.00}" rendered="{!OP.Payment_Description__c = 'Monthly'}">$<apex:param value="{!OP.UnitPrice}" /></apex:outputText>
                	<apex:outputText value="$0.00"  rendered="{!OP.Payment_Description__c != 'Monthly'}"/>
                  </apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Mandatory'}" headerValue="{!lblOneChrg}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;" >
                    <apex:outputText value="{0, number,###,###,##0.00}" rendered="{!OP.Payment_Description__c = '1X Fee'}">$<apex:param value="{!OP.UnitPrice}" /></apex:outputText>
                	<apex:outputText value="$0.00"  rendered="{!OP.Payment_Description__c != '1X Fee'}"/>
                  </apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Mandatory'}" headerValue="{!lblSubTot}" value="{!OP.TotalPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                </apex:dataTable>
              <br/>
                <apex:dataTable value="{!Opportunity.opportunityLineItems}" var="OP" style="width:98.7%">
                  <apex:column rendered="{!OP.Product_Type__c = 'Base'}" headerValue="Item" value="{!OP.ProductCode}" headerClass="column_ttl tal" styleClass="tbl_bdr tal" style="width:8%;"></apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Base'}" headerValue="{!set}" value="{!OP.Set__c}" headerClass="column_ttl tal" styleClass="tbl_bdr tal" style="width:5%;"></apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Base'}" headerValue="{!lblQty}" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OP.Quantity}" /></apex:outputText></apex:column>
                  <apex:column headerValue="Description" value="{!OP.PriceBookEntry.Name}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.Product_Type__c = 'Base' && Opportunity.Language__c = 'ENGLISH'}"></apex:column>
                  <apex:column headerValue="Description" value="{!OP.Product2.Product_name_french__c}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.Product_Type__c = 'Base' && Opportunity.Language__c = 'FRENCH'}"></apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Base'}" headerValue="{!lblMonthPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;">
                	<apex:outputText value="{0, number,###,###,##0.00}" rendered="{!OP.Payment_Description__c = 'Monthly'}">$<apex:param value="{!OP.UnitPrice}" /></apex:outputText>
                	<apex:outputText value="$0.00"  rendered="{!OP.Payment_Description__c != 'Monthly'}"/>
                  </apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Base'}" headerValue="{!lblOneChrg}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;" >
                    <apex:outputText value="{0, number,###,###,##0.00}" rendered="{!OP.Payment_Description__c = '1X Fee'}">$<apex:param value="{!OP.UnitPrice}" /></apex:outputText>
                	<apex:outputText value="$0.00"  rendered="{!OP.Payment_Description__c != '1X Fee'}"/>
                  </apex:column>
                  <apex:column rendered="{!OP.Product_Type__c = 'Base'}" headerValue="{!lblSubTot}" value="{!OP.TotalPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                </apex:dataTable>

 
Hello,

I'm a novice at Apex code and am trying to adjust my extension for SavePDF so that it saves as a file as well.  I get an error message related to the line that says:  file.Origin = 'a';

I am indicating the wrong origin or something?  Or do I need to complete the attachment fully before I can add the file?  Any help would be appreciated!

 
public pageReference savePDF(){
    
        Date dateToday = Date.today();
        String sMonth = String.valueof(dateToday.month());
        String sDay = String.valueof(dateToday.day());
        if(sMonth.length()==1){
          sMonth = '0' + sMonth;
        }
        if(sDay.length()==1){
          sDay = '0' + sDay;
        }
        String sToday = String.valueof(dateToday.year())+ '-' + sMonth +  '-' + sDay ;
        
      PageReference pagePdf = new PageReference('/apex/SalesAgreement_PDF');
          pagePdf.getParameters().put('id', idVal);
          Blob pdfPageBlob;
          pdfPageBlob = pagePdf.getContentAsPDF();
                 
          Attachment a = new Attachment();
          a.Body = pdfPageBlob;
          a.ParentID = idVal;
          a.Name = 'Service_Agreement_' + strOppName + '_' + sToday + '.pdf';
          a.Description = 'Service Agreement_' + sToday;
          insert a;

          ContentVersion file = new ContentVersion();
		  file.Title = 'Service_Agreement_' + strOppName + '_' + sToday + '.pdf';
		  file.PathOnClient = 'Service_Agreement_' + Datetime.now().getTime() + '.txt';
		  file.VersionData = Blob.valueOf('Service_Agreement_' + 
		  Datetime.now().getTime() + '.txt');
		  file.Origin = 'a';
		  insert file;         
    
        
        pop_msg='Successfully saved';
        displayPopup = true;  
       
        
        opp.Signature_Date__c = null;
        opp.Signature_Key__c = '';
        opp.Signature_Name__c = '';
        opp.Signature_URL__c = null;
        opp.Signature__c = null;

        
        update opp;
      return new PageReference('/apex/SalesAgreement_HTML?id=' + idVal);
      
        
    }



 
My PMs want to see which other opportunities have been signed when they receive an approved opportunity.  I created a VF page add an opportunity related list and it works, but I can't figure out how to ONLY show those where StageName = 'SIGNED'.  

Any help would be appreciated...
 
<apex:page standardController="Opportunity" showHeader="false" sidebar="false" readOnly="true">
<style type="text/css">
.actionColumn {display:none; visibility:hidden}
</style>

    <apex:relatedList list="Account.Opportunities">
    <apex:facet name="header"><center><b></b></center></apex:facet>
    </apex:relatedList>

</apex:page>

 
I need to create a popup alert on Account object that is triggered when the related contacts (related list) need to be updated.  So I want to look at a custom date field in Contact "Last_Verified__c" and if it is blank or older than 2 years this should trigger the popup on the Account to recommend updating the contacts.

I can figure out the visualforce page, but I'm still new to Apex (I've only got about 3 triggers so far) and this one feels a little complicated.  Can anyone help get me started on the Apex Class?

Thanks!
My Visualforce page is throwing an error sometimes saying to check the markup. I've made sure of the following:

- No empty fields
- I've removed render PDF and the HTML generates with no problem
- I've removed my code until I found the trouble area and it is my datatable, specifically the IF statement in my columns.
- My last attempt to resolve the issue was to make sure that the field represented in the IF statement appears as a column...still didn't solve the issue.

Here is the data table section of the VF page:
 
<apex:dataTable value="{!Account.Hardware__r}" var="AH" columns="3" cellPadding="0" border="1" width="100%"  headerclass="Mheader_sm" title="Returned Equipment">
            
            <apex:column headerValue="PRODUCT NAME" rendered="{!IF(AH.Client_Returned_Date_VF__c = TODAY(),true,false)}" value="{!AH.Product_Txt__c}" styleClass="tbl_bdr" /> 
            <apex:column headerValue="SERIAL #" rendered="{!IF(AH.Client_Returned_Date_VF__c = TODAY(),true,false)}" value="{!AH.Serial_Number__c}"  styleClass="tbl_bdr"/>
            <apex:column headerValue="RETURNED DATE" rendered="{!IF(AH.Client_Returned_Date_VF__c = TODAY(),true,false)}" value="{!AH.Client_Returned_Date_VF__c}"  styleClass="tbl_bdr"/>

        </apex:dataTable>

The fields Product_Txt__c and Client_Returned_Date_VF__c are both formula fields (text and date respectively)...here's a screenshot of their properties:

User-added image

User-added image

The problem seems to occur if the Account related list have multiple Hardware records and although the formula fields above are populated, if the "Client_Returned_Date__c" mentioned in the Client_Returned_Date_VF__c formula is blank on one of them, it throws the PDF generation failed. Check the page markup is valid. 

So to repeat, there is a value for the 3 fields mentioned in my data table for ALL records, but it is still throwing the error....any suggestions what I could do next to troubleshoot this?

Here is a sample of one that is throwing that error:

User-added image
I think I know WHY I'm getting the error, but still haven't solved it.

I have a visualforce page that renders as PDF.  It is a receipt for returned hardware.  We have a Hardware custom object and my VF page has a conditional rendering to only show the Hardware Product Name and Serial number originally, if the "Client_Returned_Date__c" = TODAY. 

We then got the error message above for one account and I realized it is probably because some records may have nothing populated in the "Client_Returned_Date__c" field so I created a Date Formula field that says: IF(Client_Returned_Date__c = TODAY(), Client_Returned_Date__c, DATE(2000,01,01) ). It means the person would have to update all previous hardware, but there is not many so it isn't that much and going forward the field will always be populated so it won't always be an issue.

So I updated my VF page conditional rendering to use this new formula field instead and tested.  My formula field works as expected, but I still get the error message above (even though there is now a value for each record for this formula field.  I also checked the other fields indicated (Product name and Serial number) and there are values in all.

Any suggestions what I'm overlooking?

Here is the VF page if it helps!:
 
<apex:page standardController="Account" applyHtmlTag="true" showHeader="false" renderAs="PDF">

<apex:stylesheet value="{!$Resource.AssetReceipt_PDF}"/>
<apex:stylesheet value="http://fonts.googleapis.com/css?family=Open+Sans"/>



      
    <table cellspacing="0" border="0" cellpadding="0" width="98%">  
        <tr>
            <td width="80%" valign="top"><apex:image id="logo" url="{!$Resource.logo_bkp}"/> </td>
            <td width="18%">               
                <table id="servicetbl" cellspacing="0" border="0" cellpadding="5">
                    <tr><td colpsan="3"></td></tr>     
                    <tr>
                    <td class="rt" width="20%">Date:&nbsp;<apex:outputText value="{0,date,yyyy-MM-dd 'Time:' hh:mm}"> <apex:param value="{!NOW () - 0.208333}" /></apex:outputText></td>                    
                    </tr>
                </table>
            </td>
        </tr>
    </table>   
    
    <br clear="all" />
    <div class="full_line">{!Account.Name}</div><br clear="all"/>
    <div class="full_line">{!Account.AccountNumber}</div><br clear="all"/>

    <div >
        <br/>
        <br/>
        <h2>ÉQUIPEMENT RETOURNÉ</h2><br clear="all"/>
        <apex:dataTable value="{!Account.Hardware__r}" var="AH" columns="6" cellPadding="0" border="1" width="100%"  headerclass="Mheader_sm" title="Returned Equipment">
            
            <apex:column headerValue="PRODUCT NAME" rendered="{!IF(AH.Client_Returned_Date_VF__c = TODAY(),true,false)}" value="{!AH.Product_Txt__c}" styleClass="tbl_bdr" /> 
            <apex:column headerValue="SERIAL #" rendered="{!IF(AH.Client_Returned_Date_VF__c = TODAY(),true,false)}" value="{!AH.Serial_Number__c}"  styleClass="tbl_bdr"/>

        </apex:dataTable>
    </div>    
   
    <div class="full_line">
        
    <table>
    <tr>
    <td style="border-bottom:1px solid #000000; height:75px; width:40%;"></td>
    </tr>  
    <tr>
    <td>Heather Hanson</td>
    </tr>
    </table>
    </div>
    
        <div class="footerC">
            <div class="cover_footer">My company info</div>    
        </div>
           
 
 </apex:page>

 
I'm still reallly new to triggers.  I have 2 custom objects, "Work_Order__c" and "OrderProject__c", Work Order is a child of Account and Order Project is just related to Account with a look up field.

Order Project and Work Order are also related.  I have a related list for Work Order in the Order Project object. So Work Orders are created from an Order Project.

I created a field in Order Project called "Installatin_WO__c".  I need this field to be populated with the "Name" of the Work Order in the related list found in the Order Project that has the Work_Order_Type__c of "Installation".

I've only ever successfully created one trigger before and it is very similar to what I want to accomplish here, but I'm running into a couple of errors so I think I may be lacking understanding....

Below is what I have and the 2 error messages I have are:


Line: 9 Name, Work_Order_Type__c from Work_Order__c Where Work_Order_Type__c
                              ^
ERROR at Row:1:Column:60
Didn't understand relationship 'Work_Order__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.


AND

Line 17: Variable does not exist: WO

Any help correcting this would be greatly appreciated!!
trigger PM_WO_Installation on OrderProject__c (before insert, before update) {

set<Id> AccountIds = new set<Id>();
for (OrderProject__c  pm: trigger.new) {
	AccountIds.add(pm.Account_ID__c);
}
map<Id, Account> AccountWOMap = new map<Id, Account>();
list<Account> AccWOs = new list<Account>();
AccWOs = [Select Id, Name, (Select Id, Name, Work_Order_Type__c from Work_Order__c Where Work_Order_Type__c = 'Installation') from Account where Id IN : AccountIds];
for(Account acc : AccWOs){
    AccountWOMap.put(acc.Id, acc);
}
    for (OrderProject__c  pm: trigger.new) {
       if(pm.Installation_WO__c == null){
			Account Acc = AccountWOMap.get(pm.Account_ID__c);
			if(Acc != null){
				List<Work_Order__c> WO = new list<Work_Order__c>(Acc.WO);
				if(WO.size() == 1){
					pm.Installation_WO__c = WO[0].Id;
				}
			}
		}
	}

}

 
A few months ago, I was asked to add to our existing Visualforce page, two more pages that present the products chosen in a certain way.  Our products got labelled "NQP" if it was equipment and "HPX, HPS, or LIC" if it was a service, and "CNT" if it was an activation fee.

Rendering the page to PDF has been termpermental ever since. Sometimes it works and sometimes I get the error message.  I have checked and ensured that each product has it's label as I know that was the cause of the problem at times.  Sometimes when the problem occurs, I find just removing all the products and picking them all again helps, but right now I'm currently stuck on fixing one and also would like for this problem to just not happen anymore.

I read that empty columns cause problems on the render PDF, so I fixed that, but I'm still having issues.  I think I have narrowed the issue down to one of the two pages that I had to add.  Here is the code for the HTML version (we have a button in the HTML that is linked to the PDF rendered version).
<table class="column_ttl2" style="width:100%;">
                            <tr>
                            <td style="width:10%;" class="tac">TR Code</td>                                
                            <td style="width:5%;">Qty</td>
                            <td class="tal">Description</td>
                            <td style="width:15%;" class="tac">Unit Price</td>
                            <td style="width:15%;" class="tac">Totals</td>
                            </tr>
                        </table>
                 <apex:pageBlock >
                         <apex:pageblocktable value="{!Opportunity.opportunityLineItems}" var="OP" styleClass="items_tbl">
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="TR Code" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText value="{!OP.TR_Service_Group__c}"/></apex:column>
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblQty}" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OP.Quantity}" /></apex:outputText></apex:column>
                            <apex:column headerValue="Description" value="{!OP.PriceBookEntry.Name}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'NQP' && Opportunity.Language__c = 'ENGLISH'}"></apex:column>
                            <apex:column headerValue="Description" value="{!OP.Product2.Product_name_french__c}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'NQP' && Opportunity.Language__c = 'FRENCH'}"></apex:column>
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblUnitPrice}" value="{!OP.UnitPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblSubTot}" value="{!OP.TotalPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                     </apex:pageblocktable>
                     
                        <apex:outputPanel rendered="{!strServiceType = 'HPBX'}">
                            <apex:pageblocktable value="{!Opportunity}" var="OPP" headerClass="hidden" >
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Unifôn Services</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unifon_Services__c}"/>  
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unifon_Services__c}"/>  
                            </apex:pageblocktable>
                        </apex:outputPanel>
                     
                        <apex:outputPanel rendered="{!strServiceType ='Unifôn IP Connect' && CONTAINS(Opportunity.Financing_Term__c, '36')}">
                            <apex:pageblocktable value="{!Opportunity}" var="OPP" headerClass="hidden" >
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Unifôn Services</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                            </apex:pageblocktable>
                        </apex:outputPanel>   

                        <apex:outputPanel rendered="{!strServiceType ='Unifôn IP Connect' && CONTAINS(Opportunity.Financing_Term__c, '60')}">
                            <apex:pageblocktable value="{!Opportunity}" var="OPP" headerClass="hidden" >
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Unifôn Services</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                            </apex:pageblocktable>
                        </apex:outputPanel> 
                     
                      <apex:pageblocktable value="{!Opportunity}" var="OPP" headerClass="hidden" >
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >CNT</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Interconnection_Installation_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Interconnection: Installation</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Interconnection_Installation__c}"/>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Interconnection_Installation__c}"/>
                     </apex:pageblocktable>
Here is the PDF version.  
 
<table class="column_ttl" style="width:98.7%;">
                            <tr>
                            <td style="width:10%;" class="tac">TR Code</td>                                
                            <td style="width:5%;">Qty</td>
                            <td class="tal">Description</td>
                            <td style="width:15%;" class="tac">Unit Price</td>
                            <td style="width:15%;" class="tac">Totals</td>
                            </tr>
                        </table>
                        

                        <apex:dataTable value="{!Opportunity.opportunityLineItems}" var="OP" style="width:98.7%">
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="TR Code" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText value="{!OP.TR_Service_Group__c}"/></apex:column>
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblQty}" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OP.Quantity}" /></apex:outputText></apex:column>
                            <apex:column headerValue="Description" value="{!OP.PriceBookEntry.Name}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'NQP' && Opportunity.Language__c = 'ENGLISH'}"></apex:column>
                            <apex:column headerValue="Description" value="{!OP.Product2.Product_name_french__c}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'NQP' && Opportunity.Language__c = 'FRENCH'}"></apex:column>
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblUnitPrice}" value="{!OP.UnitPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                            <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblSubTot}" value="{!OP.TotalPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                        </apex:dataTable>
                        
                        <apex:outputPanel rendered="{!strServiceType = 'HPBX'}">    
                            <apex:dataTable value="{!Opportunity}" var="OPP" headerClass="hidden"  style="width:98.7%">
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Unifôn Services</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unifon_Services__c}"/>  
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unifon_Services__c}"/>  
                            </apex:dataTable>
                        </apex:outputPanel>

                        <apex:outputPanel rendered="{!strServiceType ='Unifôn IP Connect' && CONTAINS(Opportunity.Financing_Term__c, '36')}">    
                            <apex:dataTable value="{!Opportunity}" var="OPP" headerClass="hidden"  style="width:98.7%">
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Unifôn Services</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                            </apex:dataTable>
                        </apex:outputPanel>

                        <apex:outputPanel rendered="{!strServiceType ='Unifôn IP Connect' && CONTAINS(Opportunity.Financing_Term__c, '60')}">    
                            <apex:dataTable value="{!Opportunity}" var="OPP" headerClass="hidden"  style="width:98.7%">
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Unifôn Services</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                            </apex:dataTable>
                        </apex:outputPanel>    
    
                            <apex:dataTable value="{!Opportunity}" var="OPP" headerClass="hidden" style="width:98.7%">
                                <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >CNT</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Interconnection_Installation_Qty__c}" /></apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Interconnection: Installation</apex:outputText></apex:column>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Interconnection_Installation__c}"/>
                                <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Interconnection_Installation__c}"/>
                            </apex:dataTable>

Any suggestions for improvement or trouble shooting would be greatly appreciated!
I created 1 new Trigger and a Test Class and it is saying that my overall code coverage is now 74%...but the test itself passes.

Maybe I'm missing something in my test?  Although I have a very similar trigger already and it is in production so not sure why this one is causing problems...

Here is the Trigger:
Trigger OppContactResi on Opportunity (before insert, before update) { 

set<Id> AccountIds = new set<Id>();
for (Opportunity  o: trigger.new) {
	AccountIds.add(o.AccountId);
}


map<Id, Account> AccountContactMap = new map<Id, Account>();
list<Account> AccConts = new list<Account>();
AccConts = [Select Id, Name, (Select Id, Name, Contact_Role__c from Contacts Where Contact_Role__c = 'MAIN CONTACT') from Account where Id IN : AccountIds];
for(Account acc : AccConts){
    AccountContactMap.put(acc.Id, acc);
}

for (Opportunity  o: trigger.new) {
       if(o.Contact__c == null && o.RecordTypeID == '0121H0000019Lna'){
			Account Acc = AccountContactMap.get(o.AccountId);
			if(Acc != null){
				List<Contact> conts = new list<Contact>(Acc.Contacts);
				if(conts.size() == 1){
					o.Contact__c = conts[0].Id;
				}
			}
		}
	}
}

Here is the TestClass:
 
@isTest 

public class OppContactResiTEST {
    
    static testMethod void createAccount()
	{

		Account a = new Account();
		a.Name = 'Test';
        a.RecordTypeId = '0121H0000019LnX';
        a.Language__c = 'ENGLISH';
		insert a;
		System.debug('created account');
			
		//Then create a non Main contact
		Contact c = new Contact();
        c.RecordtypeId = '0121H0000019LnZ';
		c.FirstName = 'Paul';
		c.LastName  = 'Test';
		c.AccountId = a.id;
		c.Contact_Role__c = 'BILLING CONTACT';
        c.Phone = '514-722-5656';
		insert c;
		System.debug('created signing contact');
			
		//Then create another Main contact
		Contact ci = new Contact();
		ci.FirstName = 'Bob';
		ci.LastName  = 'Test';
		ci.AccountId = a.id;
		ci.Contact_Role__c = 'MAIN CONTACT';
        ci.Phone = '514-722-5656';
		insert ci;
		System.debug('created non-signing contact');
        
        
        
        //Create Top Shelf Settings
        Scout__TopShelf_Settings__c ts = new Scout__TopShelf_Settings__c();
        ts.Scout__TopShelf_Username__c = 'selectcom';
        ts.Scout__TopShelf_Password__c = 'Fhtmdvp2';
        ts.Scout__My_Account__c = a.id;
        insert ts;
        System.debug('created top shelf settings');
		
       
		//Now create an opportunity
		Opportunity o = new Opportunity();
        o.AccountId = a.id;
        o.Name = 'Test -';
        o.Service_Agreement_Type__c = 'Residential Services';
		o.StageName = 'NEW - CALL IN';
		o.Type = 'SALES';
		o.CloseDate = Date.today();
        o.RecordTypeId = '0121H0000019Lna';
        o.Requested_Install_Time__c = '	In the morning (9:00am-12:00pm)';
        o.Internet_Requested__c = TRUE;
        o.Existing_Internet_Provider__c = 'Bell';
        o.Existing_Internet_Service__c = 'Yes';
        o.If_Bell_is_internet_on_line_or_Dry_Loop__c = 'Line';
        o.Language__c = 'ENGLISH';  
        o.Router_Option__c = 'Customer already has router';
		insert o;
		System.debug('created opportunity');
    		
        

	}
}

​​​​​​​
I've completed the Developer Basic trail and the Apex lessons, but I only have minimal experience using Apex Triggers and Classes and have been struggling all afternoon to figure out the best and most user friendly way to do this.

I need to validate fields on the Opportunity object when someone clicks the "Submit for Approval" button related to an approval process.  Since validation rules do not work with field updates in the approval process, I though I could do an Apex Trigger instead using add.error method.

I have been working on my trigger and listing all the possible things to validate, but I ran into the issue where it only throws one error message at a time.  So I investigated further and now I'm not sure if I need to create a visualforce page or just adjust my trigger to fix it.  I would like to do visualforce as well since I don't like the screen that pops up with the error message.  I'm comfortable with Visual force, but I'm not sure how to tie in my trigger and do I need to write a separate controller for the Visualforce page.

Any guidance would be greatly appreciated!!

Here is my trigger...again I'm new so please excuse me if it is totally the wrong way to go about this...
 
trigger OppResiApprovalVali on Opportunity (before update) {

  for(Opportunity o : trigger.new)
  {  if(o.RecordTypeId=='0121H0000019Lna' && o.StageName=='PRE-PROVISIONING' && o.Internet_Requested__c==TRUE)
   {     
        if(o.Existing_Internet_Service__c==null)      
    {
      o.Existing_Internet_Service__c.addError('Please make a selection for Existing Internet Service.');
    }
       
       if(o.Existing_Internet_Provider__c==null && o.Existing_Internet_Service__c=='Yes')
       {
           o.addError ('Please make a selectcion for Existing Internet Provider.');           
       }     
          if(o.Existing_Internet_Provider__c=='Bell' && o.If_Bell_is_internet_on_line_or_Dry_Loop__c==null)
       {
           o.addError ('Please make a selectcion for If Bell, is internet on line or Dry Loop');           
       }
             if(o.Router_Option__c==null)
       {
           o.addError ('Please make a selectcion for Router Option');           
       }
   }
   
   {if(o.RecordTypeId=='0121H0000019Lna' && o.StageName=='PRE-PROVISIONING' && o.Home_Digital_Line_Requested__c==TRUE)
   {
       if(o.Telephone_to_be_transferred__c==null)      
    {
      o.addError('Please provide a response to Telephone Number to be Transferred.');
    }
       if(o.Current_Provider__c==null)      
    {
      o.addError('Please make a selection for Current Provider');
    }
       if(o.Call_Forward_Not_Reachable__c==null)      
    {
      o.addError('Please provide a response to Call Forward Not Reachable Number');
    }
      
       
   }
       
   }
     
   
   }

}

 
My case is:
When a user selects a product, I want my trigger to look at the add_for__c value on that product and if it equals 0 then it should look for all products where the add_for__c field value is equal to the lsrv_pk__c value of the initial product selected.

I'm still very new to writing triggers and only just starting the databese and SQL portion of my education, but need this trigger for work ASAP so any help would be appreciated!

I found some sample code through my research on this need and have attempted to re-work it to my need and managed to get the trigger to save, but when I test it, I'm getting this error: 

Product_Auto_Add: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.Product_Auto_Add: line 40, column 1


I'm looking for help resolving this issue and also to ensure I've created my trigger to execute what I need it to.  I have no loops in there...do I need a loop to ensure it gets ALL products that have the matching value I mentioned above?

Here's the trigger:
 
trigger Product_Auto_Add on OpportunityLineItem (before insert) {
    
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>(); 
    
    List<String> lstProduct = new List<String>();
    
    for(OpportunityLineItem optLineItem: Trigger.new)
    {
        if(optLineItem.add_for__c == '0')
        {
            lstProduct.add(optLineItem.add_for__c);
        }
    }
    
    //retrieve values of Product Selected
    List<OpportunityLineItem> lstOpptyLineItems = [SELECT OpportunityId, Name, PricebookEntryId, Quantity, add_for__c, lsrv_pk__c, UnitPrice
                                                   FROM    OpportunityLineItem
                                                   WHERE   Id = :Trigger.new 
                                                   AND add_for__c IN:lstProduct];
    
    //create a map which contains Product Name and OpportunityLineItem
    Map<String, OpportunityLineItem> mapOpptyLineItem = new Map<String, OpportunityLineItem>();
    for(OpportunityLineItem item:lstOpptyLineItems)
    {
        mapOpptyLineItem.put(item.lsrv_pk__c, item);
    }
    
    //retrieve PriceBookEntry of the Product B, this is most important
    PricebookEntry pbeProduct2 = [SELECT Id, Pricebook2Id, UnitPrice, Name, add_for__c
                                  FROM PricebookEntry 
                                  WHERE Pricebook2Id IN 
                                  (SELECT Id FROM PriceBook2 
                                   WHERE Name = 'Selectcom Telecom Pricing') 
                                  LIMIT 1];
    
    
    //retrieve Product A item from the map.         
    OpportunityLineItem itemProductA = mapOpptyLineItem.get('Product A');
    
    if(itemProductA.lsrv_pk__c == pbeProduct2.add_for__c){
        
        
        oliList.add(new OpportunityLineItem(
            OpportunityId = itemProductA.OpportunityId, 
            PricebookEntryId = pbeProduct2.Id,
        	Quantity = itemProductA.Quantity,
        	UnitPrice = pbeProduct2.UnitPrice)
                   );
        
        insert oliList;
    }
}

FYI Line 40 is:
if(itemProductA.lsrv_pk__c == pbeProduct2.add_for__c){

Thank you!
I've been working with the compent offered on this site:
https://sfdcmonkey.com/2017/04/19/download-csv-file-data-salesforce-lightning-component/

It's working perfectly, but one thing I missed is that it seems to pull all user records in my org, but really I just want to see those that are related to the Programming__c record where the button is clicked.

Is there a way to achieve this in my class?
 
public class User_List {
 
@AuraEnabled
   public static list <User_List__c> fetchList(){
      
      List <User_List__c> returnUserList = new List < User_List__c > ();
        
      for(User_List__c ul: [SELECT 	id, First_Name__c, Last_Name__c, Email__c, Extension_Number__c, Type_of_User_License__c, Phone_Model__c, Language__c, Outbound_Number_Display__c, Outbound_Name_Display__c, Voicemail_Option__c, CFNR_Number__c From User_List__c LIMIT 1000]) {
             returnUserList.add(ul);
          }
         return returnUserList;
   }
}

 
I wrote a test class for my class related to a lightning component, but when I run it I get 0 coverage.

Here is the class that needs to be tested:
public class User_List {
@AuraEnabled
   public static list <User_List__c> fetchList(){
      
      List <User_List__c> returnUserList = new List < User_List__c > ();
        
      for(User_List__c ul: [SELECT 	id, First_Name__c, Last_Name__c, Email__c, Extension_Number__c, Type_of_User_License__c, Phone_Model__c, Language__c, Outbound_Number_Display__c, Outbound_Name_Display__c, Voicemail_Option__c, CFNR_Number__c From User_List__c LIMIT 1000]) {
             returnUserList.add(ul);
          }
         return returnUserList;
   }
}

My test class basically has me creating a record of the objects needed before a User_List record is created and then it creates a User_List record.

This is my first time working with Lightning Components and alot of my test classes do the same thing so I'm wondering if I need to do something different here?

Help would be greatly appreciated!
Not sure if this is possible, but I want a trigger to fire when the Clone button on opportunity is clicked so that an alert will popup.  The alert is basic and the user can just click OK and move on to the standard clone create/edit page...I'd rather not override the standard edit page so that is why I'm hoping I can somehow achieve this in a trigger?

My trigger is below, but I'm thinking of all the actions available (before insert, after insert etc....) and none of them make logical sense so I'm not sure if what I want to do is possible. 

Worst case, I will just do it before insert, but the message will be telling them to NOT complete fields in the edit screen until after they save (loooong story) so it would be better for the user to get that message before they get to the edit screen.

Any help or suggestions would be appreciated!
 
trigger Clone_Popup on Opportunity (before insert) {
    for (Opportunity o : Trigger.new) {
  	if ( o.isclone() ) {
    o.addError('Warning...blah blah blah');
  }
}
}

 
Hello, I'm working on a visualforce page and I can't seem to get my tables to line up the way I want them to. I've had some success, but am just having trouble finishing it off.

I need it to look like this:
User-added image
But so far I have only managed to make it look like this:
User-added image

Here is the HTML 
<table class="Cx" width="98.7%">
        <tr><td class="tac rPad" colspan="4"><strong>Telco Info</strong></td></tr>
        <tr><td class="tar rPad">Sales Order:</td><td>company name</td></tr>
        <tr><td class="tar rPad">Sales Rep:</td><td>Rebiller Group</td><td>TN:</td><td>1-800-555-5555</td></tr>
        <tr><td class="tar rPad">E-Mail:</td><td>ao@ao.ca</td></tr>
        <tr><td class="tar rPad">Original E-Mail:</td><td>ao@selectcomtelecom.ca</td></tr>
        <tr><td class="tar rPad">Original Fax:</td><td>555-555-5555</td></tr>
    </table>

    <br/>

    <div width="98.7%" class="col-container">
        
    
    <table class="Cx col" >
        <th><strong>Activty</strong></th>
        <tr><td>x</td><td>New</td><td>TF</td></tr>
        <tr><td>Add</td><td>Disc</td></tr>
		<tr><td>Change</td></tr>
        <tr><td>Seasonal Disc</td></tr>        
        <tr><td>Reconnect Date</td></tr>
     </table>

&nbsp;
    
      
    <table class="Cx col" >
		<th><strong>Service Type</strong></th>
        <tr><td>Service</td></tr>
        <tr><td>Cross Border-MCI</td></tr>
        <tr><td>Cross Border-AT&amp;T</td></tr>
        <tr><td>Other</td></tr>
        <tr><td><strong>Mass Calling</strong></td></tr>
        <tr><td>Yes</td><td>x</td><td>No</td></tr>
    </table>
    
    &nbsp;

    <table>
        <tr><td>
        <table width="100%" class="Cx col">

        <tr><td><strong>Dates</strong></td></tr>
        <tr><td>Application Date:</td>
            <td><apex:outputText value="{0,date,yyyy-MM-dd}"><apex:param value="{!Client_Line__c.LASTMODIFIEDDATE}" /></apex:outputText></td>
		</tr>
        <tr><td>Due Date: ??</td><td>what is the merge field?</td></tr>  

        </table>
        &nbsp;
        <table width="100%" class="Cx col">
        <tr><td><strong>Reference of Calls</strong></td></tr>
        <tr><td>Yes</td><td>x</td><td>No</td></tr>
        <tr><td>Refer Calls To</td></tr>
        </table>
            </td>
        </tr>
    </table>
    </div>

And the CSS is
.Cx{
    border: 1px solid #534e43;
}
.tac{
    text-align: center;
}
.tar{
    text-align: right;
}
.tal{
    text-align: left;
}
.rPad{
    padding-right: 10px;
}
.col-container {
  display: table;
  width: 98.7%;
}
.col {
  display: table-cell;
  padding: 16px;
}
Any help would be appreciated!  Been struggling with this for awhile now.
I'm working on a custom classic email template using HTML and when I see the preview and when I test it in my browser, my alignment is good, but when I send a test email, the alignment is off.  

Any suggestions what I can do to resolve this?

Here is what it looks like in preview:
User-added image

Here is the email test:

User-added image
Here is a bit of my code:
<body style="font-family: Montserrat, sans-serif;">
<style>
	.progress{width: 80%; height: auto; margin:0 auto 0 auto; color: #404040; font-size: 14px; }
	.p{font: Montserrat, sans-serif; text-align: left; }
</style>

<table class="progress" cellpadding="2px">
	<tr>
		<td style="vertical-align: bottom; text-align: center;" >
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCE&oid=00DA0000000gd8G&lastMod=1581343779000" alt="orange-circle" height:20 ></td>
		<td style="">
			<p><strong>Site Survey Scheduled</strong></p>
		</td>
	</tr>

	<tr>
		<td style="vertical-align: top; text-align: center;">
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCJ&oid=00DA0000000gd8G&lastMod=1581343802000" alt="orange-line" height="120" ></td>
		<td style="vertical-align: top; font-size: 12px;">
			<p>Friday, February 7</p>
		</td>
	</tr>

	<tr>
		<td style="vertical-align: top; text-align: center;">
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCO&oid=00DA0000000gd8G&lastMod=1581343827000" alt="grey-circles" height="20" ></td>
		<td style="vertical-align: top;">
			<p><strong>Order Received</strong></p>
		</td>
	</tr>

	<tr>
		<td style="vertical-align: top; text-align: center;">
			<img src="https://selectcomtelecom--c.na72.content.force.com/servlet/servlet.ImageServer?id=0151H0000085hCT&oid=00DA0000000gd8G&lastMod=1581343849000" alt="grey-lines" height="20" ></td>
		<td style="vertical-align: top;">
			<p></p>
		</td>
	</tr>

 
I’m having trouble with my test class…not sure what I’m doing wrong, but I’m getting the following errors:
Illegal assignment from Map to List (line 6)
Method does not exist or incorrect signature: void getRecTypeId(String) from the type RecordTypeSelector (line 11)

My test class is for a custom record type selector component on my Asset object for my customer object OrderProject__c.

Any help would be appreciated!!
 
@isTest
public class TestRecordTypeSelector {


static testmethod void testFetchRecordTypes() {
    List<String> value = RecordTypeSelector.fetchRecordTypeValues('Asset');
  }

 static testmethod void testgetRecordTypeId() {
    String recordTypeLabel = 'Avaya';
    ID testId = RecordTypeSelector.getRecTypeId(recordTypeLabel);
    System.assert(testId != null);
  }
}

 
Hello,

I'm a novice at Apex code and am trying to adjust my extension for SavePDF so that it saves as a file as well.  I get an error message related to the line that says:  file.Origin = 'a';

I am indicating the wrong origin or something?  Or do I need to complete the attachment fully before I can add the file?  Any help would be appreciated!

 
public pageReference savePDF(){
    
        Date dateToday = Date.today();
        String sMonth = String.valueof(dateToday.month());
        String sDay = String.valueof(dateToday.day());
        if(sMonth.length()==1){
          sMonth = '0' + sMonth;
        }
        if(sDay.length()==1){
          sDay = '0' + sDay;
        }
        String sToday = String.valueof(dateToday.year())+ '-' + sMonth +  '-' + sDay ;
        
      PageReference pagePdf = new PageReference('/apex/SalesAgreement_PDF');
          pagePdf.getParameters().put('id', idVal);
          Blob pdfPageBlob;
          pdfPageBlob = pagePdf.getContentAsPDF();
                 
          Attachment a = new Attachment();
          a.Body = pdfPageBlob;
          a.ParentID = idVal;
          a.Name = 'Service_Agreement_' + strOppName + '_' + sToday + '.pdf';
          a.Description = 'Service Agreement_' + sToday;
          insert a;

          ContentVersion file = new ContentVersion();
		  file.Title = 'Service_Agreement_' + strOppName + '_' + sToday + '.pdf';
		  file.PathOnClient = 'Service_Agreement_' + Datetime.now().getTime() + '.txt';
		  file.VersionData = Blob.valueOf('Service_Agreement_' + 
		  Datetime.now().getTime() + '.txt');
		  file.Origin = 'a';
		  insert file;         
    
        
        pop_msg='Successfully saved';
        displayPopup = true;  
       
        
        opp.Signature_Date__c = null;
        opp.Signature_Key__c = '';
        opp.Signature_Name__c = '';
        opp.Signature_URL__c = null;
        opp.Signature__c = null;

        
        update opp;
      return new PageReference('/apex/SalesAgreement_HTML?id=' + idVal);
      
        
    }



 
I need to create a popup alert on Account object that is triggered when the related contacts (related list) need to be updated.  So I want to look at a custom date field in Contact "Last_Verified__c" and if it is blank or older than 2 years this should trigger the popup on the Account to recommend updating the contacts.

I can figure out the visualforce page, but I'm still new to Apex (I've only got about 3 triggers so far) and this one feels a little complicated.  Can anyone help get me started on the Apex Class?

Thanks!

Hello friends.

I'm having issue with this trigger in the Opportunity Products. It works fine in the Developer Sandbox, but it doesn't work in the Partial Sandbox or Full Sandbox... so I doubt that it will work in the production. Can you guys help me out? I tried everything...

I have the following trigger:

trigger AutoAddPF00001 on OpportunityLineItem (after insert, after update)
{
    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();

    List<String> lstProductCodes = new List<String>();

    for(OpportunityLineItem optLineItem: Trigger.new)
    {
        if(optLineItem.ProductCode == '00001a')
        {
            lstProductCodes.add(optLineItem.ProductCode);
        }
    }

    if(lstProductCodes.size()>0)
    {
        System.debug('lstProductCodes=' + lstProductCodes);

        //retrieve the values based on Product list
        List<OpportunityLineItem> lstOpptyLineItems = [SELECT OpportunityId, Opportunity.Pricebook2Id, Name, ProductCode , PricebookEntryId, Quantity, UnitPrice
                                                        FROM    OpportunityLineItem
                                                        WHERE ProductCode IN:lstProductCodes];

        //create a map which contains Product Name and OpportunityLineItem
        Map<String, OpportunityLineItem> mapOpptyLineItem = new Map<String, OpportunityLineItem>();
        for(OpportunityLineItem item:lstOpptyLineItems)
        {
            mapOpptyLineItem.put(item.ProductCode, item);
        }


        Id pbkId = lstOpptyLineItems[0].Opportunity.Pricebook2Id;

        //retrieve PriceBookEntry of the Product B, this is most important
        PricebookEntry pbeProduct2 = [SELECT Id, Pricebook2Id, UnitPrice, Name, Product_Fee_Percentage__c 
                                        FROM PricebookEntry
                                        WHERE Name ='Product Fee'
                                        AND Pricebook2Id  IN (SELECT Id FROM PriceBook2 WHERE Id =:pbkId) LIMIT 1];

        //retrieve Product A item from the map.        
        OpportunityLineItem itemProductA = mapOpptyLineItem.get('00001a');
        System.debug('itemProductA= ' + itemProductA);

        if(itemProductA != null)
        {
            if(Trigger.isInsert)
            {
            //now assign Product A items as required, you can retrieve the amount from Product A
            oliList.add(new OpportunityLineItem(
                OpportunityId = itemProductA.OpportunityId,
                PricebookEntryId = pbeProduct2.Id,
                Quantity = itemProductA.Quantity,
                UnitPrice = itemProductA.UnitPrice * pbeProduct2.Product_Fee_Percentage__c * 0.01 )
              );
            System.debug('oliList=' + oliList);
            insert oliList;
        }
        else if (Trigger.isUpdate)
            {
                //if you need to update PriceBookEntry of Product B
                pbeProduct2.UnitPrice = itemProductA.UnitPrice * pbeProduct2.Product_Fee_Percentage__c * 0.01 ;
                update pbeProduct2;

                //if you need to update OpportunityLineItem of Product B
                OpportunityLineItem optLIProductB = [SELECT OpportunityId, Opportunity.Pricebook2Id,
                                                        Name, ProductCode , PricebookEntryId,
                                                        Quantity, UnitPrice
                                                        FROM    OpportunityLineItem
                                                        WHERE ProductCode = '00001b'];

                optLIProductB.Quantity = mapOpptyLineItem.get('00001a').Quantity;
                optLIProductB.UnitPrice = mapOpptyLineItem.get('00001a').UnitPrice * pbeProduct2.Product_Fee_Percentage__c * 0.01 ;

                update optLIProductB;
            }
    }
}
}

I'm getting the following error:
Apex trigger AutoAddPF00001 caused an unexpected exception, contact your administrator: AutoAddPF00001: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.AutoAddPF00001: line 35, column 1

Line 35 is:
PricebookEntry pbeProduct2 = [SELECT Id, Pricebook2Id, UnitPrice, Name, Product_Fee_Percentage__c

I tried the solution given by the article below, but it causes more issues.
https://help.salesforce.com/articleView?id=000159853&type=1

So I used the following code with some help:​
List<PricebookEntry> pbeProduct2=new List<PricebookEntry>();
 pbeProduct2 = [SELECT Id, Pricebook2Id, UnitPrice, Name, Product_Fee_Percentage__c 
                            FROM PricebookEntry
                            WHERE Name ='Product Fee'
                            AND Pricebook2Id  IN (SELECT Id FROM PriceBook2 WHERE Id =:pbkId) LIMIT 1];
System.debug('pbeProduct2 '+pbeProduct2);

I get the following error if I try the solution given in the link above:
Error: Compile Error: Variable does not exist: Id at line 53 column 48

Line 53 is:
PricebookEntryId = pbeProduct2.Id,

  • October 11, 2017
  • Like
  • 0
Hello All,

We have created a lookup filter on a custom object. It works for all other users in a profile as expected , except for one user. The object permission is public read/write and there are no permission sets or field level security preventing user from viewing records. If we remove the lookup filter the same user can see all the records. 
Any idea what is going on and how to fix it? 
Thank you
  • February 27, 2017
  • Like
  • 0
I created a VF page for a custom object and would like to have the column header "Certification Year" sorted by default in decending order.

Is there an easy way to do this without a controller? I'm new to coding and am not familiar with this. Or can someone help me with getting it done?

This is the code I have for the visualforce page:


<apex:page standardController="Account">
   
      You are viewing the {!account.name} account.

      <apex:pageBlock title="ONS's">

      <apex:pageBlockTable value="{!account.ONC_s__r}" var="onc">

         <apex:column value="{!onc.Name}"/>
         <apex:column value="{!onc.Owner.name}"/>
         <apex:column value="{!onc.Certification_Year__c}"  />
         <apex:column value="{!onc.Practice_Setting__c}"/>
         

      </apex:pageBlockTable>

   </apex:pageBlock>

</apex:page>