• Nicholas Mirams
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 10
    Replies
Hi,
I am trying to use process builder and a flow to clone an event and add in all the leads/contacts form the old event to the new.
The owner of the new event is a user selected from a picklist.

So far I have got the event to create but the who ids are not adding.  Can someone have a look and see where I am going wrong.

User-added image
I have first looked up the old event ID (process builder input) and then saved every field into individual variables

The looked up the table Event Who Relation using the same criteria of event id = the old event id variable I input into process builder and saved the ID and Relation ID from that table

Then I created the event record with the value of each field being the variables I saved from looking up the old event.  

Then I loop through a collection variable (Event Who relation) and assign it to a record variable (event who relation)

The decision checks if there are any ids from the loop.

Here are the assignents; -
User-added image

TaskRelationId is a record variable on the Event Who Relation table in the first assignment and they equal the relation id from the loop.  The other is the new event id

The final assignment is a collection varibale on the event who relation table and is equal to the record variable from the previous

The creation, final part of the flow is creating from the collection variable.

I get no error, how would I debug this?  do I have to assign them to the event relation table and event table and if so how.  The event clones and assigns the new owner but no who ids are showing

Thanks for any help in solving this
 
Hi,
I am new to visualforce and trying to create a list view of opportunities for the mobile app,  Here is the page so far: -

User-added image
How on earth do I move the commant button tot he middle?  The botom one is centered but not the tope one; 

code: -
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity" sidebar="true" lightningStylesheets="true">
    <apex:form >        
          <apex:pageblock >       
              <apex:pageBlockSection title="MY OPPORTUNITIES" columns="2" collapsible="false"> 
                          <apex:selectList value="{!filterId}" size="1">
                                <apex:actionSupport event="onchange" rerender="opp_table"/>
                                <apex:selectOptions value="{!listviewoptions}"/>
                          </apex:selectList>
                      <div>
                         <left><img src="{!$Resource.OpportunityLogo}" height="50" width="50"/></left>
                      </div>    
             </apex:pageBlockSection> 
                   <apex:pageBlockButtons location="both">
                    <apex:commandButton value="Save" action="{!save}" style="float:center;color: #1798c1; font-size: 17px;font-weight: normal; border-radius:0;" />
                </apex:pageBlockButtons>
               
                 
            <apex:pageBlockTable value="{!opportunities}" var="opp" id="opp_table">
                <apex:column value="{!opp.name}" title="Opportuntiy Name"/>
                <apex:column value="{!opp.Account.Name}"/>
                <apex:column value="{!opp.CTN_Service__c}"/>
                <apex:column headerValue="Stage">
                    <apex:inputField value="{!opp.stageName}"/>
                </apex:column>
                <apex:column headerValue="Close Date">
                    <apex:inputField value="{!opp.closeDate}"/>
                </apex:column>
                <apex:column headerValue="Amount">
                    <apex:inputField value="{!opp.amount}"/>
                </apex:column>
             </apex:pageBlockTable>   
        </apex:pageBlock>
    </apex:form>
</apex:page>

Any ideas how or a better way to show a related opportunity list on salesforce?
Thanks!​​​​​​​
Hi,

I am tryign to write a test class for a campaign memebr trigger and am struggling to get over 60% code coverage.  I am veyr much trying to learn apex as very new to it so any help you be good.
Thanks

TRIGGER


