• SFTerr
  • NEWBIE
  • 65 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 18
    Replies
Hi, I was wondering if it's possible to modify or replace with a custom one "export data" button situated on the reports tab, so when clicked it will show a message "you are about to export confidencial info from SF, if you wish to continue click "Yes" or "Cancel" to abort." allowing them to continue or not.

Thanks in advsnce
Hi, I'm struggling with test class to increase test coverage, currently got only 68%, so all suggestions welcome

my trigger:
/* Provide summary of Number of Contacts on Account record
https://success.salesforce.com/answers?id=90630000000h3mNAAQ */ 

trigger ContactSumTrigger on Contact (after delete, after insert, after undelete, 
after update) {

    Contact[] cons;
    if (Trigger.isDelete) 
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId
                                                            from Contact
                                                            where AccountId in :acctIds]);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,Number_of_Contacts__c
                                                                  from Account
                                                                  where Id in :acctIds]);
                                                                 
    for (Account acct : acctsToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) {
            if (con.AccountId == acct.Id)
                conIds.add(con.Id);
        }
        if (acct.Number_of_Contacts__c != conIds.size())
            acct.Number_of_Contacts__c = conIds.size();
    }

    update acctsToUpdate.values();

}

my class:
 
@isTest
public class ContactSumTriggerTest {

    static testmethod void TestContactTrgr() {
    
           Test.startTest();
        // Create account
           Account ac = new Account();
           ac.Name = 'Test Account';
           ac.Mailing_Country__c = 'United Kingdom';
           Insert ac;
           system.debug('Completed Account Creation'); 
		   
		// Update account
          Database.SaveResult sr2 = Database.update(ac, true);
          System.assert(sr2.isSuccess());
          system.debug('Account updated');

           delete ac;
           undelete ac;
		   
        // Create 1st contact
           Contact ct1 = new Contact();
           ct1.FirstName = 'FirstName 1';
           ct1.LastName = 'LastName 1';
           ct1.Email = 'test1@test.com';
           ct1.Mailing_Country__c = 'United Kingdom';
           ct1.Account = ac;
           Insert ct1;  
		   system.debug('Completed Contact Creation'); 
		   
		// Update 1st contact
          Database.SaveResult sr2 = Database.update(ct1, true);
          System.assert(sr2.isSuccess());
          system.debug('Contact updated');
		   
		   delete ct1;
           undelete ct1;
		   
		// Create 2nd contact
		   Contact ct2 = new Contact();
           ct2.FirstName = 'FirstName 2';
           ct2.LastName = 'LastName 2';
           ct2.Email = 'test2@test.com';
           ct2.Mailing_Country__c = 'United Kingdom';
           ct2.Account = ac;
           Insert ct2;
           system.debug('Completed Contact Creation'); 
		   
		// Update 2nd contact
          Database.SaveResult sr2 = Database.update(ct2, true);
          System.assert(sr2.isSuccess());
          system.debug('Contact updated');
           
		   delete ct2;
           undelete ct2;
           
           Test.stopTest();
          
    }    
    
}

thank you in advance
I have a trigger which populates custom opportunioty field (Primary_Contact_Role__c) with the name of the contact selected as primary which works great when new record is being created. How can I modify it, so the name of the contact is changed if user selects different primary contact on the same opportunity?
 
trigger PrimaryContactRole on Opportunity (before update) {

List<OpportunityContactRole> cRoles = new List<OpportunityContactRole>();

cRoles = [SELECT OpportunityId, IsPrimary, Contact.Name FROM OpportunityContactRole WHERE OpportunityId IN :Trigger.newMap.keySet() AND IsPrimary = TRUE];
    for(OpportunityContactRole ocr : cRoles) {
        Trigger.newMap.get(ocr.OpportunityId).Primary_Contact_Role__c = ocr.Contact.Name;
    }
}
Thank you in advance
 
Hi, trying to print one badge page from below code, but for some reason it prints 2nd page which is completely blank.
Any idea what I'm mising here?
<apex:page sidebar="false" showHeader="false" standardStylesheets="false" standardController="Project_Attendance__c">
<script type="text/javascript">
        var __sfdcSessionId = '{!GETSESSIONID()}';
        </script>
        <script src="../../soap/ajax/29.0/connection.js"
              type="text/javascript"></script>
<apex:outputPanel layout="block" styleClass="standardBackground"/>

<style>
@page {
size: 110mm 90mm;
margin: 0px;
padding: 0mm;
}

.divFirstName{
font-weight:bold;
font-family:Arial;
font-size: 13pt;
text-transform:uppercase;
width: 110mm;
text-align:center;
}

.divLastName {
font-weight:bold;
font-family:Arial;
font-size:20pt;
width: 110mm;
text-align:center;
}

.divCompany{
font-weight:bold;
font-family:arial;
font-size:24pt;
width: 110mm;
text-align:center;
max-height:80px;
}

.divType{
font-weight:bold;
font-family:Arial;
font-size:30pt;
width: 110mm;
text-align:center;
max-height:50px;
}

td { text-align:center; }
div { overflow:hidden; }

table { width:110mm; height:90mm; margin:0; padding:0; border-collapse:collapse;  }

body {
font-family:Arial ;
font-size:14px;
}

