• Jos Vervoorn 2
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 15
    Replies

We have custom apex trigger running on Opportunity Line item. This will generate line item schedule for any given line items matching conditions.

The Clone opportunity with related function also allows to clone opportunity with products and schedule .... so when using this function my trigger kicks in and creates a secundairy schedule which .. will give twice the revenue .... Now I would like to prevent the trigger from firing but then I need to know if the opportunity is created by this function. 

So .. is there a way to determine the opp and it's items are created thru this function ...
 

I have s custom object containing a Product2 Lookup and several other fields like for example the stock volume. This data is originated from another system.

Based on this custom object I like to show a table (VF) to expose the product name and some other details ... but I would also like to show the price coming from a dedicated Pricebook with entries.

So basically I would like to join the custom object with price book entry filtered on the currency. The join should be done on the mutual product lookup. Can this be done through mapping?

when using global search ... the files section only returns the technical details on the files found. But I like to expose some custom fields like which account the file is attached to etc. Now I know I can create custom fields ... but it does not allow me to create custom fields on the content version. Maybe I could create/populate some custom fields thru Apex trigger but I'm not sure if anyone already walked this path.

Honestly ... attachments were much more flexible in this.
I'm running a scheduled batch but I like to clean up the rows from previous runs during the day. So from the schedule, I call the batch with the JobId as a string parameter. So far good. But then I need to select all rows not having the jobId__c with the same value (parameter) and it does not work. It affects all rows and not only the ones with the JobId having the same value as the parameter.
We are trying to implement a solution which uses the Streaming API, but we are running into a problem in which if we try to start the subscription from a replayID which is older than 24h it won’t work.

Currently, we are using jsforce (Node.JS) SDK and if you log the message exchange between server and client we get the error that the provided replayId is invalid and that we should use -2 or -1, the thing is that this error does not throw an exception or notifies the handler in any way.

So from your perspective how should we tackle this problem? From our side we could only work on forking the client project, then we could do these modifications and later make a PR, but it would be much better if something would be done from the server side such as supporting replayIDs older than 24H of age.

Thanks in advance.
I wrote a fairly simple trigger on the ContentVersion object which ultimately would allow tracking opportunities without a signed contract. 

So a document is added or changed and the picklist value 'Signed Contract' is selected. This would flip the 'HasSignedQuote__c' bollean on true on the opportunity. 

However I noticed that the LinkedEntityId from the ContentDocumentLink is not always populated and I can't get my finger behind the root cause.
 
trigger ContentVersion_TRIGGER on ContentVersion (After insert, After update) {

      
    Public static Boolean SignedContract = false;

    System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - TRIGGER ');
    

        Set<Id> contentDocumentIdSet = new Set<Id>();
        for(ContentVersion cv:trigger.new){

            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
                If(cv.File_Type__c == 'Signed Contract'){ //** Based on Content version picklist ...
                   System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Set SignedContract = true');   
                   SignedContract = true;
                }
            }
        }
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].contentDocumentIdSet'+contentDocumentIdSet);   
        ContentDocumentLink cdl = [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN:contentDocumentIdSet Limit 1];
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].ContentDocumentLink  :'+cdl.LinkedEntityId);      
        List<Opportunity> OppList = [SELECT Id, HasSignedQuote__c FROM Opportunity where Id =:cdl.LinkedEntityId];  
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].OppList.size() :'+OppList.size());  
        For (Opportunity Opp:OppList){
            If (SignedContract == true){
                System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Flag opportunity HasSignedQuote to true ...');   
                Opp.HasSignedQuote__c = true;
            }
        }
        Update OppList;
   
} //** end of Class

 
I try to get a table populated with .. target versus actuals per year/month based on quota and line item schedule revenue value