Trigger HistoryTrack on CampaignMember (after insert, before update, before delete) {          
List<CampaignHistory__c> ch= new List<CampaignHistory__c>(); ch.sort();
List<CampaignMember> cmOld= Trigger.old;  
List<String> changes  = new List<String>(); 
List<String> CampHisId  = new List<String>(); 
integer i=0;     
if(Trigger.isDelete){
            for(CampaignMember cm: Trigger.old ){     
                       String s;                            
                       s='Campaign Member: ' + cm.Member_Name__c + ' is Deleted from campaign: '+ cm.Campaign_Name__c + 'by user '+ userinfo.getName();                                        
                       changes.add(s);
                       CampHisId.add(cm.campaignId);
                       CampaignHistory__c c= new CampaignHistory__c();                           
                       System.debug('CName:'+c.Name);
                       c.CampaignId__c=CampHisId[i];
                       System.debug('CampaignId:'+c.CampaignId__c);                              
                       c.History_Details__c=changes[i];
                      System.debug('CHistory:'+c.History_Details__c);         
                      ch.add(c);                              
                      i++;      
     
             } 
        }else {      
                     for(CampaignMember cm: Trigger.new ){  
                            String s;
                            if((Trigger.isUpdate)){
                                   if(cmOld[i].status!=cm.status){    
                                          s='Lead/Contact: ' + cm.Member_Name__c +                       
                                            ' status changed from ' + cmOld[i].status + ' to ' + cm.status +                        
                                            ' by user ' + userinfo.getName();
                                           
                                           changes.add(s);
                                          CampHisId.add(cm.campaignId);                                                  
                                          CampaignHistory__c c= new CampaignHistory__c();                          
                                          System.debug('CName:'+c.Name);
                                          c.CampaignId__c=CampHisId[i];                        
                                          System.debug('CampaignId:'+c.CampaignId__c);                                      
                                          c.History_Details__c=changes[i];
                                          System.debug('CHistory:'+c.History_Details__c);
                                          ch.add(c); 
                                      }else if(cmOld[i].campaignId!=cm.campaignId){                        
                                                s='Changed Campaign id from : '+ cmOld[i].campaignId + 'to :' + cm.campaignId +                        
                                                    ' by user '+ userinfo.getName();  
                                              changes.add(s);                        
                                             CampHisId.add(cm.campaignId);                                                            
                                            CampaignHistory__c c= new CampaignHistory__c();                           
                                            System.debug('CName:'+c.Name);              
                                            c.CampaignId__c=CampHisId[i];                   
                                           System.debug('CampaignId:'+c.CampaignId__c);                                          
                                            c.History_Details__c=changes[i];
                                            System.debug('CHistory:'+c.History_Details__c);                         
                                            ch.add(c);

                                         }             
                           }else if(Trigger.isInsert){                                
                                       s='A new Campaign Member: ' + cm.Member_Name__c + ' is added to Campaign: ' + cm.Campaign_Name__c +' by user '+ userinfo.getName();
                                       changes.add(s);                    
                                       CampHisId.add(cm.campaignId);                    
                                       System.debug('s>>>'+s);                                                                    
                                       CampaignHistory__c c= new CampaignHistory__c();                                                         
                                       System.debug('CName:'+c.Name);
                                       c.CampaignId__c=CampHisId[i];
                                       System.debug('CampaignId:'+c.CampaignId__c);                                          
                                       c.History_Details__c=changes[i];
                                       System.debug('CHistory:'+c.History_Details__c);                                        
                                       ch.add(c);
                            } 
                            i++;     
                       }         
                }    
                insert ch; 
                ch.sort();               
         }

TEST CLASS
@IsTest
    Public class HistoryTrackTest{
    
    static testMethod void HistoryTrackTest() {
    
        Account a = new Account();
        a.Name = 'Brian Blesseds House';
        a.Primary_Regions__c = 'United Kingdom';
        a.Type = 'Casdodian';
        a.Status__c = 'Live';
        insert a;
    
        Lead l = new Lead();
        l.FirstName = 'Brian';
        l.LastName = 'Blessed';
        l.Marketing_Prospect_Level__c = 'Prospect';
        l.Title = 'Madmen';
        l.Company = 'Gordans Alive Ltd';
        l.email = 'brian.blessed@crackers.com';
        l.Status = 'Sales Accepted Lead (SAL)';
        l.Country__c = 'United Kigdom';
        l.RecordTypeId = '0120X0000009exXQAQ';
        insert l;
        
        Contact cnt = new Contact();
        cnt.firstname = 'Robin';
        cnt.lastname = 'Williams';
        cnt.accountid = a.id;
        cnt.Marketing_Prospect_Level__c = 'Prospect';
        cnt.Country__c = 'United Kingdom';
        cnt.Title = 'Crackers';
        cnt.Level__c = 'Level 1';
        insert cnt;
        
        Campaign cam = new Campaign();
        cam.Name = 'New Campaign';
        cam.IsActive = True;
        cam.Description = 'This campaign will hold my lead for the history trigger';
        cam.StartDate = Date.Today();
        cam.Type = 'Email';
        insert cam;
        
        CampaignMember cm = new CampaignMember();
        cm.Leadid = l.id;
        cm.Status = 'Responded';
        cm.CampaignId = cam.id;
        insert cm;
        
        CampaignMember cm2 = new CampaignMember();
        cm2.Contactid = cnt.id;
        cm2.Status = 'Sent';
        cm2.Campaignid = cam.id;
        insert cm2;
        
        CampaignHistory__c ch = new CampaignHistory__c();
        ch.CampaignId__c = cam.id;
        ch.History_Details__c = 'Campaign Member Brian Blessed was added to New Campaign by Nick Mirams';
        insert ch;
        
        CampaignHistory__c ch2 = new CampaignHistory__c();
        ch2.CampaignId__c = cam.id;
        ch2.History_Details__c = 'Campaign Member Robin Williams was added to New Campaign by Nick Mirams';
        insert ch2;
        
        cm.Status = 'Sent';
        update cm;
        
        CampaignHistory__c ch3 = new CampaignHistory__c();
        ch3.CampaignId__c = cam.id;
        ch3.History_Details__c = 'Campaign Member Robin Williams Status was changed form Responded to Sent by Nick Mirams';
        insert ch3;
        
   }
   
 }