</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>

                <script type="text/javascript">
                $(document).ready(function() {

                                var originalFontSize = 12;
                                var sectionWidth = $('.divFirstName').width();

                                $('span').each(function(){
                                                var spanWidth = $(this).width();
                                                var newFontSize = (sectionWidth/spanWidth) * originalFontSize;
                                                var newSize = newFontSize/1.2;
                                                if (newFontSize > 50) { newFontSize=50; }
                                                $(this).css({"font-size" : newFontSize, "line-height" : newFontSize/1.2 + "px"});
                                });

                                setupPage();
                });
                </script>

<apex:form >

<table>
  <tr>
    <td>
                <div class="divFirstName"><span><apex:outputText value="{!Project_Attendance__c.First_Name__c}"></apex:outputText></span></div>
    </td>
  </tr>
  <tr>
    <td>
                <div class="divLastName"><apex:outputText value="{!Project_Attendance__c.Last_Name__c}"></apex:outputText></div>
    </td>
  </tr>
  <tr>
    <td>
                <div class="divCompany"><apex:outputText value="{!Project_Attendance__c.Company__c}"></apex:outputText></div>
    </td>
    </tr>
     <tr>
    <td>
                <div class="divType"><apex:outputText value="{!Project_Attendance__c.Badge_Type__c}"></apex:outputText></div>
    </td>
    </tr>
</table>

<script type="text/javascript"> 
window.onload=function(){self.print();} 
</script> 
</apex:form>
</apex:page>

Thank you in advance
Hi, trying to modify below apex trigget to generate contact role name instead of ID
I would appreciate suggestions what I'm doing wrong here
 
trigger PrimaryContactRole on Opportunity (before update) {

   for (Opportunity o : Trigger.new) {

       Integer i = [select count() from OpportunityContactRole where OpportunityId = :o.id and IsPrimary = true];
      
       if(i==1) {
       OpportunityContactRole contactRole =
            [select Contact.Name from OpportunityContactRole where OpportunityId = :o.id and IsPrimary = true];

       o.Primary_Contact_Role__c = contactRole.ContactID;
       } 

      }

   }

thanks
  • April 30, 2015
  • Like
  • 0
Hi, I’ve created custom list button, which when clicked open VF page. That button will be used for viewing existing records only (so user will have to select the record first from the list by checkbox and then clicking new button), but currently it opens up new page, but all fields are blank.
How do I change the apex to display the selected record instead (I've tried different options, e.g. with controller.getSelected, but can't get pass the errors)?

controller:
global with sharing class SalesInvoicePrintReceipt extends SkyEditor2.SkyEditorPageBaseWithSharing {
  
  public c2g__codaInvoice__c record {get{return (c2g__codaInvoice__c)mainRecord;}}
  public with sharing class CanvasException extends Exception {}

  
  

  public SalesInvoicePrintReceipt(ApexPages.StandardController controller) {
    super(controller);


    SObjectField f;

    f = c2g__codaInvoice__c.fields.c2g__Account__c;
    f = c2g__codaInvoice__c.fields.c2g__Opportunity__c;
    f = c2g__codaInvoice__c.fields.Name;
    f = c2g__codaInvoice__c.fields.c2g__InvoiceDate__c;

    List<RecordTypeInfo> recordTypes;
    try {
      mainSObjectType = c2g__codaInvoice__c.SObjectType;
      setPageReferenceFactory(new PageReferenceFactory());
      
      mainQuery = new SkyEditor2.Query('c2g__codaInvoice__c');
      mainQuery.addFieldAsOutput('c2g__Account__c');
      mainQuery.addFieldAsOutput('c2g__Opportunity__c');
      mainQuery.addFieldAsOutput('Name');
      mainQuery.addFieldAsOutput('c2g__InvoiceDate__c');
      mainQuery.addWhere('Id', mainRecord.Id, SkyEditor2.WhereOperator.Eq)
        .limitRecords(1);
      
      
      
      mode = SkyEditor2.LayoutMode.LayoutSalesforce; 
      
      queryMap = new Map<String, SkyEditor2.Query>();
      SkyEditor2.Query query;
      
      
      p_showHeader = true;
      p_sidebar = true;
      init();
      
      if (record.Id == null) {
        
        saveOldValues();
        
      }

      
      
    }  catch (SkyEditor2.Errors.FieldNotFoundException e) {
      fieldNotFound(e);
    } catch (SkyEditor2.Errors.RecordNotFoundException e) {
      recordNotFound(e);
    } catch (SkyEditor2.ExtenderException e) {
      e.setMessagesToPage();
    }
  }
  

  @TestVisible
    private void sObjectNotFound(SkyEditor2.Errors.SObjectNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }
  @TestVisible
    private void fieldNotFound(SkyEditor2.Errors.FieldNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }
  @TestVisible
    private void recordNotFound(SkyEditor2.Errors.RecordNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }

  with sharing class PageReferenceFactory implements SkyEditor2.PageReferenceFactory.Implementation {
    public PageReference newPageReference(String url) {
      return new PageReference(url);
    }
  }
}


Thanks
 
  • April 15, 2015
  • Like
  • 0
Hi, because of upcoming changes to our instance where all our URLs are going to change overnight in august and because photos currently stored in SF as Documents are taking some time to load on our website, I was wondering if it's possible to get this content on a CDN/our own domain of sorts?

Has anyone tried that? Not sure what the best approach would be here or if it's even possible.

Thanks In advance
  • April 10, 2015
  • Like
  • 0
Recently I've added trigger on contact populating Area_Code__c field based on the information added to contact.MailingCountry through CountryRegion__c custom setting. It works well:
trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
    {
        string AreaCode =  .getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;
    }
}

