• KitaSan
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 15
    Replies
I have an embedded VF page that shows if a lead is suspected to be a potential new contact at an existing customer. There are two formula fields on the lead and contact that contain the email domain. I then have a controller extension that takes the lead email domain and looks for matches in the contact table. 
 
public integer getPotentialCustomers() {
        return [SELECT count() FROM contact WHERE email != null AND Contact_Status__c = 'Active' AND email_domain__c = :lead.email_domain__c  LIMIT 1];
    }

However, that has so search over 120k contacts... so its slow. 

I tried JS remoting it but I run into an error with public classes in an iframe.

I have asked SFDC for custom indexing on the formula fields which should help a bit.. but wondering if there is another method to speed this up. Even just a way to make that SOQL query asynchronous so that the rest of the page loads and then the embedded vf updates. 

-Justin 
Trigger posts a chatter update when 'post to chatter' checkbox is selected. Workflow is causing trigger to fire twice in Prod so change was made in dev (passed tests) but fails on validation in Prod. 

HelperClass: 
public class HelperClass {
   public static boolean firstRun = true;
}



Trigger

trigger newsToChatter on News_Catalyst__c (after update) {
    
Set<ID> newsIds = new Set<ID>();
       for (News_Catalyst__c n : Trigger.new) {
       
        if (trigger.isUpdate && n.Post_to_chatter__c != FALSE && trigger.oldMap.get(n.id).Post_To_Chatter__c != TRUE) {
            if(HelperClass.firstRun){
                newsIds.add(n.ID);
            }
        }
      }
      
      List<News_Catalyst__c> updatedNewsCats = [SELECT Id, News_Description__c, Name, Wordpress_Post_Hyperlink__c FROM News_Catalyst__c WHERE Id in :newsIds];
      
      List<FeedItem> feedItems = new List<FeedItem>();
    
    for (News_Catalyst__c nc : updatedNewsCats){
        // Loop through each Related Deal record
        List<Customer_News_Connector__c> relatedConnectors = [SELECT Id, Account__c, Chatter_Ticker_Tag__c, Customer_News__c FROM Customer_News_Connector__c WHERE Customer_News__c =: nc.Id];
        for(Customer_News_Connector__c connector : relatedConnectors){
            //logic to add chatter posting 
            FeedItem fitem = new FeedItem();

            //what if the description is less than 200 characters?
            Integer i = nc.News_Description__c.replaceAll('<[^>]+>',' ').length();
              if (i > 200) { i = 200;}
            
            fitem.type = 'TextPost';
            fitem.ParentId = connector.account__c;
            fitem.body = '#CustomerNews - '+nc.name + '\n\n' + nc.News_Description__c.replaceAll('<[^>]+>',' ').substring(0,i) +'...' + '\n\n Read More: \n '+nc.Wordpress_Post_Hyperlink__c+'\n\n'  +connector.Chatter_Ticker_Tag__c ;
            feedItems.add(fitem);
            
        }
    }
    //Save the FeedItems all at once.
    if (feedItems.size() != 0) {
        insert(feedItems);
    } 
    //set the helperclass
    HelperClass.firstRun=false;
 }

Test Class: 

@isTest 
private class News_to_Trigger_TestClass {
    
/*
This class tests that checking the Add_to_Chatter__c box creates a chatter posing with details of the activity

+Revision History+
2014 08 29 - Created by Justin Kitagawa        
*/  
   
     static testMethod void testChatterActivity() {
        //create the test account
        Account a = new Account(name='Test Account');
        a.End_User_Number__c = NULL;
        a.RecordTypeId = '012300000004wx8';
        a.Type = 'Prospect';
        a.Site_Type__c = 'Division Headquarters';
        a.Country__c ='United States';
        a.Region__c = 'NAmer';
        a.Primary_Vertical__c = 'Auto';
        a.Primary_Sub_Vertical__c ='Services';
        a.Primary_Industry_Description__c = '4214 - Trucking and storage, local';
        insert a;
        
        //test that no chatter was created
        list<AccountFeed> posts1 = [select ID from AccountFeed where ParentId =: a.id];
        system.assertEquals(0,posts1.size());

        //create a news_catalyst on that account
        News_Catalyst__c n = new News_Catalyst__c(Name = 'Test News');
        n.News_Description__c = 'Aint nobody got time for that';
        n.Post_To_Chatter__c = FALSE;
        insert n;

        //Test if Acount was created
        list<Account> acct = [select id from Account where id = :a.id];
        system.AssertEquals(1,acct.size());

        //Create the connector record
        Customer_News_Connector__c connector = new Customer_News_Connector__c(); 
        connector.Account__c = a.Id; 
        connector.Customer_News__c = n.Id;
        insert connector;
        
        //Test if Customer_News_Connector__c was created
        list<Customer_News_Connector__c> newsConnector = [select id from Customer_News_Connector__c where id = :connector.id];
        system.AssertEquals(1,newsConnector.size());

        //Update the news catalyst so Post_To_Chatter__c = TRUE
        n.Post_To_Chatter__c = TRUE; 
        update n; 

        //Test if News_Catalyst__c was created
        list<News_Catalyst__c> news = [select id from News_Catalyst__c where id = :n.id];
        system.AssertEquals(1,news.size());
        
        //Test if chatter feed was created
        list<AccountFeed> posts2 = [select id from AccountFeed where parentid =: a.id];
        system.assertEquals(1,posts2.size());
        
    }
}