Hi,
I am getting an error when testing and trying to deploy the below trigger
How do I change the list to a map as I think thats the error.  I am not an apex coder and am trying to learn

first trigger which updates a contact  record to customer upon the opportunity setting to won (contact role): -
trigger UpdateContactToCustomer on Opportunity (after insert, after update) {

        OpportunityContactRole ocr;
        Contact contact;
        Opportunity opp = Trigger.new[0];
        
        list<Contact> listToUpdate = new list<Contact>();
        
        if(opp.StageName == 'Complete - Live'){

            
            for(OpportunityContactRole iterating_oppConRole : [SELECT o.Role, 
                                                                      o.OpportunityId, 
                                                                      o.IsPrimary, 
                                                                      o.Id, 
                                                                      o.ContactId,
                                                                      o.Contact.Marketing_Prospect_Level__c
                                                              FROM OpportunityContactRole o where o.OpportunityId =: opp.id])
                                                              {
                Contact tempContact = new Contact(id=iterating_oppConRole.ContactId, Marketing_Prospect_Level__c = 'Customer');
                               
                listToUpdate.add(tempContact);
               
           }
        }

        if(!listToUpdate.isEmpty())
            update listToUpdate;
}
Hi,

I have the below trigger on Lead which works after the lead is converted.  It takes the name of the new contact thats created and adds it to a field on the opportunity.
How do I go about adjusting this to only fire of the field on opportunity is blank?  I have tried adding somethign to the if statement but its not doing anything as the contact is not created yet
Thanks
trigger LeadTrigger on Lead (after update) {

    if (trigger.isAfter && trigger.isUpdate) {
        List<Opportunity> oppsToUpdate = new List<Opportunity>();

        for (Lead ld : trigger.New) {
            if(ld.isConverted && trigger.OldMap.get(ld.id).isConverted) {
                continue;
            }

            if (ld.ConvertedOpportunityId != null && ld.ConvertedContactId != null) {
                 Opportunity opp = new Opportunity(Id = ld.ConvertedOpportunityId);
                 opp.Primary_Contact__c = ld.ConvertedContactID;
                 oppsToUpdate.add(opp);
            }
        }

        if (!oppsToUpdate.isEmpty()) {
            update oppsToUpdate;
        }
    }

}
Hi
I am trying to write a trigger on opportunity.  Once the opportuntiy is Won, I want to look at the product picklist field on the opportunity and update the corresponding contact roles with checking the checkbox of the product.
i.e. Opportunity is closed won, product on the opportuntiy is a picklist is Product A I want to update a contact role (contact) checkbox field called product A.
So far I ued some old code I tried when I had lots of rollup summary fields and now getting an error that the expression must be of type boolean and not string