but when I'm trying to replicate the code on lead:
trigger PopulateLeadAreaCode on Lead (before insert, before update) {

    for (Lead newLead : Trigger.new)
    {
        string AreaCode = CountryRegion__c.getInstance(Lead.Country). Area_Code__c;
        lead.Area_Code__c = AreaCode;
    }
}

it does gives me an error: "Error: Compile Error: Variable does not exist: CountryRegion__c at line 5 column 27"

CountThat CountryRegion__c custom setting is the same I've used for contacts, so not sure why the system acan't see it this time? Do I need a new separate custom setting for leads?

Thank you in advance!
  • February 25, 2015
  • Like
  • 0
Hi, I wrote a trigger and a test class, but when testing I get below error: 

System.DmlException: Update failed. First exception on row 0 with id 003M000000Zc1NaIAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateContactAreaCode: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.PopulateContactAreaCode: line 5, column 1: []

Trigger:
trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
    {
        string AreaCode = CountryRegion__c.getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;
    }
}

test class:
@isTest
public class PopulateContactAreaCodeTest
{
    static testMethod void attTriggerTest1()
    {
        test.startTest();
        Account acct = new Account(id = '001M000000iLhTL', Name = 'Test Account ', Mailing_Country__c = 'Afghanistan');
        update acct;      
        Contact con = new Contact(id = '003M000000Zc1Na', LastName = 'Test Contact', Account = acct, Email = 'test@test.com', Mailing_Country__c = 'Afghanistan', MailingCountry = 'Afghanistan');
        update con;
        delete con;
        test.stopTest();
    }
}

any idea what I added wrong?

thank you in advance
  • February 24, 2015
  • Like
  • 2
I'm trying to add additional page to customer badge if Catering__c checkbox is ticked on Project_Attendance__c object.

Sections I've adddeed:

<style>
@page {
size: 102mm 76mm;
margin: 0mm;
padding: 0mm;
}

#Catering{text-align: center; font-size:14pt; }
</style>

PLUS
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>

                <script type="text/javascript">
                //window.onload = setupPage();

                function setupPage() {
                                
                                var c = new sforce.SObject("Project_Attendance__c");
                                c.id ="{!Project_Attendance__c.id}";
                                c.Catering__c = true;
                                $(".Table1").css("background" , "White");
                                
                                "{!Project_Attendance__c.Catering__c}" = true) 
                                    { 
                                        $("#Catering").css("page-break-after", "always");
                                        var msg="";
                                        if ("{!Project_Attendance__c.Catering__c}" = true) { msg="You are entitled to premium catering. Please collect your voucher from registration desk.";}
                                        $("#Catering").html("<p>" + msg + "</p>");
                                    }
                                
                                
                }
                </script>



                <script type="text/javascript">
                $(document).ready(function() {

                                var originalFontSize = 12;
                                var sectionWidth = $('.divFirstName').width();

                                $('span').each(function(){
                                                var spanWidth = $(this).width();
                                                var newFontSize = (sectionWidth/spanWidth) * originalFontSize;
                                                var newSize = newFontSize/1.2;
                                                if (newFontSize > 50) { newFontSize=50; }
                                                $(this).css({"font-size" : newFontSize, "line-height" : newFontSize/1.2 + "px"});
                                });

                                setupPage();
                });
                </script>

but additional page is not printing at all. Any ideas where is the error?

Thank you in advance
  • February 23, 2015
  • Like
  • 0
I'm new to APEX and I would be grateful if someone could help me with below trigger.
when there is new attachment added to custom Project_Edition__c object I need Venue_Contract_Attached__c to be ticked automatically (and unticked when attachment is deleted)
 
trigger CountAttachments on Project_Edition__c (before insert, before delete)
{
if(trigger.isinsert){
List<Project_Edition__c> co = [select id from Project_Edition__c where id =: Trigger.New[0].ParentId];
If(co.size()>0)         
{             
co[0].Venue_Contract_Attached__c = True;             
update co;         
}
}


if(trigger.isdelete){

List<Project_Edition__c> co = [select id from Project_Edition__c where id =: Trigger.old[0].ParentId];         
If(co.size()>0)         
{             
co[0].Venue_Contract_Attached__c = false;             
update co;         
}
}
}

I'm getting all sorts of errors, last one being "Error: Compile Error: Invalid field ParentId for SObject Project_Edition__c at line 4 column 93"

 
  • February 17, 2015
  • Like
  • 0
Hi, trying to add a condition to our VF page for printing badges.
When an Account name exceed 22 characters, sections are being pushed down to the next page, and what I would like it to do, is to hide image (.divLogo img) if the Account name exceed those 22 characters
<style>
@page {
size: 102mm 76mm;
margin: 0mm;
padding: 0mm;
}

body {
font-family:Arial ;
font-size:14px;
}

.divFirstName{
font-weight:bold;
font-family:Arial;
font-size: 20pt;
text-transform:uppercase;
width: 102mm;
text-align:center;
padding:10px 0px 5px 0px;
}

.divLastName {
font-weight:bold;
font-family:Arial;
font-size:15pt;
width: 102mm;
text-align:center;
padding:0px 0px 5px 0px;
}

.divCompany{ 
font-weight:bold;
font-family:arial;
font-size:20pt;
text-transform:uppercase;
width: 102mm;
text-align:center;
padding:0px 0px 0px 0px;
}