I have created to Lists. One of Quotas (Sales targets) and another on Opportunity Line Item schedule.and I'working with a nested loop (forgive me the inefficiency) ....
For (OpportunityLineItemSchedule OppS:LineItemSchedList){
      For (ForecastingQuota FQ:MyForeCastquotaList){

        If ((FQ.StartDate.Year() == OppS.ScheduleDate.Year()) && (FQ.StartDate.Month() == OppS.ScheduleDate.month()){
           LineCounter = LineCounter  + 1;

           System.debug(LoggingLevel.Info,'[******] --------------------------------------------------');
           System.debug(LoggingLevel.Info,'[******] Month          ..: '+FQ.StartDate.Month());
           System.debug(LoggingLevel.Info,'[******] FQ.Currency    ..: '+FQ.currencyisocode);
           System.debug(LoggingLevel.Info,'[******] FQ.QuotaAmount ..: '+FQ.QuotaAmount);
           System.debug(LoggingLevel.Info,'[******] FQ.Owner       ..: '+FQ.quotaOwner.Name);
           System.debug(LoggingLevel.Info,'[******] Item Revenue   ..: '+OppS.Revenue);
           System.debug(LoggingLevel.Info,'[******] LineCounter    ..: '+LineCounter);           
        }
      }
   }

So ultimately want to have a sum on OppS.Revenue per month/year ..... but for some reason I'm not getting this to work. Now you may wander why i'm not using aggregate list ... well ... it's simple ... convertCurrency(QuotaAmount) is not allowed on aggregate and on a multi currency I need to make sure all quota's and actuals are in singular (read EUR) currency.

Once I have this I will insert the rows (target/actuals) in a table so I can simply report on this and schedule a job to (auto) populate and refresh the table ... 

Any help / direction is much appreciated ....

 
I'm using substring to extract valid user timezone picklist values using below code. It does match .. but I get to results.
String text= 'Australian Central Standard Time ((South Australia) Australia/Adelaide)';

String RegEx = '(\\w+[/]\\w+[/]?\\w+)||GMT';
Pattern regexPattern = Pattern.compile(regex);
Matcher mymatcher= regexPattern.matcher(text);
If (myMatcher.find()){
  system.debug(LoggingLevel.Info,'*** Match ' + myMatcher.group());
}
What I expect in the log is Australia/Adelaide. The RegEx seems ok ... https://regexr.com/43hi9

Looking for a way to adjust the branding of the community consent page (image below) or how to implement a custom page (if possible). Any kind of support/direction is much appreciated. 

This dialog is presented after login to approve/grant access to various types of information from Salesforce. We use Salesforce as the identity provider for another (connected) community.
User-added image
While performing validation on my Apex Trigger & helper class I run into the following error:

Static method cannot be referenced from a non static context: void OpportunityLineItemTriggerHandler.AutoScheduleLineItemsAfterUpdate(List<OpportunityLineItem>, Map<Id,OpportunityLineItem>)

Now in test sandbox ... I did not run into this error .. so I'm not sure why in production it fails ...
Trigger code:
OpportunityLineItemTriggerHandler updater = new OpportunityLineItemTriggerHandler();

Apex class code (first x lines ......)
Public void AutoScheduleLineItemsAfterInsert(List<OpportunityLineItem> NewOppLineItems)
  {
     System.debug('** * ** #20 AutoScheduleLineItemsAfterInsert');
     //** Get prepped by retrieving the base information needed for generating schedule
     Date currentDate;             
     Decimal NumberOfInstallments; //**Decimal numberPayments;
     Decimal paymentAmount;
     Decimal totalPaid;
     String ItemDescription;
      
     NumberOfInstallments = 1; //** Ensure default value for installments even when no value provided.
          
     //** Generate lists for bulkify on OpportunityItems etc. 
     set<id> oppid = new set<id>();
     List<Id> oppLineIdsList = new List<Id>();
     List<OpportunityLineItemSchedule> newScheduleObjects = new List<OpportunityLineItemSchedule>();
     
     //** Assign (new) added ID values to variables
     for (OpportunityLineItem ol : NewOppLineItems) {
          oppLineIdsList.add(ol.id);
          oppid.add(ol.opportunityid);
     }
     //** Create (parent) opportunity list so we have required into to retrieve account based product (pricebook) values.
     list<opportunity> opplist = [select id, AccountID,CurrencyIsoCode from opportunity where id in : oppid ];
     
    for (opportunity opp: opplist) {
         //** So we have all we need. Account, Opportunity currency and ProductID
         system.debug('** * ** #44 AccountID: '+opp.AccountID);
         system.debug('** * ** #45 Opportunity Currency: '+opp.CurrencyIsoCode);
           
         //** For every OpportunityLineItem record, add its associated pricebook entry
         //** to a set so there are no duplicates.
         Set<Id> pbeIds = new Set<Id>();             //** PriceBookEntryID
         for (OpportunityLineItem oli : NewOppLineItems) 
            //** pbeIds.add(oli.pricebookentryid);
            pbeIds.add(oli.id);
            //** For every OpportunityLineItem record, add its associated oppty
            //** to a set so there are no duplicates.
            Set<Id> opptyIds = new Set<Id>();
            for (OpportunityLineItem oli : NewOppLineItems) 
                 opptyIds.add(oli.OpportunityId);

Thanks in advance.
 
While creating a 'simple' Lightning QuickAction to update case date/time field I get this unexpected token case.
({
   StartTiming: function(component, event, helper) {
        console.log('save:1');
        var action = component.get("c.case");
        action.setParams({"case": case  });
   }
})
Some help to overcome this would be great. Now the controller is not finished but I need to overcome this issue first.

Many thanks on advance.
 
I'm working on a controller to list case related email.I'm struggling to get the SOQL query to limit results based on ParentID = case.id.

Without this everything works just fine.as a 'related' email list on the case page layout. What do I miss of what is wrong ?

The code of the controller:

public class CaseEmailListController {

    public CaseEmailListController(ApexPages.StandardController controller) {

    }

private ApexPages.StandardController stdCtrl {get; set;}
public List<Case> Cases {get; set;}

// Sorting on CreatedDate and ToAddress
private String sortOrder = 'CreatedDate';
public void sortByCreatedDate() {
    this.sortOrder = 'CreatedDate';
}  
public void sortByToAddress() {
    this.sortOrder = 'ToAddress';
}
    
public Case   ourCase {get; set;}
public List<EmailMessage> getCaseEmail() {

  List<EmailMessage> results = Database.query(
      'SELECT CreatedDate, FromAddress,HasAttachment,Id,ParentId,Subject,TextBody,ToAddress ' +
      'FROM EmailMessage ' + 'WHERE ParentID=:' + Case.ID +
      ' ORDER BY ' + sortOrder + ' ASC ' +
      'LIMIT 10'
    );

return results;
}
}
I'm running a scheduled batch but I like to clean up the rows from previous runs during the day. So from the schedule, I call the batch with the JobId as a string parameter. So far good. But then I need to select all rows not having the jobId__c with the same value (parameter) and it does not work. It affects all rows and not only the ones with the JobId having the same value as the parameter.
I wrote a fairly simple trigger on the ContentVersion object which ultimately would allow tracking opportunities without a signed contract. 

So a document is added or changed and the picklist value 'Signed Contract' is selected. This would flip the 'HasSignedQuote__c' bollean on true on the opportunity. 

However I noticed that the LinkedEntityId from the ContentDocumentLink is not always populated and I can't get my finger behind the root cause.
 
trigger ContentVersion_TRIGGER on ContentVersion (After insert, After update) {

      
    Public static Boolean SignedContract = false;

    System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - TRIGGER ');
    

        Set<Id> contentDocumentIdSet = new Set<Id>();
        for(ContentVersion cv:trigger.new){

            if(cv.ContentDocumentId != null){
                contentDocumentIdSet.add(cv.ContentDocumentId);
                If(cv.File_Type__c == 'Signed Contract'){ //** Based on Content version picklist ...
                   System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Set SignedContract = true');   
                   SignedContract = true;
                }
            }
        }
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].contentDocumentIdSet'+contentDocumentIdSet);   
        ContentDocumentLink cdl = [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN:contentDocumentIdSet Limit 1];
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].ContentDocumentLink  :'+cdl.LinkedEntityId);      
        List<Opportunity> OppList = [SELECT Id, HasSignedQuote__c FROM Opportunity where Id =:cdl.LinkedEntityId];  
        System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER].OppList.size() :'+OppList.size());  
        For (Opportunity Opp:OppList){
            If (SignedContract == true){
                System.debug(LoggingLevel.Info,'[ContentVersion_TRIGGER]. - Flag opportunity HasSignedQuote to true ...');   
                Opp.HasSignedQuote__c = true;
            }
        }
        Update OppList;
   
} //** end of Class

 
I'm using substring to extract valid user timezone picklist values using below code. It does match .. but I get to results.
String text= 'Australian Central Standard Time ((South Australia) Australia/Adelaide)';