trigger Updateproductsbought on Opportunity (after update) {

Set<Id> st_OppId = new Set<Id>();
List<Contact> con_List;

for(Opportunity opp :Trigger.new)
  {
     if(opp.StageName=='Complete - Live' )
         st_OppId.add(opp.id);
 }

if(st_OppId!=null && !st_OppId.isEmpty())
    {

         for(OpportunityContactRole iterating_oppConRole : [SELECT Role, 
                                                             OpportunityId, 
                                                             IsPrimary, 
                                                             Id, 
                                                             ContactId,
                                                             Contact.Order_Routing__c, 
                                                             Contact.Settlements__c,
                                                             Contact.Dividends__c,
                                                             Contact.Transfers__c,
                                                             Contact.Payments__c,
                                                             Contact.Re_registration__c,
                                                             Contact.Reporting_Reconciliations__c,
                                                             Opportunity.CTN_Service__c
                                                             FROM OpportunityContactRole  where OpportunityId IN : st_OppId])
                               {                                                                

                    if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Order Routing')
                        {
                              iterating_oppConRole.Contact.Order_Routing__c = true;
                        }
                    
                     if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Settlements')
                         {
                               iterating_oppConRole.Contact.Settlements__c = true;
                         }
                         
                      if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Dividends')
                        {
                              iterating_oppConRole.Contact.Dividends__c = true;
                        }
                    
                     if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Transfers')
                         {
                               iterating_oppConRole.Contact.Transfers__c = true;
                         }
                         
                      if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Payments')
                        {
                              iterating_oppConRole.Contact.Payments__c = true;
                        }
                    
                     if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Re-registration')
                         {
                               iterating_oppConRole.Contact.Re_registration__c = true;
                         }    
                         
                      if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Reporting_Reconciliations__c')
                         {
                               iterating_oppConRole.Contact.Reporting_Reconciliations__c = true;
                         }                                      

                                       if(con_List == null)
                                           con_List = new List<Contact>();

                                          con_List.add(iterating_oppConRole.Contact);
                                }

               
           }
        
        if(con_List!=null && !con_List.isEmpty())
            update con_List;
}

As I am new to apex any help would be appreciated
Thanks
 
Hi,
I have a custom button attached to a visualforce page: -

<apex:page StandardController="Lead" lightningStylesheets="true" showHeader="false">        
    <flow:interview name="Leads_Mass_Take_Ownership_Button"
          finishLocation="{!IF($User.UITheme == 'Theme4d' || $User.UITheme == 'Theme4t','/lightning/o/Lead/{!Lead.Id}','/{!Lead.Id}')}">
        <apex:param name="VLeadid" value="{!Lead.Id}"/>
    </flow:interview>
</apex:page>

Once clicked on the flow runs to Update the Lead Status and also change the owner form a queue tot he current user.

This seems to work ok but I cannot get the page to redirect back to the Lead record where the button was clicked after the flow is complete.  It works ok in Classic but not lightning, any ideas on how to help me.

Asuming this is the best was to update two fields on screen via a button

Thanks
 
Hi,

I have completed a flow which fires from process builder which is only working in lightning and not fully working in classic!

My flow works after a task is created on an opportunity the task takes all the contacts from that task and adds then as contact roles on the associated opportuntiy.

here is a view of it, seems to work fine adding all the contacts in the task as contact roles in lightning but only adding the first contact in classic...

Any ideas?
User-added image
Hi,

Using a Flow and process Building (assuming its possible) I would like to, once a task is added on an opportuntiy, get all the contacts from that task and then add them to the corresponding opportuntiy as contact roles.  I will try this with events also later on.

How do I do this? do I start, in the flow with a fast lookup to the task object or task relation object and then do I need a Loop and then assignment?
I also want to, once the records have been fetched, either create the contact role on the opportunity with that contact(s) or if it already exists as a contact role, update it

I am struggling and have so far got it to add a single contact, but it also duplicates it if its added again to another task

Thanks
 
Hi,
Is it possible to remove the New button from the Opportunity List view called Recent Items?  I can remove it from all other list views but not this one.
My aim is to get everyone to create opportunities through contacts or lead conversion.  I have managed this using a visualforce page for classic but no idea how to do it in lightning and not a developer

Thanks
 
Hi,

Gettgin an error 'Invalid or Unexpecte Token'