.divLogo img { 
margin:0; padding:5;
display: block;
margin-left: auto;
margin-right: auto; 
}



div { overflow:hidden; }

table { width:100mm; height:70mm; margin:0; padding:0; border-collapse:collapse;  }

.Table1 { page-break-after:always; background:Red; }



<apex:form >
<div id="Meetings"></div> 
<table class="Table1">
  <tr>
    <td>
                <div class="divFirstName"><span><apex:outputText value="{!Attendance__c.First_Name__c}"></apex:outputText></span></div>
    </td>
  </tr>
  <tr>
    <td>
                <div class="divLastName"><apex:outputText value="{!Attendance__c.Last_Name__c}"></apex:outputText></div>
    </td>
  </tr>
  <tr>
    <td>
               <div class="divCompany"><apex:outputText value="{!Attendance__c.Company__c}"></apex:outputText></div>
    </td>
  </tr>
  <tr>
    <td>            
               <div class="divLogo"><apex:image value="{!Attendance__c.Badge_Logo__c}"></apex:image></div>
    </td>
    </tr>
  </table>

Thank you in advance
 
  • January 23, 2015
  • Like
  • 0
Hi, wonder if anyone will be able to help
When viewing PDF invoice from FF page I get below table
User-added image
But when emailing customer with the same PDF invoice attached I get below table
User-added image
Same page is responsible for that PDF, so not sure what I need to do to always include that “SGD” currency code in the invoice total.
Page detail:

<!-- Summary Values -->
                    <td class="alignTop noPadding">
                        <table class="boxed boxedNoTop boxedNoBottom">
                            <tr>
                                <th class="nobg noLines textAlignRight">{!lblInvoiceNetTotal}</th>
                                <td class="textAlignRight widthMedium boxedNoTop" style="width:100px">
                                    <apex:outputText value="{0,number,#,###,###,###,###,###.00}">
                                        {!invoiceCurrencySymbol}<apex:param value="{!salesInvoice.c2g__NetTotal__c}"/>
                                    </apex:outputText>
                                </td>
                            </tr>
                            <tr>
                                <th class="nobg noLines textAlignRight">{!lblInvoiceTaxTotal}</th>
                                <td class="textAlignRight widthMedium">
                                    <apex:outputText value="{0,number,#,###,###,###,###,##0.00}">
                                        {!invoiceCurrencySymbol}<apex:param value="{!salesInvoice.c2g__TaxTotal__c}"/>
                                    </apex:outputText>
                                </td>
                            </tr>
                            <tr>
                                <th class="nobg noLines textAlignRight">{!lblInvoiceTotal}</th>
                                <td class="textAlignRight widthMedium">
                                    <apex:outputText value="{0,number,#,###,###,###,###,###.00}">
                                        {!salesInvoice.c2g__InvoiceCurrency__r.Name}  <apex:param value="{!salesInvoice.c2g__InvoiceTotal__c}"/>
                                    </apex:outputText>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>


Thanks in advance!
 
  • December 19, 2014
  • Like
  • 0
We are looking into building our own customer portal, where our top customers (already provided with login details) will be able to select one of the 2 following options:
- One, where they will update their own details and also see the number of their free passes available to them for the specific Campaign
- Second one, where they will be able to add their colleagues (as many as the have free passes available) and those records would match to our existing Contacts/Accounts + new Opportunity (or completely new records will get created if they won’t exist in SFDC already). They should also be able to modify those records if something changes (attending people, or their details).

I’m new to development, so not sure where will be best to start. Shall I be looking into Sites/Flows or Sites/VF/APEX?

Thank you in advance
 
  • December 05, 2014
  • Like
  • 0
Hi, I’m having problem to make my Flow work, when I try the link in the browser I get below error:

“An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.”

Lookup:

lookup

Decision:
Decision

Record update:
Record update


All variables Input/Output type are set to “Input and Output” (except SF ID which is set to Output only) and users have an access to all listed fields in the flow.

Related VF page:
Related VF page


And related Site is set and active.
Detailed error message I got:
Encountered unhandled fault when running process Onsite_Registration/301D0000000L4Bz exception by user/organization: 00DD0000000CWOe/{4}

; nested exception is:
common.exception.ApiQueryException: sObject type 'Project_Attendance__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
(There was a problem executing your command.) > RETRIEVE

caused by element : FlowRecordLookup.Confirm_Registration

caused by: ; nested exception is:
common.exception.ApiQueryException: sObject type 'Project_Attendance__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
(There was a problem executing your command.) > RETRIEVE

Salesforce Error ID: 191450639-491968 (-1473334608)

But 'Project_Attendance__c' already include '__c'


Thank you in advance

Iga




  • October 16, 2014
  • Like
  • 0

Hi, 

 

On our webform we are capturing a lot of data that we want to try and make use off in Salesforce. The forms are comming from our marketing system (Eloqua). 

 

An example of what we get: 

 

a0TD0000008NSnbMAG|To purchase products or services^\a0TD0000008NSmnMAG|Fixed Stock^\a0TD0000008NSnCMAW|USD $0-5m^\a0TD0000008NSnHMAW|Consultants ^\a0TD0000008NSnMMAW|Not applicable^

 

the record ID is the “question” – held on a custom object of us called Project Profiling

then there is a pipe

then the answers (either single or multi select)

^ separates the multi select answers

^\ separates the next question

 

Basically I want to be able to see on a project attendance:

 

Q1: Question (text)  - answer/s

Q2: Question (text) – answer/s

Etc...

 