String RegEx = '(\\w+[/]\\w+[/]?\\w+)||GMT';
Pattern regexPattern = Pattern.compile(regex);
Matcher mymatcher= regexPattern.matcher(text);
If (myMatcher.find()){
  system.debug(LoggingLevel.Info,'*** Match ' + myMatcher.group());
}
What I expect in the log is Australia/Adelaide. The RegEx seems ok ... https://regexr.com/43hi9
Seeking a way to update case field after milestone processing. We have tried several options like flow with process builder, apex trigger (with/without @Future annotation) but ... whatever we try .... case field is not updated.

To sketch the scenario:
On the case, we would like to have a field to contain the deadline for the active milestone. So when we complete the current milestone ... this custom field get's populated with the deadline.

Now we can do this whenever a field update on the case has been performed ... but it seems that milestone processing takes place after triggers and after process builder. I have seen some samples out there but  ... I'm having a hard time to get this working while it sounds so easy.

 - milestone is completed / case deadline is populated by next milestone

All help & support is much appreciated.
While performing validation on my Apex Trigger & helper class I run into the following error:

Static method cannot be referenced from a non static context: void OpportunityLineItemTriggerHandler.AutoScheduleLineItemsAfterUpdate(List<OpportunityLineItem>, Map<Id,OpportunityLineItem>)

