• Complete novice
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 15
    Replies
Hi, can anyone help me combine these two formulas on a date field please?

IF the Portfolio is Interfaces and the Status is Agreed and the EA Action is one of 3, then the date should be Expected Submission Date -28, +14 or +42.
PLUS
IF the Portfolio is Interfaces and the Status is Invited and the EA Action is First Invitation Chaser, then the date should be Invite email sent + 28 days

I have them both working on separate fields, but can't get them into one formula.

Formula 1:

IF( AND( Journal_for_Article_use__r.Portfolio__c = "Interfaces",
ISPICKVAL( Status__c , "AGR - Agreed to submit")
),
CASE( TEXT( EA_Action__c ),
"Submission Reminder", (Expected_Submission_Date__c - 28),
"First Submission Chaser", (Expected_Submission_Date__c + 14),
"Second Submission Chaser", (Expected_Submission_Date__c + 42),
Null
),
Null
)

Formula 2:

IF( AND(
Journal_for_Article_use__r.Portfolio__c = "Interfaces",
ISPICKVAL( Status__c , "INV - Invited")
),
CASE( TEXT( EA_Action__c ),
"First Invitation Chaser", (Invite_email_sent__c +28),
Null),
Null)
Hi, I am completely new to coding and am trying to set up a validation rule on a web to case form.  I have date fields (option 1 date 1, option 1 date 2, option 2 date 1, option 2 date 2) and I want a validation rule that will prevent Date 2 being earlier than Date 1.

I have found some example code online and have tried it on my web form but it hasn't worked.

This is what I have tried:

User-added image

It still allows any date to be added and the case is created in Salesforce.

Can anyone explain in really simple terms what I have done wrong or what I could try please?

Many thanks.
Hi, I'm getting the same error on all the code I try for  the Trailhead Challenge 'Create a unit test for a simple Apex Class'.

The error I get is: Method does not exist or incorrect signature: void CheckDates(Date, Date) from the type VerifyDate

I have tried the following:

@isTest
private class TestVerifyDate {
    
    static testMethod void TestVerifyDates() {
        VerifyDate.CheckDates(system.today(),system.today().addDays(10));
        
        VerifyDate.CheckDates(system.today(),system.today().addDays(78));
       
    }

}


Also:

@isTest
public class TestVerifyDate {
    @isTest static void testVerifyDate(){
        date date1=VerifyDate.CheckDates(system.today(),system.today().addDays(10));
        System.assertEquals(system.today().addDays(10),date1);
        
        date date2=VerifyDate.CheckDates(system.today(),system.today().addDays(78));
        System.assertEquals(system.today(),date2);
    }
}


Also:

@isTest
private class TestVerifyDate{
    @isTest static void testDt1GtrDt2(){
        Date d2 = system.today();
        Date d1 = d2.addDays(10);
        
        Date dt = VerifyDate.CheckDates(d1, d2);
        Date testDt = Date.newInstance(2017, 7, 31);
        System.assertEquals(dt, testDt);
    }
    
    @isTest static void testDt2Within30dayOfDt1(){
        Date d1 = system.today();
        Date d2 = d1.addDays(10);
        
        Date dt = VerifyDate.CheckDates(d1, d2);
        System.assertEquals(dt, d2);
    }
}


This is the code for the Class itself:

public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
//check for date2 being in the past
if( date2 < date1) { return false; }
//check that date2 is within (>=) 30 days of date1
Date date30Days = date1.addDays(30); //create a date 30 days away from date1
if( date2 >= date30Days ) { return false; }
else { return true; }
}
//method to return the end of the month of a given date
private static Date SetEndOfMonthDate(Date date1) {
Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
return lastDay;
}
}

Can anyone point me to what I am doing wrong please?

Thanks!




 
I've just about got my head around amending pre-written VF email templates but now find I need to write a custom controller and component, which means I am seriously out of my depth.

This is what I am trying to achieve:

An email to be sent from an opportunity.  It is sent to the primary opportunity contact and details the opportunity product, plus some fields from the Account record.  I can do this bit.  However I have also been asked to include specific contacts from the Account related contacts list.  

I understand this needs a custom controller and component but I don't understand how to build these.

Can anyone help me please? You would be helping me out of a massive hole!

This is the code I have so far which retuns the opportunity propduct and the Account record fields:

messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
 replyTo="xxx@xxx.org" >
 
<messaging:htmlEmailBody >        
    <html>
        <body>
        <apex:image id="Email_Header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=xxxxx&oid=xxxxx"
height="130" width="600"/>

         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
             
             </STYLE>
           <font face="arial" size="2">
           <br/>
           <br/>
      <p/>  Dear  
    <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>

</apex:repeat>,
            <br/>
            <br/>       
        {!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
                    <br/>
       
Our records show the information below about your company:
<br/>
            <br/>
             <td><b>•   </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
             <br/>
             <td><b>•   </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>

<p/>  <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">  
       <tr>
       <td><b>•   </b> Membership type {!opp.PriceBookEntry.name}.</td> <br/>
        </tr>
      </apex:repeat>  
      <br/>​


Thanks in advance.
Hi, I have a VF email template on the Opportunity object. I've been asked to include contact information from the related account but I can't work out how to get this into the template.

This is the code:

messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
 replyTo="xxx@xxx.org" >
 
<messaging:htmlEmailBody >        
    <html>
        <body>
        <apex:image id="Email_Header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=xxxxx&oid=xxxxx"
height="130" width="600"/>

         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
             
             </STYLE>
           <font face="arial" size="2">
           <br/>
           <br/>
      <p/>  Dear  
    <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>

</apex:repeat>,
            <br/>
            <br/>       
        {!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
                    <br/>
       
Our records show the information below about your company:
<br/>
            <br/>
             <td><b>•   </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
             <br/>
             <td><b>•   </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>

<p/>  <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">  
       <tr>
       <td><b>•   </b> Membership type {!opp.PriceBookEntry.name}.</td> <br/>
        </tr>
      </apex:repeat>  
      <br/>
 <p/>  <apex:repeat var="acc" value="{!relatedTo.Account}">  
       <tr>
       <td><b>•   </b> Main Contact "{!relatedto.acc.Contacts}".</td> <br/>
        </tr>
      </apex:repeat> 


The part in italics is what I have added to try and include the contact related list but I get the error 'Invalid field acc for SObject Opportunity'.

I'm not good on code; is there a simple way to bring in a related list from a related object?

Any help is much appreciated!

Thanks.
I kept getting an error message when checking my challenge to say that it couldn't find Last Name and Company ifields in my screen element.  I managed to get that working and passed the challenge, however if I go to my home page, the create lead lightning component isn't showing.  instead I get the following error message:

We can't launch this flow because of a variable error. Send this error message to your admin. The value null is being provided for variable leadId but isn't compatible with the variable's data type (String). Check the places where you implemented the flow ‒ such as through a Lightning page or a custom button ‒ and make sure that all provided values are compatible with the variables' data types.

The variable LeadId is a text field.

What have I done wrong and why did it let me pass the challenge if it doesn't work properly?

 
Hi, I have created a flow to add an opportunity from a button.  I need to be able to populate a field with the current year, but I can't work out how to do it.  Can anyone help please?
Thanks
Hi,

I've just started the Trailhead 'Set Up a Community for External Identity' and can't find Customers in the Members list.

This is what I'm meant to see:
User-added image

And this is what I actually see:

User-added image

There is no 'Customers' on the list.

I've only just started this Trailhead and I can't see where I could have gone wrong.  Any ideas?
 
I have a process and flow that creates a new record.  I want to populate a date field with the end of the current year, how do I do this?

Being even more ambitious, is it possible to say if current date is later than 31st November, then populate date with 31st December next year, otherwise say 31st December this year?

Many thanks
Hi, I am creating my first VF email template and everything is working ok, apart from the letterhead.

I have saved the image in a folder accessible by all users, and the image is externally available.  However the image doesn't show on the preview or on the email that I receive when I test it.  It looks no different to when I don't include the image part.

This is the code (image part in italics):

<messaging:emailTemplate subject="Is it right for your course?" recipientType="Contact"
    relatedToType="Opportunity"
 replyTo="ABC@RSC.org" >
   
<apex:image id="Campaign_email_template_1_header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=0155E000000DOpG&oid=00D5E0000008mQr&lastMod=1491232024000"
height="64" width="64"/>


<messaging:htmlEmailBody >        
    <html>
        <body>
        
         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
             
             </STYLE>
           <font face="arial" size="2">
      <p/>  Dear   
      <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
{!ContactRole.Contact.Name}
</apex:repeat>
<br/>
<p/>  Thank you for reviewing <p/>                  
   
    <b><apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
       <tr>
           
           <td>{!opp.PriceBookEntry.name}</td>
        </tr>
      </apex:repeat>  </b>  
 <br/>      
 <br/>
<br/>
Text of email etc. etc.

<br/>We look forward to hearing from you.
<br/>
<br/>Best wishes
<br/>
<br/>RSC
       </font>
          </body>
        </html>
    </messaging:htmlEmailBody>  
   
</messaging:emailTemplate>


Can anyone give me any ideas as to where I've gone wrong please?  In easy to understand words, as I don't 'do' code! :)
Hi, I am a complete coding novice and have hit a problem with code written by my predecessor in my test org.

Opportunities have a field called 'renew with what year' which is a picklist of future years. When the opp is closed and 2017 is selected in this field, the code creates a new opportunity and adds the products from the 2017 price book. It is also meant to replicate any quote attached to the opportunity.

It works ok in production but we have activated multi currency in our test org and this caused the code to fail. Salesforce support fixed it so that the opportunity is replicated fine if there isn't a quote attached (thier comment was 'you were trying to update the list which is not possible. So you have to update the record instead of list'), but it still won't work if the opportunity has a quote attached.

The error I get is:  Error:Apex trigger RenewOp6 caused an unexpected exception, contact your administrator: RenewOp6: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 1; first error: FIELD_INTEGRITY_EXCEPTION, The pricebook entry is in a different pricebook than the one assigned to the Quote, or Quote has no pricebook assigned.: Price Book Entry ID: [PricebookEntryId]: Trigger.RenewOp6: line 99, column 1

This is the portion of code that doesn't work:

//If there is a Syncing Quote create a new quote on the new opp and add same details to the new quote
IF(o.SyncedQuoteId!=null)
{    
List<Quote> Q = [select id, Account_Joining_Count__c, Which_Billing_address_should_be_used__c
                 from Quote
                 where IsSyncing =:true and Opportunity.Id =:o.Id limit 1];   
      Quote NQ = New Quote();
        NQ.Opportunityid = op.Id;
            NQ.Which_Billing_address_should_be_used__c = Q[0].Which_Billing_address_should_be_used__c;
        NQ.Contract_Start_Date__c = op.CloseDate;
        NQ.Contract_End_Date__c = op.Asset_Expires_When__c;
        NQ.Name = op.Name;
        NQ.Pricebook2Id=PBE[0].Pricebook2Id;
      Insert NQ;
list<QuoteLineItem> QLI = new list <QuoteLineItem>();
QuoteLineItem QOL = New QuoteLineItem();
FOR(PricebookEntry PE :PBE){
    FOR(OpportunityLineItem OL :OLI){
    IF(PE.Product2Id == OL.PricebookEntry.Product2Id){
        QOL = New QuoteLineItem();
            QOL.Quoteid = NQ.id;
            QOL.PricebookEntryId = PE.id;
            system.debug('gggggggggggg'+PE.id);
            QOL.Quantity = OL.Quantity;
            IF(o.Use_New_Pricebook_Values__c == true)
                QOL.UnitPrice = PE.UnitPrice;
                else
                
                    QOL.UnitPrice = OL.UnitPrice * IncPerAsDec;
                
           QLI.add(QOL);
        }
    }

}
Insert QLI;

Can anyone suggest what I need to do to get the quote to recognise the pricebook please?  Bearing in mind I don't speak code... :(
Hi,

I've just started the Trailhead 'Set Up a Community for External Identity' and can't find Customers in the Members list.

This is what I'm meant to see:
User-added image

And this is what I actually see:

User-added image

There is no 'Customers' on the list.

I've only just started this Trailhead and I can't see where I could have gone wrong.  Any ideas?
 
Hi, can anyone help me combine these two formulas on a date field please?

IF the Portfolio is Interfaces and the Status is Agreed and the EA Action is one of 3, then the date should be Expected Submission Date -28, +14 or +42.
PLUS
IF the Portfolio is Interfaces and the Status is Invited and the EA Action is First Invitation Chaser, then the date should be Invite email sent + 28 days

I have them both working on separate fields, but can't get them into one formula.

Formula 1:

IF( AND( Journal_for_Article_use__r.Portfolio__c = "Interfaces",
ISPICKVAL( Status__c , "AGR - Agreed to submit")
),
CASE( TEXT( EA_Action__c ),
"Submission Reminder", (Expected_Submission_Date__c - 28),
"First Submission Chaser", (Expected_Submission_Date__c + 14),
"Second Submission Chaser", (Expected_Submission_Date__c + 42),
Null
),
Null
)

Formula 2:

IF( AND(
Journal_for_Article_use__r.Portfolio__c = "Interfaces",
ISPICKVAL( Status__c , "INV - Invited")
),
CASE( TEXT( EA_Action__c ),
"First Invitation Chaser", (Invite_email_sent__c +28),
Null),
Null)
Hi, I'm getting the same error on all the code I try for  the Trailhead Challenge 'Create a unit test for a simple Apex Class'.

The error I get is: Method does not exist or incorrect signature: void CheckDates(Date, Date) from the type VerifyDate

I have tried the following:

@isTest
private class TestVerifyDate {
    
    static testMethod void TestVerifyDates() {
        VerifyDate.CheckDates(system.today(),system.today().addDays(10));
        
        VerifyDate.CheckDates(system.today(),system.today().addDays(78));
       
    }

}


Also:

@isTest
public class TestVerifyDate {
    @isTest static void testVerifyDate(){
        date date1=VerifyDate.CheckDates(system.today(),system.today().addDays(10));
        System.assertEquals(system.today().addDays(10),date1);
        
        date date2=VerifyDate.CheckDates(system.today(),system.today().addDays(78));
        System.assertEquals(system.today(),date2);
    }
}


Also:

@isTest
private class TestVerifyDate{
    @isTest static void testDt1GtrDt2(){
        Date d2 = system.today();
        Date d1 = d2.addDays(10);
        
        Date dt = VerifyDate.CheckDates(d1, d2);
        Date testDt = Date.newInstance(2017, 7, 31);
        System.assertEquals(dt, testDt);
    }
    
    @isTest static void testDt2Within30dayOfDt1(){
        Date d1 = system.today();
        Date d2 = d1.addDays(10);
        
        Date dt = VerifyDate.CheckDates(d1, d2);
        System.assertEquals(dt, d2);
    }
}


This is the code for the Class itself:

public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
//check for date2 being in the past
if( date2 < date1) { return false; }
//check that date2 is within (>=) 30 days of date1
Date date30Days = date1.addDays(30); //create a date 30 days away from date1
if( date2 >= date30Days ) { return false; }
else { return true; }
}
//method to return the end of the month of a given date
private static Date SetEndOfMonthDate(Date date1) {
Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
return lastDay;
}
}