Any Ideas on if this can be achieved? 

 

Thanks,

Michael 

 

 

 

  • November 06, 2013
  • Like
  • 0

Hi, 

 

I have a custom object called "Project_Attendance__c"

 

On this record I have a button which opens up a custom visualforce page and the same time I want a tickbox to be ticked. 

 

To tick this I am using a JavaScript code

 

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Project_Attendance__c"); 
c.id ="{!Project_Attendance__c.ID}"; 
c.Attended__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

 

 

I am then referencing this in the visualforce page

 

<apex:includeScript value="{!$Resource.tickattendeed_js}"/>

 But it does not work, the visualforce page opens up fine but it does not tick my checkbox. 

 

Any ideas on why it is not working?

 

Thanks,

Michael

 

 

 

Hi, 

 

I am using a URL button to copy information from one object to another. However when I try and write the currency field I get an error: Invalid Currency. I did some research on this and it seems to be caused by my organisation having turned on multi-currency. I have also found some other posts then I have to write the CurrencyISO field along with it but I have tried this and I still get the error. 

 

I think the solution is to remove the currency code when the information is being written across. So remove the first 3 letters such as GBP, USD etc. Or just be able to just write the number without any currency information attachted to it. 

 

Has anyone got any ideas?

 

Thanks,

Michael

  • November 27, 2012
  • Like
  • 0

Hi, 

 

We have a custom object called "Contact Profiles" which writes information back to the campaign member object. So for every campaign member record we have we also have 1 contact profile record.

 

However the problem is that when we update one of our contact profile records this trigger and class should write the same infromation back to the matching campaign member record however instead updates all the campaign members of a related camapign with the same information 

 

Here is the class that writes the information back. 

 

*/
public with sharing class ContactProfileServices {
        
    public static boolean isRunning = false;
    
    public static void updateValuesInCampaignMembers(Map<Id,Contact_Profiles__c> oldContactProfiles, Map<Id,Contact_Profiles__c> newContactProfiles){
        
        final List<CampaignMember> campaingMemberList = new List<CampaignMember>();
        final List<CampaignMember> campaignMemberOnEachCampaign = new List<CampaignMember>();       
        final Set<ID> campaignIDSet = new Set<ID>();
        
        final map<Id,Contact_Profiles__c> campaignIdToContactProfiles = new map<Id,Contact_Profiles__c>();      
        
        //When a new Contact Profile is created old Contact Profile would be null.
        if(oldContactProfiles == null)
            return;
        
        final List<Contact_Profiles__c> changedContactProfiles = checkForChangedFields(oldContactProfiles, newContactProfiles);
        if(changedContactProfiles.isEmpty())
            return;
        
        for(Contact_Profiles__c currentContact : changedContactProfiles){           
            
            campaignIDSet.add(currentContact.campaign__c);
            campaignIdToContactProfiles.put(currentContact.Campaign__c,currentContact);     
        }
        
        campaignMemberOnEachCampaign.addAll([Select Id,
                                        campaignId,
                                        Profile__c,
                                        Source2__c,
                                        Status 
                                        from CampaignMember 
                                        where campaignId IN :CampaignIDSet]);
                                        
        
            
            for(CampaignMember currentCampMem : CampaignMemberOnEachCampaign){
                
                if(campaignIdToContactProfiles.containsKey(currentCampMem.campaignId)){
                
                    currentCampMem.Profile__c = campaignIdToContactProfiles.get(currentCampMem.campaignId).Profile__c;
                    currentCampMem.Source2__c =campaignIdToContactProfiles.get(currentCampMem.campaignId).Source2__c;
                    currentCampMem.status  = campaignIdToContactProfiles.get(currentCampMem.campaignId).Campaign_Member_Status__c;
                                        
                    campaingMemberList.add(currentCampMem);
                    
                    system.debug('***'+campaingMemberList);
                
                }
            }   
            
            
        isRunning =  true;                                                                      
        updateCampaigmMembers(campaingMemberList);
        isRunning = false;
    }
    
    private static void updateCampaigmMembers(final List<CampaignMember> campaingMemberList){
        update campaingMemberList;      
    }
    
    private static list<Contact_Profiles__c> checkForChangedFields(final Map<Id,Contact_Profiles__c> oldContactProfiles, final Map<Id,Contact_Profiles__c> newContactProfiles){
        
        final list<Contact_Profiles__c> changedContactProfiles = new list<Contact_Profiles__c>();
        for(Contact_Profiles__c newContactProfile :newContactProfiles.values()) {
            Contact_Profiles__c oldContactProfile = oldContactProfiles.get(newContactProfile.Id);
            if(oldContactProfile.Profile__c != newContactProfile.Profile__c || 
               oldContactProfile.Source2__c != newContactProfile.Source2__c ||
               oldContactProfile.Campaign_Member_Status__c != newContactProfile.Campaign_Member_Status__c){
                changedContactProfiles.add(newContactProfile);
            }
        }
        
        return changedContactProfiles;
    }
    
    //kkrupal: moved this from opportunityservices. this belongs here
    public static  Map<Id, Contact_Profiles__c> getContactOnContactProfile(final set<Id> contactProfileIds){
        return new Map<Id,Contact_Profiles__c>([SELECT Id, Contact__c FROM Contact_Profiles__c WHERE Id IN :contactProfileIds]);
    }   
    
}

 The fields we are updating that need to write back are Profile, Source, List and Campaign Member Status. 

 