Now in test sandbox ... I did not run into this error .. so I'm not sure why in production it fails ...
Trigger code:
OpportunityLineItemTriggerHandler updater = new OpportunityLineItemTriggerHandler();

Apex class code (first x lines ......)
Public void AutoScheduleLineItemsAfterInsert(List<OpportunityLineItem> NewOppLineItems)
  {
     System.debug('** * ** #20 AutoScheduleLineItemsAfterInsert');
     //** Get prepped by retrieving the base information needed for generating schedule
     Date currentDate;             
     Decimal NumberOfInstallments; //**Decimal numberPayments;
     Decimal paymentAmount;
     Decimal totalPaid;
     String ItemDescription;
      
     NumberOfInstallments = 1; //** Ensure default value for installments even when no value provided.
          
     //** Generate lists for bulkify on OpportunityItems etc. 
     set<id> oppid = new set<id>();
     List<Id> oppLineIdsList = new List<Id>();
     List<OpportunityLineItemSchedule> newScheduleObjects = new List<OpportunityLineItemSchedule>();
     
     //** Assign (new) added ID values to variables
     for (OpportunityLineItem ol : NewOppLineItems) {
          oppLineIdsList.add(ol.id);
          oppid.add(ol.opportunityid);
     }
     //** Create (parent) opportunity list so we have required into to retrieve account based product (pricebook) values.
     list<opportunity> opplist = [select id, AccountID,CurrencyIsoCode from opportunity where id in : oppid ];
     
    for (opportunity opp: opplist) {
         //** So we have all we need. Account, Opportunity currency and ProductID
         system.debug('** * ** #44 AccountID: '+opp.AccountID);
         system.debug('** * ** #45 Opportunity Currency: '+opp.CurrencyIsoCode);
           
         //** For every OpportunityLineItem record, add its associated pricebook entry
         //** to a set so there are no duplicates.
         Set<Id> pbeIds = new Set<Id>();             //** PriceBookEntryID
         for (OpportunityLineItem oli : NewOppLineItems) 
            //** pbeIds.add(oli.pricebookentryid);
            pbeIds.add(oli.id);
            //** For every OpportunityLineItem record, add its associated oppty
            //** to a set so there are no duplicates.
            Set<Id> opptyIds = new Set<Id>();
            for (OpportunityLineItem oli : NewOppLineItems) 
                 opptyIds.add(oli.OpportunityId);

Thanks in advance.
 
While creating a 'simple' Lightning QuickAction to update case date/time field I get this unexpected token case.
({
   StartTiming: function(component, event, helper) {
        console.log('save:1');
        var action = component.get("c.case");
        action.setParams({"case": case  });
   }
})
Some help to overcome this would be great. Now the controller is not finished but I need to overcome this issue first.

Many thanks on advance.
 
I'm working on a controller to list case related email.I'm struggling to get the SOQL query to limit results based on ParentID = case.id.

Without this everything works just fine.as a 'related' email list on the case page layout. What do I miss of what is wrong ?

The code of the controller:

public class CaseEmailListController {

    public CaseEmailListController(ApexPages.StandardController controller) {

    }

private ApexPages.StandardController stdCtrl {get; set;}
public List<Case> Cases {get; set;}

// Sorting on CreatedDate and ToAddress
private String sortOrder = 'CreatedDate';
public void sortByCreatedDate() {
    this.sortOrder = 'CreatedDate';
}  
public void sortByToAddress() {
    this.sortOrder = 'ToAddress';
}
    
public Case   ourCase {get; set;}
public List<EmailMessage> getCaseEmail() {

  List<EmailMessage> results = Database.query(
      'SELECT CreatedDate, FromAddress,HasAttachment,Id,ParentId,Subject,TextBody,ToAddress ' +
      'FROM EmailMessage ' + 'WHERE ParentID=:' + Case.ID +
      ' ORDER BY ' + sortOrder + ' ASC ' +
      'LIMIT 10'
    );

return results;
}
}
Hi guys, the quote template has lots of limitations when it comes to styling; I would like to do something custom and need a step-by-step guide. Basically, I would like a "create quote" button on quote pagelayout that references my visualforce page and creates the pdf. 

So I think I need to follow the steps below:
1. Create a custom controller class. Can I do this with standard List controller? Basically, I have to query all the quote and quotelineitems
2. Create a new visual force page using controller from step1, add the proper styling and render as pdf.
3. Create the button on quote with a link to visual force page
Any tips and guides are appreciated. 
Thanks.

Did I miss anything? 
 
  • October 17, 2016
  • Like
  • 0
I am trying to find a way to send emails from Salesforce1 and I think the only way might be to make a VF page of the Send Email page.  I need to be able to use email templates and preview it.