• Will Crowley 6
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I'm having trouble getting my head around returning the ID of a newly created record & inserting it into a field on the original object.  I'm trying to automatically create a campaign from a custom object (Listing__c) (which is working) but I've tried various ways of inserting the campaign ID into the Campaign__c field on the Listing and it's just not working.  

Can someone help me out?

Current Trigger:
trigger CreateCampaign on Listing__c (after insert)
 {

// Create Associated Campaign when Listing is Created
 
    List<Campaign> CampaignInsert=new List<Campaign>();
    for(Listing__c L: trigger.new)
 


 CampaignInsert.add(new Campaign(
                                  Name=L.Deal_Name__c,
                                  Type='Email - Property Listing',
                                  IsActive=True,
                                  Status='New'                                                                                                     
                                                    ));
 }   
    try{
    if(CampaignInsert != Null){
          insert CampaignInsert;          
    }
    }Catch(Exception e){
        System.debug('Exception ****'+e.getMessage());
        System.debug(Campaign.id);
     }
}
I am trying to create a report that puts Opportunities into specific groups based on their current status and whether it has ever been in that status. For example, I want to have groupings of "New Deal", "Resurfaced Deal", "Dropped Deal", and "Terminated".  

New Deals would be in a status of "Contract Received" and have never been in "Contract Received".  Resurfaced Deals would be in a status of "Contract Received" and have been in a status of "Contract Received".  Dropped Deals would have been in the status of "Contract Received" but now are in any status other than "Terminated' or "Contract Received".

I've got a field added to capture what group I want them to show up in but I'm struggling with how to build the logic to set the status based on field history of the Status field.  
I'm having trouble getting my head around returning the ID of a newly created record & inserting it into a field on the original object.  I'm trying to automatically create a campaign from a custom object (Listing__c) (which is working) but I've tried various ways of inserting the campaign ID into the Campaign__c field on the Listing and it's just not working.  

Can someone help me out?

Current Trigger:
trigger CreateCampaign on Listing__c (after insert)
 {

// Create Associated Campaign when Listing is Created
 
    List<Campaign> CampaignInsert=new List<Campaign>();
    for(Listing__c L: trigger.new)
 


 CampaignInsert.add(new Campaign(
                                  Name=L.Deal_Name__c,
                                  Type='Email - Property Listing',
                                  IsActive=True,
                                  Status='New'                                                                                                     
                                                    ));
 }   
    try{
    if(CampaignInsert != Null){
          insert CampaignInsert;          
    }
    }Catch(Exception e){
        System.debug('Exception ****'+e.getMessage());
        System.debug(Campaign.id);
     }
}
I am trying to create a report that puts Opportunities into specific groups based on their current status and whether it has ever been in that status. For example, I want to have groupings of "New Deal", "Resurfaced Deal", "Dropped Deal", and "Terminated".  

New Deals would be in a status of "Contract Received" and have never been in "Contract Received".  Resurfaced Deals would be in a status of "Contract Received" and have been in a status of "Contract Received".  Dropped Deals would have been in the status of "Contract Received" but now are in any status other than "Terminated' or "Contract Received".

I've got a field added to capture what group I want them to show up in but I'm struggling with how to build the logic to set the status based on field history of the Status field.