The person who created this code no longer works for us and I am not an advanced coder but any help you could provide will be much apprechiated. 

 

Thanks,

Michael

  • August 09, 2012
  • Like
  • 0
Hi, I wrote a trigger and a test class, but when testing I get below error: 

System.DmlException: Update failed. First exception on row 0 with id 003M000000Zc1NaIAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateContactAreaCode: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.PopulateContactAreaCode: line 5, column 1: []

Trigger:
trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
    {
        string AreaCode = CountryRegion__c.getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;
    }
}

test class:
@isTest
public class PopulateContactAreaCodeTest
{
    static testMethod void attTriggerTest1()
    {
        test.startTest();
        Account acct = new Account(id = '001M000000iLhTL', Name = 'Test Account ', Mailing_Country__c = 'Afghanistan');
        update acct;      
        Contact con = new Contact(id = '003M000000Zc1Na', LastName = 'Test Contact', Account = acct, Email = 'test@test.com', Mailing_Country__c = 'Afghanistan', MailingCountry = 'Afghanistan');
        update con;
        delete con;
        test.stopTest();
    }
}

any idea what I added wrong?

thank you in advance
  • February 24, 2015
  • Like
  • 2
Hi, I was wondering if it's possible to modify or replace with a custom one "export data" button situated on the reports tab, so when clicked it will show a message "you are about to export confidencial info from SF, if you wish to continue click "Yes" or "Cancel" to abort." allowing them to continue or not.

Thanks in advsnce
Hi, I'm struggling with test class to increase test coverage, currently got only 68%, so all suggestions welcome

my trigger:
/* Provide summary of Number of Contacts on Account record
https://success.salesforce.com/answers?id=90630000000h3mNAAQ */ 

trigger ContactSumTrigger on Contact (after delete, after insert, after undelete, 
after update) {

    Contact[] cons;
    if (Trigger.isDelete) 
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId
                                                            from Contact
                                                            where AccountId in :acctIds]);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,Number_of_Contacts__c
                                                                  from Account
                                                                  where Id in :acctIds]);
                                                                 
    for (Account acct : acctsToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) {
            if (con.AccountId == acct.Id)
                conIds.add(con.Id);
        }
        if (acct.Number_of_Contacts__c != conIds.size())
            acct.Number_of_Contacts__c = conIds.size();
    }

    update acctsToUpdate.values();

}

my class:
 
@isTest
public class ContactSumTriggerTest {

    static testmethod void TestContactTrgr() {
    
           Test.startTest();
        // Create account
           Account ac = new Account();
           ac.Name = 'Test Account';
           ac.Mailing_Country__c = 'United Kingdom';
           Insert ac;
           system.debug('Completed Account Creation'); 
		   
		// Update account
          Database.SaveResult sr2 = Database.update(ac, true);
          System.assert(sr2.isSuccess());
          system.debug('Account updated');

           delete ac;
           undelete ac;
		   
        // Create 1st contact
           Contact ct1 = new Contact();
           ct1.FirstName = 'FirstName 1';
           ct1.LastName = 'LastName 1';
           ct1.Email = 'test1@test.com';
           ct1.Mailing_Country__c = 'United Kingdom';
           ct1.Account = ac;
           Insert ct1;  
		   system.debug('Completed Contact Creation'); 
		   
		// Update 1st contact
          Database.SaveResult sr2 = Database.update(ct1, true);
          System.assert(sr2.isSuccess());
          system.debug('Contact updated');
		   
		   delete ct1;
           undelete ct1;
		   
		// Create 2nd contact
		   Contact ct2 = new Contact();
           ct2.FirstName = 'FirstName 2';
           ct2.LastName = 'LastName 2';
           ct2.Email = 'test2@test.com';
           ct2.Mailing_Country__c = 'United Kingdom';
           ct2.Account = ac;
           Insert ct2;
           system.debug('Completed Contact Creation'); 
		   
		// Update 2nd contact
          Database.SaveResult sr2 = Database.update(ct2, true);
          System.assert(sr2.isSuccess());
          system.debug('Contact updated');
           
		   delete ct2;
           undelete ct2;
           
           Test.stopTest();
          
    }    
    
}

thank you in advance
I have a trigger which populates custom opportunioty field (Primary_Contact_Role__c) with the name of the contact selected as primary which works great when new record is being created. How can I modify it, so the name of the contact is changed if user selects different primary contact on the same opportunity?
 
trigger PrimaryContactRole on Opportunity (before update) {

List<OpportunityContactRole> cRoles = new List<OpportunityContactRole>();

cRoles = [SELECT OpportunityId, IsPrimary, Contact.Name FROM OpportunityContactRole WHERE OpportunityId IN :Trigger.newMap.keySet() AND IsPrimary = TRUE];
    for(OpportunityContactRole ocr : cRoles) {
        Trigger.newMap.get(ocr.OpportunityId).Primary_Contact_Role__c = ocr.Contact.Name;
    }
}
Thank you in advance
 
Hi, trying to modify below apex trigget to generate contact role name instead of ID
I would appreciate suggestions what I'm doing wrong here
 
trigger PrimaryContactRole on Opportunity (before update) {

   for (Opportunity o : Trigger.new) {

       Integer i = [select count() from OpportunityContactRole where OpportunityId = :o.id and IsPrimary = true];
      
       if(i==1) {
       OpportunityContactRole contactRole =
            [select Contact.Name from OpportunityContactRole where OpportunityId = :o.id and IsPrimary = true];

       o.Primary_Contact_Role__c = contactRole.ContactID;
       } 

      }

   }