I am tryign to create a button in salesforce to check if the Opportuntiy Stage is a certain stage and if so open a url, pre populating fields along the way: -

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")} 


if("{!Opportunity.StageName}" != "Won - Pending Ops") { 

alert("You cannot create a Sales Handover until the opportunity is in the Stage of 'Won - Pending Ops'.\n\nPlease amend the Stage and try again"); 

} else { 

window.open('https://calastone--sandbox.cs88.my.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01Ib00000001BNO&retURL=%2Fa09%2Fo&save_new_url=%2Fa09%2Fe%3FretURL%3D%252Fa09%252Fo
&CF00Nb0000001uEZ9={!Opportunity.OwnerFullName}
&CF00Nb0000009fjvF={!Opportunity.Name}
&00Nb0000001uojJ="New"
&00Nb0000002Uvb5={!Opportunity.CTN_Service__c}
&CF00Nb00000039Pn4={!Opportunity.Account}
&CF00Nb0000002UvNo={!Account.TPA_Account__c}
&00Nb0000001uFSe={!Account.Client_Type__c}
&00Nb0000002UvIY={!Account.Primary_Regions__c}','_Parent');

}

Help, I am new so struggling to see what I have missed out

Thanks
 
Hi,
I am trying to use process builder and a flow to clone an event and add in all the leads/contacts form the old event to the new.
The owner of the new event is a user selected from a picklist.

So far I have got the event to create but the who ids are not adding.  Can someone have a look and see where I am going wrong.

User-added image
I have first looked up the old event ID (process builder input) and then saved every field into individual variables

The looked up the table Event Who Relation using the same criteria of event id = the old event id variable I input into process builder and saved the ID and Relation ID from that table

Then I created the event record with the value of each field being the variables I saved from looking up the old event.  

Then I loop through a collection variable (Event Who relation) and assign it to a record variable (event who relation)

The decision checks if there are any ids from the loop.

Here are the assignents; -
User-added image

TaskRelationId is a record variable on the Event Who Relation table in the first assignment and they equal the relation id from the loop.  The other is the new event id

The final assignment is a collection varibale on the event who relation table and is equal to the record variable from the previous

The creation, final part of the flow is creating from the collection variable.

I get no error, how would I debug this?  do I have to assign them to the event relation table and event table and if so how.  The event clones and assigns the new owner but no who ids are showing

Thanks for any help in solving this
 
Hi,
I am new to visualforce and trying to create a list view of opportunities for the mobile app,  Here is the page so far: -

User-added image
How on earth do I move the commant button tot he middle?  The botom one is centered but not the tope one; 

code: -
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity" sidebar="true" lightningStylesheets="true">
    <apex:form >        
          <apex:pageblock >       
              <apex:pageBlockSection title="MY OPPORTUNITIES" columns="2" collapsible="false"> 
                          <apex:selectList value="{!filterId}" size="1">
                                <apex:actionSupport event="onchange" rerender="opp_table"/>
                                <apex:selectOptions value="{!listviewoptions}"/>
                          </apex:selectList>
                      <div>
                         <left><img src="{!$Resource.OpportunityLogo}" height="50" width="50"/></left>
                      </div>    
             </apex:pageBlockSection> 
                   <apex:pageBlockButtons location="both">
                    <apex:commandButton value="Save" action="{!save}" style="float:center;color: #1798c1; font-size: 17px;font-weight: normal; border-radius:0;" />
                </apex:pageBlockButtons>
               
                 
            <apex:pageBlockTable value="{!opportunities}" var="opp" id="opp_table">
                <apex:column value="{!opp.name}" title="Opportuntiy Name"/>
                <apex:column value="{!opp.Account.Name}"/>
                <apex:column value="{!opp.CTN_Service__c}"/>
                <apex:column headerValue="Stage">
                    <apex:inputField value="{!opp.stageName}"/>
                </apex:column>
                <apex:column headerValue="Close Date">
                    <apex:inputField value="{!opp.closeDate}"/>
                </apex:column>
                <apex:column headerValue="Amount">
                    <apex:inputField value="{!opp.amount}"/>
                </apex:column>
             </apex:pageBlockTable>   
        </apex:pageBlock>
    </apex:form>
</apex:page>

Any ideas how or a better way to show a related opportunity list on salesforce?
Thanks!​​​​​​​
Hi,

I am tryign to write a test class for a campaign memebr trigger and am struggling to get over 60% code coverage.  I am veyr much trying to learn apex as very new to it so any help you be good.
Thanks

TRIGGER


Trigger HistoryTrack on CampaignMember (after insert, before update, before delete) {          
List<CampaignHistory__c> ch= new List<CampaignHistory__c>(); ch.sort();
List<CampaignMember> cmOld= Trigger.old;  
List<String> changes  = new List<String>(); 
List<String> CampHisId  = new List<String>(); 
integer i=0;     
if(Trigger.isDelete){
            for(CampaignMember cm: Trigger.old ){     
                       String s;                            
                       s='Campaign Member: ' + cm.Member_Name__c + ' is Deleted from campaign: '+ cm.Campaign_Name__c + 'by user '+ userinfo.getName();                                        
                       changes.add(s);
                       CampHisId.add(cm.campaignId);
                       CampaignHistory__c c= new CampaignHistory__c();                           
                       System.debug('CName:'+c.Name);
                       c.CampaignId__c=CampHisId[i];
                       System.debug('CampaignId:'+c.CampaignId__c);                              
                       c.History_Details__c=changes[i];
                      System.debug('CHistory:'+c.History_Details__c);         
                      ch.add(c);                              
                      i++;      
     
             } 
        }else {      
                     for(CampaignMember cm: Trigger.new ){  
                            String s;
                            if((Trigger.isUpdate)){
                                   if(cmOld[i].status!=cm.status){    
                                          s='Lead/Contact: ' + cm.Member_Name__c +                       
                                            ' status changed from ' + cmOld[i].status + ' to ' + cm.status +                        
                                            ' by user ' + userinfo.getName();
                                           
                                           changes.add(s);
                                          CampHisId.add(cm.campaignId);                                                  
                                          CampaignHistory__c c= new CampaignHistory__c();                          
                                          System.debug('CName:'+c.Name);
                                          c.CampaignId__c=CampHisId[i];                        
                                          System.debug('CampaignId:'+c.CampaignId__c);                                      
                                          c.History_Details__c=changes[i];
                                          System.debug('CHistory:'+c.History_Details__c);
                                          ch.add(c); 
                                      }else if(cmOld[i].campaignId!=cm.campaignId){                        
                                                s='Changed Campaign id from : '+ cmOld[i].campaignId + 'to :' + cm.campaignId +                        
                                                    ' by user '+ userinfo.getName();  
                                              changes.add(s);                        
                                             CampHisId.add(cm.campaignId);                                                            
                                            CampaignHistory__c c= new CampaignHistory__c();                           
                                            System.debug('CName:'+c.Name);              
                                            c.CampaignId__c=CampHisId[i];                   
                                           System.debug('CampaignId:'+c.CampaignId__c);                                          
                                            c.History_Details__c=changes[i];
                                            System.debug('CHistory:'+c.History_Details__c);                         
                                            ch.add(c);

                                         }             
                           }else if(Trigger.isInsert){                                
                                       s='A new Campaign Member: ' + cm.Member_Name__c + ' is added to Campaign: ' + cm.Campaign_Name__c +' by user '+ userinfo.getName();
                                       changes.add(s);                    
                                       CampHisId.add(cm.campaignId);                    
                                       System.debug('s>>>'+s);                                                                    
                                       CampaignHistory__c c= new CampaignHistory__c();                                                         
                                       System.debug('CName:'+c.Name);
                                       c.CampaignId__c=CampHisId[i];
                                       System.debug('CampaignId:'+c.CampaignId__c);                                          
                                       c.History_Details__c=changes[i];
                                       System.debug('CHistory:'+c.History_Details__c);                                        
                                       ch.add(c);
                            } 
                            i++;     
                       }         
                }    
                insert ch; 
                ch.sort();               
         }

TEST CLASS
@IsTest
    Public class HistoryTrackTest{
    
    static testMethod void HistoryTrackTest() {
    
        Account a = new Account();
        a.Name = 'Brian Blesseds House';
        a.Primary_Regions__c = 'United Kingdom';
        a.Type = 'Casdodian';
        a.Status__c = 'Live';
        insert a;
    
        Lead l = new Lead();
        l.FirstName = 'Brian';
        l.LastName = 'Blessed';
        l.Marketing_Prospect_Level__c = 'Prospect';
        l.Title = 'Madmen';
        l.Company = 'Gordans Alive Ltd';
        l.email = 'brian.blessed@crackers.com';
        l.Status = 'Sales Accepted Lead (SAL)';
        l.Country__c = 'United Kigdom';
        l.RecordTypeId = '0120X0000009exXQAQ';
        insert l;
        
        Contact cnt = new Contact();
        cnt.firstname = 'Robin';
        cnt.lastname = 'Williams';
        cnt.accountid = a.id;
        cnt.Marketing_Prospect_Level__c = 'Prospect';
        cnt.Country__c = 'United Kingdom';
        cnt.Title = 'Crackers';
        cnt.Level__c = 'Level 1';
        insert cnt;
        
        Campaign cam = new Campaign();
        cam.Name = 'New Campaign';
        cam.IsActive = True;
        cam.Description = 'This campaign will hold my lead for the history trigger';
        cam.StartDate = Date.Today();
        cam.Type = 'Email';
        insert cam;
        
        CampaignMember cm = new CampaignMember();
        cm.Leadid = l.id;
        cm.Status = 'Responded';
        cm.CampaignId = cam.id;
        insert cm;
        
        CampaignMember cm2 = new CampaignMember();
        cm2.Contactid = cnt.id;
        cm2.Status = 'Sent';
        cm2.Campaignid = cam.id;
        insert cm2;
        
        CampaignHistory__c ch = new CampaignHistory__c();
        ch.CampaignId__c = cam.id;
        ch.History_Details__c = 'Campaign Member Brian Blessed was added to New Campaign by Nick Mirams';
        insert ch;
        
        CampaignHistory__c ch2 = new CampaignHistory__c();
        ch2.CampaignId__c = cam.id;
        ch2.History_Details__c = 'Campaign Member Robin Williams was added to New Campaign by Nick Mirams';
        insert ch2;
        
        cm.Status = 'Sent';
        update cm;
        
        CampaignHistory__c ch3 = new CampaignHistory__c();
        ch3.CampaignId__c = cam.id;
        ch3.History_Details__c = 'Campaign Member Robin Williams Status was changed form Responded to Sent by Nick Mirams';
        insert ch3;
        
   }
   
 }
Hi,
I am getting an error when testing and trying to deploy the below trigger
How do I change the list to a map as I think thats the error.  I am not an apex coder and am trying to learn

first trigger which updates a contact  record to customer upon the opportunity setting to won (contact role): -
trigger UpdateContactToCustomer on Opportunity (after insert, after update) {

        OpportunityContactRole ocr;
        Contact contact;
        Opportunity opp = Trigger.new[0];
        
        list<Contact> listToUpdate = new list<Contact>();
        
        if(opp.StageName == 'Complete - Live'){

            
            for(OpportunityContactRole iterating_oppConRole : [SELECT o.Role, 
                                                                      o.OpportunityId, 
                                                                      o.IsPrimary, 
                                                                      o.Id, 
                                                                      o.ContactId,
                                                                      o.Contact.Marketing_Prospect_Level__c
                                                              FROM OpportunityContactRole o where o.OpportunityId =: opp.id])
                                                              {
                Contact tempContact = new Contact(id=iterating_oppConRole.ContactId, Marketing_Prospect_Level__c = 'Customer');
                               
                listToUpdate.add(tempContact);
               
           }
        }

        if(!listToUpdate.isEmpty())
            update listToUpdate;
}
Hi,

I have the below trigger on Lead which works after the lead is converted.  It takes the name of the new contact thats created and adds it to a field on the opportunity.
How do I go about adjusting this to only fire of the field on opportunity is blank?  I have tried adding somethign to the if statement but its not doing anything as the contact is not created yet
Thanks
trigger LeadTrigger on Lead (after update) {

    if (trigger.isAfter && trigger.isUpdate) {
        List<Opportunity> oppsToUpdate = new List<Opportunity>();

        for (Lead ld : trigger.New) {
            if(ld.isConverted && trigger.OldMap.get(ld.id).isConverted) {
                continue;
            }

            if (ld.ConvertedOpportunityId != null && ld.ConvertedContactId != null) {
                 Opportunity opp = new Opportunity(Id = ld.ConvertedOpportunityId);
                 opp.Primary_Contact__c = ld.ConvertedContactID;
                 oppsToUpdate.add(opp);
            }
        }

        if (!oppsToUpdate.isEmpty()) {
            update oppsToUpdate;
        }
    }

}
Hi
I am trying to write a trigger on opportunity.  Once the opportuntiy is Won, I want to look at the product picklist field on the opportunity and update the corresponding contact roles with checking the checkbox of the product.
i.e. Opportunity is closed won, product on the opportuntiy is a picklist is Product A I want to update a contact role (contact) checkbox field called product A.
So far I ued some old code I tried when I had lots of rollup summary fields and now getting an error that the expression must be of type boolean and not string

trigger Updateproductsbought on Opportunity (after update) {

Set<Id> st_OppId = new Set<Id>();
List<Contact> con_List;

for(Opportunity opp :Trigger.new)
  {
     if(opp.StageName=='Complete - Live' )
         st_OppId.add(opp.id);
 }

if(st_OppId!=null && !st_OppId.isEmpty())
    {

         for(OpportunityContactRole iterating_oppConRole : [SELECT Role, 
                                                             OpportunityId, 
                                                             IsPrimary, 
                                                             Id, 
                                                             ContactId,
                                                             Contact.Order_Routing__c, 
                                                             Contact.Settlements__c,
                                                             Contact.Dividends__c,
                                                             Contact.Transfers__c,
                                                             Contact.Payments__c,
                                                             Contact.Re_registration__c,
                                                             Contact.Reporting_Reconciliations__c,
                                                             Opportunity.CTN_Service__c
                                                             FROM OpportunityContactRole  where OpportunityId IN : st_OppId])
                               {                                                                

                    if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Order Routing')
                        {
                              iterating_oppConRole.Contact.Order_Routing__c = true;
                        }
                    
                     if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Settlements')
                         {
                               iterating_oppConRole.Contact.Settlements__c = true;
                         }
                         
                      if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Dividends')
                        {
                              iterating_oppConRole.Contact.Dividends__c = true;
                        }
                    
                     if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Transfers')
                         {
                               iterating_oppConRole.Contact.Transfers__c = true;
                         }
                         
                      if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Payments')
                        {
                              iterating_oppConRole.Contact.Payments__c = true;
                        }
                    
                     if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Re-registration')
                         {
                               iterating_oppConRole.Contact.Re_registration__c = true;
                         }    
                         
                      if(iterating_oppConRole.Opportunity.CTN_Service__c = 'Reporting_Reconciliations__c')
                         {
                               iterating_oppConRole.Contact.Reporting_Reconciliations__c = true;
                         }                                      

                                       if(con_List == null)
                                           con_List = new List<Contact>();

                                          con_List.add(iterating_oppConRole.Contact);
                                }

               
           }
        
        if(con_List!=null && !con_List.isEmpty())
            update con_List;
}

As I am new to apex any help would be appreciated
Thanks
 
Hi,

I have completed a flow which fires from process builder which is only working in lightning and not fully working in classic!

My flow works after a task is created on an opportunity the task takes all the contacts from that task and adds then as contact roles on the associated opportuntiy.

here is a view of it, seems to work fine adding all the contacts in the task as contact roles in lightning but only adding the first contact in classic...

Any ideas?
User-added image
Hi,

Using a Flow and process Building (assuming its possible) I would like to, once a task is added on an opportuntiy, get all the contacts from that task and then add them to the corresponding opportuntiy as contact roles.  I will try this with events also later on.

How do I do this? do I start, in the flow with a fast lookup to the task object or task relation object and then do I need a Loop and then assignment?
I also want to, once the records have been fetched, either create the contact role on the opportunity with that contact(s) or if it already exists as a contact role, update it

I am struggling and have so far got it to add a single contact, but it also duplicates it if its added again to another task

Thanks