Trigger passes without the HelperClass.firstRun check. 

How is HelperClass.firstRun returning false? 

Any help is greatly appreciated. 
 

  • September 08, 2014
  • Like
  • 0

In our evironment, users can relate opportunities to another opportunity (add on sales) or to a 'vision' (custom object). There are two lookup fields on the opportunity to track this. 

 

Source_Vision__c and Source_Opportunity__c 

 

It is possible that an opportunity is created from another opportunity that was created from a vision. What I would like to do is create a trigger that will populate this relationship so that the newly created opportunity has both the relationship to the original vision, and the source opportunity. 

 

trigger OpportunityTrigger on Opportunity (after insert) {
	for(Opportunity o:Trigger.new){
//Check if Source_Vision__c is null if(o.Source_Opportunity__r.Source_Vision__c.name != null ){

//If not, set Source_Vision__c on new record to Source_Vision of relaated record. o.Source_Vision__c = o.Source_Opportunity__r.Source_Vision__c;} } }

 I am getting an invalid key relationship error (Opportunity.Source_Vision__c)


Am I missing something? 

 

Thanks@

 

I am trying to create a button on the task create that will create a custom object that is automatically associated with the Account that the task is associated with. 

 

On the custom object I have a lookup to Account, but it looks like in order to populate it I need both the account name CF00N80000004rohc= and account ID CF00N80000004rohc_lkid=. 

 

Using just the _lkid value doesnt seem to work... https://na6.salesforce.com/a0Z/e?CF00N80000004rohc_lkid=0018000000kwlAx

and as I am creating from the Task record, I cannot access the account name... 

 

Any help would be GREATLY appreciated! 

Hi Everybody,

 

Major APEX newbie here...

 

Objective: Create an Apex trigger to update the task field "Assigned_Region__c" with the region from the user record "Region__c" (picklist).

 

I have tried to create the trigger... but with no success:

 

Trigger TaskRegion on Task (after insert, after update) {

String URegion = [select region__c from USER where id = 'Owner.Id'];

FOR (Task act:System.Trigger.new) {

'Task.Region__c' = URegion }

}

 

I am probably way off on this... I had originally hoped to just create a look up field into the Assighed User record, but it appears that it is not possible...

 

Thanks for the help!

Justin

Trigger posts a chatter update when 'post to chatter' checkbox is selected. Workflow is causing trigger to fire twice in Prod so change was made in dev (passed tests) but fails on validation in Prod. 

HelperClass: 
public class HelperClass {
   public static boolean firstRun = true;
}



Trigger

trigger newsToChatter on News_Catalyst__c (after update) {
    
Set<ID> newsIds = new Set<ID>();
       for (News_Catalyst__c n : Trigger.new) {
       
        if (trigger.isUpdate && n.Post_to_chatter__c != FALSE && trigger.oldMap.get(n.id).Post_To_Chatter__c != TRUE) {
            if(HelperClass.firstRun){
                newsIds.add(n.ID);
            }
        }
      }
      
      List<News_Catalyst__c> updatedNewsCats = [SELECT Id, News_Description__c, Name, Wordpress_Post_Hyperlink__c FROM News_Catalyst__c WHERE Id in :newsIds];
      
      List<FeedItem> feedItems = new List<FeedItem>();
    
    for (News_Catalyst__c nc : updatedNewsCats){
        // Loop through each Related Deal record
        List<Customer_News_Connector__c> relatedConnectors = [SELECT Id, Account__c, Chatter_Ticker_Tag__c, Customer_News__c FROM Customer_News_Connector__c WHERE Customer_News__c =: nc.Id];
        for(Customer_News_Connector__c connector : relatedConnectors){
            //logic to add chatter posting 
            FeedItem fitem = new FeedItem();

            //what if the description is less than 200 characters?
            Integer i = nc.News_Description__c.replaceAll('<[^>]+>',' ').length();
              if (i > 200) { i = 200;}
            
            fitem.type = 'TextPost';
            fitem.ParentId = connector.account__c;
            fitem.body = '#CustomerNews - '+nc.name + '\n\n' + nc.News_Description__c.replaceAll('<[^>]+>',' ').substring(0,i) +'...' + '\n\n Read More: \n '+nc.Wordpress_Post_Hyperlink__c+'\n\n'  +connector.Chatter_Ticker_Tag__c ;
            feedItems.add(fitem);
            
        }
    }
    //Save the FeedItems all at once.
    if (feedItems.size() != 0) {
        insert(feedItems);
    } 
    //set the helperclass
    HelperClass.firstRun=false;
 }

Test Class: 

@isTest 
private class News_to_Trigger_TestClass {
    
/*
This class tests that checking the Add_to_Chatter__c box creates a chatter posing with details of the activity

+Revision History+
2014 08 29 - Created by Justin Kitagawa        
*/  
   
     static testMethod void testChatterActivity() {
        //create the test account
        Account a = new Account(name='Test Account');
        a.End_User_Number__c = NULL;
        a.RecordTypeId = '012300000004wx8';
        a.Type = 'Prospect';
        a.Site_Type__c = 'Division Headquarters';
        a.Country__c ='United States';
        a.Region__c = 'NAmer';
        a.Primary_Vertical__c = 'Auto';
        a.Primary_Sub_Vertical__c ='Services';
        a.Primary_Industry_Description__c = '4214 - Trucking and storage, local';
        insert a;
        
        //test that no chatter was created
        list<AccountFeed> posts1 = [select ID from AccountFeed where ParentId =: a.id];
        system.assertEquals(0,posts1.size());

        //create a news_catalyst on that account
        News_Catalyst__c n = new News_Catalyst__c(Name = 'Test News');
        n.News_Description__c = 'Aint nobody got time for that';
        n.Post_To_Chatter__c = FALSE;
        insert n;

        //Test if Acount was created
        list<Account> acct = [select id from Account where id = :a.id];
        system.AssertEquals(1,acct.size());

        //Create the connector record
        Customer_News_Connector__c connector = new Customer_News_Connector__c(); 
        connector.Account__c = a.Id; 
        connector.Customer_News__c = n.Id;
        insert connector;
        
        //Test if Customer_News_Connector__c was created
        list<Customer_News_Connector__c> newsConnector = [select id from Customer_News_Connector__c where id = :connector.id];
        system.AssertEquals(1,newsConnector.size());

        //Update the news catalyst so Post_To_Chatter__c = TRUE
        n.Post_To_Chatter__c = TRUE; 
        update n; 

        //Test if News_Catalyst__c was created
        list<News_Catalyst__c> news = [select id from News_Catalyst__c where id = :n.id];
        system.AssertEquals(1,news.size());
        
        //Test if chatter feed was created
        list<AccountFeed> posts2 = [select id from AccountFeed where parentid =: a.id];
        system.assertEquals(1,posts2.size());
        
    }
}


Trigger passes without the HelperClass.firstRun check. 

How is HelperClass.firstRun returning false? 

Any help is greatly appreciated. 
 

  • September 08, 2014
  • Like
  • 0

In our evironment, users can relate opportunities to another opportunity (add on sales) or to a 'vision' (custom object). There are two lookup fields on the opportunity to track this. 

 

Source_Vision__c and Source_Opportunity__c 

 

It is possible that an opportunity is created from another opportunity that was created from a vision. What I would like to do is create a trigger that will populate this relationship so that the newly created opportunity has both the relationship to the original vision, and the source opportunity. 

 

trigger OpportunityTrigger on Opportunity (after insert) {
	for(Opportunity o:Trigger.new){
//Check if Source_Vision__c is null if(o.Source_Opportunity__r.Source_Vision__c.name != null ){

//If not, set Source_Vision__c on new record to Source_Vision of relaated record. o.Source_Vision__c = o.Source_Opportunity__r.Source_Vision__c;} } }

 I am getting an invalid key relationship error (Opportunity.Source_Vision__c)


Am I missing something? 

 

Thanks@

 

Hello.  I have a quick question for the group.

 

I have a text area field that is being populated by a line of code in the controller.  Since this is a text area field, I know line breaks can be used.  The force.com interface would allow me to insert a break in this line by specifying the formula BR()...but this command does not work in Apex.

 

Does anyone know how to do this?  In short, I want to combine the Name, hours, months and days fields together to form the below phrase.  For reasons that are too long to explain in this forum, I cannot make this two separate variables...my goal is to use a line break.

 

Fred can contribute 3200 hours across 12 months.

He has 12 days that are no-go's.

 

x.setLongPhrase(zzz.Name__c + ' can contribute ' + zzz.Hours__c + ' hours across ' + zzz.months__c + ' months.  He has ' + Days__c + ' days that are no-go's.'

 

My goal is to figure out what code I can insert prior to the "He has" text so a line break will be forced.

 

 

Thanks in advance for any thoughts.

I added a picklist value "Test PL" to the Standard field Type in Task object. I don't have any default value set for the picklist. now if I try to delete the value "Test PL", it is giving me error "This picklist must contain at least one default value."  Is there any other way I can delete the picklist value. however I am able to this for any custom picklist field. but not able to do for this particular field. please advice.

 

Thanks in advance

RS

I have a trigger set up on an object to trigger after an update.  If I do the update manually it works just fine.  However, if I do a mass update using the Data Loader the trigger doesn't get invoked.
 
Is there a way to force the trigger while using the Apex Data Loader?
  • November 18, 2008
  • Like
  • 0
Hi everyone,

Is that possible to remove None from a picklist?