thanks
  • April 30, 2015
  • Like
  • 0
Hi, I’ve created custom list button, which when clicked open VF page. That button will be used for viewing existing records only (so user will have to select the record first from the list by checkbox and then clicking new button), but currently it opens up new page, but all fields are blank.
How do I change the apex to display the selected record instead (I've tried different options, e.g. with controller.getSelected, but can't get pass the errors)?

controller:
global with sharing class SalesInvoicePrintReceipt extends SkyEditor2.SkyEditorPageBaseWithSharing {
  
  public c2g__codaInvoice__c record {get{return (c2g__codaInvoice__c)mainRecord;}}
  public with sharing class CanvasException extends Exception {}

  
  

  public SalesInvoicePrintReceipt(ApexPages.StandardController controller) {
    super(controller);


    SObjectField f;

    f = c2g__codaInvoice__c.fields.c2g__Account__c;
    f = c2g__codaInvoice__c.fields.c2g__Opportunity__c;
    f = c2g__codaInvoice__c.fields.Name;
    f = c2g__codaInvoice__c.fields.c2g__InvoiceDate__c;

    List<RecordTypeInfo> recordTypes;
    try {
      mainSObjectType = c2g__codaInvoice__c.SObjectType;
      setPageReferenceFactory(new PageReferenceFactory());
      
      mainQuery = new SkyEditor2.Query('c2g__codaInvoice__c');
      mainQuery.addFieldAsOutput('c2g__Account__c');
      mainQuery.addFieldAsOutput('c2g__Opportunity__c');
      mainQuery.addFieldAsOutput('Name');
      mainQuery.addFieldAsOutput('c2g__InvoiceDate__c');
      mainQuery.addWhere('Id', mainRecord.Id, SkyEditor2.WhereOperator.Eq)
        .limitRecords(1);
      
      
      
      mode = SkyEditor2.LayoutMode.LayoutSalesforce; 
      
      queryMap = new Map<String, SkyEditor2.Query>();
      SkyEditor2.Query query;
      
      
      p_showHeader = true;
      p_sidebar = true;
      init();
      
      if (record.Id == null) {
        
        saveOldValues();
        
      }

      
      
    }  catch (SkyEditor2.Errors.FieldNotFoundException e) {
      fieldNotFound(e);
    } catch (SkyEditor2.Errors.RecordNotFoundException e) {
      recordNotFound(e);
    } catch (SkyEditor2.ExtenderException e) {
      e.setMessagesToPage();
    }
  }
  

  @TestVisible
    private void sObjectNotFound(SkyEditor2.Errors.SObjectNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }
  @TestVisible
    private void fieldNotFound(SkyEditor2.Errors.FieldNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }
  @TestVisible
    private void recordNotFound(SkyEditor2.Errors.RecordNotFoundException e) {
    SkyEditor2.Messages.addErrorMessage(e.getMessage());
    hidePageBody = true;
  }

  with sharing class PageReferenceFactory implements SkyEditor2.PageReferenceFactory.Implementation {
    public PageReference newPageReference(String url) {
      return new PageReference(url);
    }
  }
}


Thanks
 
  • April 15, 2015
  • Like
  • 0
Recently I've added trigger on contact populating Area_Code__c field based on the information added to contact.MailingCountry through CountryRegion__c custom setting. It works well:
trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
    {
        string AreaCode =  .getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;
    }
}

but when I'm trying to replicate the code on lead:
trigger PopulateLeadAreaCode on Lead (before insert, before update) {

    for (Lead newLead : Trigger.new)
    {
        string AreaCode = CountryRegion__c.getInstance(Lead.Country). Area_Code__c;
        lead.Area_Code__c = AreaCode;
    }
}

it does gives me an error: "Error: Compile Error: Variable does not exist: CountryRegion__c at line 5 column 27"

CountThat CountryRegion__c custom setting is the same I've used for contacts, so not sure why the system acan't see it this time? Do I need a new separate custom setting for leads?

Thank you in advance!
  • February 25, 2015
  • Like
  • 0
Hi, I wrote a trigger and a test class, but when testing I get below error: 

System.DmlException: Update failed. First exception on row 0 with id 003M000000Zc1NaIAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateContactAreaCode: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.PopulateContactAreaCode: line 5, column 1: []

Trigger:
trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
    {
        string AreaCode = CountryRegion__c.getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;
    }
}

test class:
@isTest
public class PopulateContactAreaCodeTest
{
    static testMethod void attTriggerTest1()
    {
        test.startTest();
        Account acct = new Account(id = '001M000000iLhTL', Name = 'Test Account ', Mailing_Country__c = 'Afghanistan');
        update acct;      
        Contact con = new Contact(id = '003M000000Zc1Na', LastName = 'Test Contact', Account = acct, Email = 'test@test.com', Mailing_Country__c = 'Afghanistan', MailingCountry = 'Afghanistan');
        update con;
        delete con;
        test.stopTest();
    }
}

any idea what I added wrong?

thank you in advance
  • February 24, 2015
  • Like
  • 2
I'm new to APEX and I would be grateful if someone could help me with below trigger.
when there is new attachment added to custom Project_Edition__c object I need Venue_Contract_Attached__c to be ticked automatically (and unticked when attachment is deleted)
 
