• manuel.johnson
  • NEWBIE
  • 0 Points
  • Member since 2013

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

I am trying to create a trigger that will update an opportunity field called "Tinderbox_Sites__c" after a child object called "Site__c" is inserted with a list of all the child Site names. I have created the below trigger and helper class method but for some reason, when there are multiple child sites, the string will just overwrite instead of concatenate the site names. For example,

 

Opportunity A has two child Site__c objects:

- Site 1

- Site 2

 

The "Tinderbox_Sites__c" opportunity field will only display

"Site 2<br />"

 

instead of the expected concatenated string of sites

"Site 1<br />Site 2<br />"

 

. Can anyone help me figure out why the string is overwriting instead of concatenating? Thanks!

 

 

trigger SiteTrigger on Site__c (after insert) {
    
  SiteTriggerHelper helper = new SiteTriggerHelper();

  if(Trigger.isAfter && Trigger.isInsert){
    helper.updateTinderboxSites(Trigger.new);
  }
}

 

 

public void updateTinderboxSites(List<Site__c> sites){

  Set<Id> opportunityIds = new Set<Id>();
  for(Site__c s: sites){
    opportunityIds.add(s.Opportunity__c);
  }
  List<Opportunity> opps = new List<Opportunity>([select Id, Tinderbox_Sites__c from Opportunity where Id in : opportunityIds]);
  List<Opportunity> oppsToUpdate = new List<Opportunity>();
  for(Opportunity o: opps){
    String html = '';
    for(Site__c oppSite: sites){
      html += oppSite.Name+'<br />';
    }
    o.Tinderbox_Sites__c = html;
    oppsToUpdate.add(o);
  }
  update oppsToUpdate;
}

 

 

 

I created a visualforce page that displays the opportunity owner's phone number with the standard U.S. formatting "(555) 555-5555". Since the phone number is retrieved from the database unformatted (e.g. "5555555555"), I uploaded the jquery 1.9.1 library as a static resource and added a script to format the number as shown below. It works perfectly, however, when I try to render the page as pdf it no longer displays with the formatting. Is there any way to display it without having to create a controller extension? And if not, what is the simplest controller extension that would format the phone number?

 

<apex:page standardController="Quote" renderAs="pdf">
<head>
<apex:includeScript value="{!$Resource.jquery}"/>
<script>

$(document).ready(function() {
// Attach masks to correct input fields

$(".phone").text(function(i, text) {
text = text.replace(/(\d\d\d)(\d\d\d)(\d\d\d\d)/, "($1) $2-$3");
return text;
});

});

</script>
</head>
<apex:outputText styleClass="phone" value="{!Quote.Opportunity.Owner.Phone}" />
</apex:page>

I created a visualforce page that displays the opportunity owner's phone number with the standard U.S. formatting "(555) 555-5555". Since the phone number is retrieved from the database unformatted (e.g. "5555555555"), I uploaded the jquery 1.9.1 library as a static resource and added a script to format the number as shown below. It works perfectly, however, when I try to render the page as pdf it no longer displays with the formatting. Is there any way to display it without having to create a controller extension? And if not, what is the simplest controller extension that would format the phone number?

 

<apex:page standardController="Quote" renderAs="pdf">
<head>
<apex:includeScript value="{!$Resource.jquery}"/>
<script>

$(document).ready(function() {
// Attach masks to correct input fields

$(".phone").text(function(i, text) {
text = text.replace(/(\d\d\d)(\d\d\d)(\d\d\d\d)/, "($1) $2-$3");
return text;
});

});

</script>
</head>
<apex:outputText styleClass="phone" value="{!Quote.Opportunity.Owner.Phone}" />
</apex:page>