Can anyone point me to what I am doing wrong please?

Thanks!




 
Hi, I have a VF email template on the Opportunity object. I've been asked to include contact information from the related account but I can't work out how to get this into the template.

This is the code:

messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
 replyTo="xxx@xxx.org" >
 
<messaging:htmlEmailBody >        
    <html>
        <body>
        <apex:image id="Email_Header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=xxxxx&oid=xxxxx"
height="130" width="600"/>

         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
             
             </STYLE>
           <font face="arial" size="2">
           <br/>
           <br/>
      <p/>  Dear  
    <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>

</apex:repeat>,
            <br/>
            <br/>       
        {!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
                    <br/>
       
Our records show the information below about your company:
<br/>
            <br/>
             <td><b>•   </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
             <br/>
             <td><b>•   </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>

<p/>  <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">  
       <tr>
       <td><b>•   </b> Membership type {!opp.PriceBookEntry.name}.</td> <br/>
        </tr>
      </apex:repeat>  
      <br/>
 <p/>  <apex:repeat var="acc" value="{!relatedTo.Account}">  
       <tr>
       <td><b>•   </b> Main Contact "{!relatedto.acc.Contacts}".</td> <br/>
        </tr>
      </apex:repeat> 


The part in italics is what I have added to try and include the contact related list but I get the error 'Invalid field acc for SObject Opportunity'.

I'm not good on code; is there a simple way to bring in a related list from a related object?

Any help is much appreciated!

Thanks.
I kept getting an error message when checking my challenge to say that it couldn't find Last Name and Company ifields in my screen element.  I managed to get that working and passed the challenge, however if I go to my home page, the create lead lightning component isn't showing.  instead I get the following error message:

We can't launch this flow because of a variable error. Send this error message to your admin. The value null is being provided for variable leadId but isn't compatible with the variable's data type (String). Check the places where you implemented the flow ‒ such as through a Lightning page or a custom button ‒ and make sure that all provided values are compatible with the variables' data types.

The variable LeadId is a text field.

What have I done wrong and why did it let me pass the challenge if it doesn't work properly?

 
Module: Lightning Flow
            : Guide Users Through Your Business Processes with Cloud Flow Designer

Issue   : Unable to complete the challenge - Guide users through creating a lead

Can't find the forceContent:fileUpload Lightning component in the 'New Lead' flow. Make sure the field’s unique name is 'Upload_File'

For some reason i'm unable to save as Upload File field name. I have checked for any duplicates in FLOW's and deleted the one which had but still getting same error message.

Could anybody please assist me on this?

Cheers
Hi All,

I am new to Salesforce and I just wrote my first Hello World Trigger on Lead object as below.

trigger HelloWorld on Lead (before update) {
    for (Lead l: Trigger.new) {
        l.FirstName='Hello';
        l.lastName='World';
    }

Guess what, this thing is running even when I create new Lead and setting the first and last names to hello world. What am I doing wrong?

- Amar
Hi, I have created a flow to add an opportunity from a button.  I need to be able to populate a field with the current year, but I can't work out how to do it.  Can anyone help please?
Thanks
Hi,

I've just started the Trailhead 'Set Up a Community for External Identity' and can't find Customers in the Members list.

This is what I'm meant to see:
User-added image

And this is what I actually see:

User-added image

There is no 'Customers' on the list.

I've only just started this Trailhead and I can't see where I could have gone wrong.  Any ideas?
 
Hi, I am creating my first VF email template and everything is working ok, apart from the letterhead.

I have saved the image in a folder accessible by all users, and the image is externally available.  However the image doesn't show on the preview or on the email that I receive when I test it.  It looks no different to when I don't include the image part.

This is the code (image part in italics):

<messaging:emailTemplate subject="Is it right for your course?" recipientType="Contact"
    relatedToType="Opportunity"
 replyTo="ABC@RSC.org" >
   
<apex:image id="Campaign_email_template_1_header"
value="https://c.cs84.content.force.com/servlet/servlet.ImageServer?id=0155E000000DOpG&oid=00D5E0000008mQr&lastMod=1491232024000"
height="64" width="64"/>


<messaging:htmlEmailBody >        
    <html>
        <body>
        
         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
             
             </STYLE>
           <font face="arial" size="2">
      <p/>  Dear   
      <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
{!ContactRole.Contact.Name}
</apex:repeat>
<br/>
<p/>  Thank you for reviewing <p/>                  
   
    <b><apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">
       <tr>
           
           <td>{!opp.PriceBookEntry.name}</td>
        </tr>
      </apex:repeat>  </b>  
 <br/>      
 <br/>
<br/>
Text of email etc. etc.

<br/>We look forward to hearing from you.
<br/>
<br/>Best wishes
<br/>
<br/>RSC
       </font>
          </body>
        </html>
    </messaging:htmlEmailBody>  
   
</messaging:emailTemplate>


Can anyone give me any ideas as to where I've gone wrong please?  In easy to understand words, as I don't 'do' code! :)
Hi, I am a complete coding novice and have hit a problem with code written by my predecessor in my test org.

Opportunities have a field called 'renew with what year' which is a picklist of future years. When the opp is closed and 2017 is selected in this field, the code creates a new opportunity and adds the products from the 2017 price book. It is also meant to replicate any quote attached to the opportunity.

It works ok in production but we have activated multi currency in our test org and this caused the code to fail. Salesforce support fixed it so that the opportunity is replicated fine if there isn't a quote attached (thier comment was 'you were trying to update the list which is not possible. So you have to update the record instead of list'), but it still won't work if the opportunity has a quote attached.

The error I get is:  Error:Apex trigger RenewOp6 caused an unexpected exception, contact your administrator: RenewOp6: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 1; first error: FIELD_INTEGRITY_EXCEPTION, The pricebook entry is in a different pricebook than the one assigned to the Quote, or Quote has no pricebook assigned.: Price Book Entry ID: [PricebookEntryId]: Trigger.RenewOp6: line 99, column 1

This is the portion of code that doesn't work:

//If there is a Syncing Quote create a new quote on the new opp and add same details to the new quote
IF(o.SyncedQuoteId!=null)
{    
List<Quote> Q = [select id, Account_Joining_Count__c, Which_Billing_address_should_be_used__c
                 from Quote
                 where IsSyncing =:true and Opportunity.Id =:o.Id limit 1];   
      Quote NQ = New Quote();
        NQ.Opportunityid = op.Id;
            NQ.Which_Billing_address_should_be_used__c = Q[0].Which_Billing_address_should_be_used__c;
        NQ.Contract_Start_Date__c = op.CloseDate;
        NQ.Contract_End_Date__c = op.Asset_Expires_When__c;
        NQ.Name = op.Name;
        NQ.Pricebook2Id=PBE[0].Pricebook2Id;
      Insert NQ;
list<QuoteLineItem> QLI = new list <QuoteLineItem>();
QuoteLineItem QOL = New QuoteLineItem();
FOR(PricebookEntry PE :PBE){
    FOR(OpportunityLineItem OL :OLI){
    IF(PE.Product2Id == OL.PricebookEntry.Product2Id){
        QOL = New QuoteLineItem();
            QOL.Quoteid = NQ.id;
            QOL.PricebookEntryId = PE.id;
            system.debug('gggggggggggg'+PE.id);
            QOL.Quantity = OL.Quantity;
            IF(o.Use_New_Pricebook_Values__c == true)
                QOL.UnitPrice = PE.UnitPrice;
                else
                
                    QOL.UnitPrice = OL.UnitPrice * IncPerAsDec;
                
           QLI.add(QOL);
        }
    }

}
Insert QLI;

Can anyone suggest what I need to do to get the quote to recognise the pricebook please?  Bearing in mind I don't speak code... :(