trigger CountAttachments on Project_Edition__c (before insert, before delete)
{
if(trigger.isinsert){
List<Project_Edition__c> co = [select id from Project_Edition__c where id =: Trigger.New[0].ParentId];
If(co.size()>0)         
{             
co[0].Venue_Contract_Attached__c = True;             
update co;         
}
}


if(trigger.isdelete){

List<Project_Edition__c> co = [select id from Project_Edition__c where id =: Trigger.old[0].ParentId];         
If(co.size()>0)         
{             
co[0].Venue_Contract_Attached__c = false;             
update co;         
}
}
}

I'm getting all sorts of errors, last one being "Error: Compile Error: Invalid field ParentId for SObject Project_Edition__c at line 4 column 93"

 
  • February 17, 2015
  • Like
  • 0
Hi, wonder if anyone will be able to help
When viewing PDF invoice from FF page I get below table
User-added image
But when emailing customer with the same PDF invoice attached I get below table
User-added image
Same page is responsible for that PDF, so not sure what I need to do to always include that “SGD” currency code in the invoice total.
Page detail:

<!-- Summary Values -->
                    <td class="alignTop noPadding">
                        <table class="boxed boxedNoTop boxedNoBottom">
                            <tr>
                                <th class="nobg noLines textAlignRight">{!lblInvoiceNetTotal}</th>
                                <td class="textAlignRight widthMedium boxedNoTop" style="width:100px">
                                    <apex:outputText value="{0,number,#,###,###,###,###,###.00}">
                                        {!invoiceCurrencySymbol}<apex:param value="{!salesInvoice.c2g__NetTotal__c}"/>
                                    </apex:outputText>
                                </td>
                            </tr>
                            <tr>
                                <th class="nobg noLines textAlignRight">{!lblInvoiceTaxTotal}</th>
                                <td class="textAlignRight widthMedium">
                                    <apex:outputText value="{0,number,#,###,###,###,###,##0.00}">
                                        {!invoiceCurrencySymbol}<apex:param value="{!salesInvoice.c2g__TaxTotal__c}"/>
                                    </apex:outputText>
                                </td>
                            </tr>
                            <tr>
                                <th class="nobg noLines textAlignRight">{!lblInvoiceTotal}</th>
                                <td class="textAlignRight widthMedium">
                                    <apex:outputText value="{0,number,#,###,###,###,###,###.00}">
                                        {!salesInvoice.c2g__InvoiceCurrency__r.Name}  <apex:param value="{!salesInvoice.c2g__InvoiceTotal__c}"/>
                                    </apex:outputText>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>


Thanks in advance!
 
  • December 19, 2014
  • Like
  • 0
We are looking into building our own customer portal, where our top customers (already provided with login details) will be able to select one of the 2 following options:
- One, where they will update their own details and also see the number of their free passes available to them for the specific Campaign
- Second one, where they will be able to add their colleagues (as many as the have free passes available) and those records would match to our existing Contacts/Accounts + new Opportunity (or completely new records will get created if they won’t exist in SFDC already). They should also be able to modify those records if something changes (attending people, or their details).

I’m new to development, so not sure where will be best to start. Shall I be looking into Sites/Flows or Sites/VF/APEX?

Thank you in advance
 
  • December 05, 2014
  • Like
  • 0
Hi, I’m having problem to make my Flow work, when I try the link in the browser I get below error:

“An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.”

Lookup:

lookup

Decision:
Decision

Record update:
Record update


All variables Input/Output type are set to “Input and Output” (except SF ID which is set to Output only) and users have an access to all listed fields in the flow.

Related VF page:
Related VF page


And related Site is set and active.
Detailed error message I got:
Encountered unhandled fault when running process Onsite_Registration/301D0000000L4Bz exception by user/organization: 00DD0000000CWOe/{4}

; nested exception is:
common.exception.ApiQueryException: sObject type 'Project_Attendance__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
(There was a problem executing your command.) > RETRIEVE

caused by element : FlowRecordLookup.Confirm_Registration

caused by: ; nested exception is:
common.exception.ApiQueryException: sObject type 'Project_Attendance__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
(There was a problem executing your command.) > RETRIEVE

Salesforce Error ID: 191450639-491968 (-1473334608)

But 'Project_Attendance__c' already include '__c'


Thank you in advance

Iga




  • October 16, 2014
  • Like
  • 0

Hi, 

 

I have a custom object called "Project_Attendance__c"

 

On this record I have a button which opens up a custom visualforce page and the same time I want a tickbox to be ticked. 

 

To tick this I am using a JavaScript code

 

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Project_Attendance__c"); 
c.id ="{!Project_Attendance__c.ID}"; 
c.Attended__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();

 

 

I am then referencing this in the visualforce page

 

<apex:includeScript value="{!$Resource.tickattendeed_js}"/>

 But it does not work, the visualforce page opens up fine but it does not tick my checkbox. 

 

Any ideas on why it is not working?

 

Thanks,

Michael

 

 

 

Hi, 

 

I am using a URL button to copy information from one object to another. However when I try and write the currency field I get an error: Invalid Currency. I did some research on this and it seems to be caused by my organisation having turned on multi-currency. I have also found some other posts then I have to write the CurrencyISO field along with it but I have tried this and I still get the error. 

 

I think the solution is to remove the currency code when the information is being written across. So remove the first 3 letters such as GBP, USD etc. Or just be able to just write the number without any currency information attachted to it. 

 

Has anyone got any ideas?

 

Thanks,

Michael

  • November 27, 2012
  • Like
  • 0