• Justin Julicher
  • NEWBIE
  • 35 Points
  • Member since 2014
  • Senior Salesforce Developer
  • Flight Centre


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
We have a custom object called "Case_Resource__c".

Is there a way to have a trigger run on a monthly basis (say the first of every month) as long as the following critera are true for the Case_Resource__c record:
1. UOM__c = "mo."
2. Active__c = true

And if so, to have that trigger create a new record for a different custom Object "TimeSlip__c" using fields from the Case_Resource__c object?

Again, looking for this trigger to fire automatcially every month and create a new "TimeSlip" so long as the "Case Resource" record has a UOM of "mo.", and is checked active.
  • September 11, 2014
  • Like
  • 0
I'm currently getting this error when trying to compile the following piece of code.

if (objectRecordTypeMap.get(objectName) == null){
    for (RecordType r : [select DeveloperName, Id from RecordType where sObjectType =: objectName]){
     recordTypeMap.put(r.DeveloperName, r.Id);
    }
    objectRecordTypeMap.put(objectName, recordTypeMap);
  } else {
   recordTypeMap = objectRecordTypeMap.get(objectName);
  }

I'm using version 30 of the API and it was compiling just a few days ago... I'm unsure what has changed as I haven't really changed much apart from trying out mavensMate. 

any ideas anyone? 

thanks.
We have a custom object called "Case_Resource__c".

Is there a way to have a trigger run on a monthly basis (say the first of every month) as long as the following critera are true for the Case_Resource__c record:
1. UOM__c = "mo."
2. Active__c = true

And if so, to have that trigger create a new record for a different custom Object "TimeSlip__c" using fields from the Case_Resource__c object?

Again, looking for this trigger to fire automatcially every month and create a new "TimeSlip" so long as the "Case Resource" record has a UOM of "mo.", and is checked active.
  • September 11, 2014
  • Like
  • 0
Hi All - I have a business requirement to attach a pdf document (visualforce rendered as pdf) to Notes and Attachments on a record when that record gets updated.  Since we can't use getContentAsPDF() in the context of a trigger, I am attempting to create a Web Service that will run asyncronously to perform this task.  Thanks go to jungleeforce for this post (http://jungleeforce.wordpress.com/2014/06/11/generate-a-pdf-and-attach-it-to-record-from-a-trigger-in-salesforce-restful/).  With some minor customization tweaks I got this working for a single record update.  However when I perform a bulk load, I am getting the following errror from the FutureHandler Operation (as seen in the Debug Log).  I am calling out from the same org that I am calling into.

10:02:35.245 (245356383)|CALLOUT_RESPONSE|[48]|System.HttpResponse[Status=Unauthorized, StatusCode=401]

I know why I am getting this, but I don't know how to resolve.  I am getting this issue because I am passing userInfo.getSessionId() to the asyncronous @future method.  Since asyncronous processes don't run in a user context I am not getting a session id....hence Status=Unauthorized.

I have tried creating a connected app and using the Consumer Key and Consumer Secret.  I'm not certain if this the correct approach and if so I need to know how to correctly use this Key and Secret.

Here is the trigger and two classes that I'm using to perform this task.

Please advise on how I can get my access code for this asyncronous process.

Thank you very much.

Trigger
trigger pdfAttachTrigger on DealerPlanning__c (after update)
{
list<id>dealerPlanIdList = new list<id>();
map<id,id> dealerPlanAcctMap = new map<id,id>();

for(DealerPlanning__c dealPlan: trigger.new)
{
  dealerPlanIdList.add(dealPlan.id);
  dealerPlanAcctMap.put(dealPlan.id,dealPlan.account__c);
}

DealerPlanTriggerController.addPDFAttach(userInfo.getSessionId(), dealerPlanIdList, dealerPlanAcctMap);
}

Class with @Future Method
global class DealerPlanTriggerController
{
    @Future(callout=true)
    public static void addPDFAttach(string sessionId, list<id> dealerPlanIdList, map<id,id> dealerPlanAcctMap)
    {
       HttpRequest req = new HttpRequest();
       req.setEndpoint('https://'+URL.getSalesforceBaseUrl().getHost()+'/services/apexrest/addPDFtoRecord/');
       req.setMethod('POST');
       req.setBody('{"dealerPlanAcctMap":'+JSON.serialize(dealerPlanAcctMap)+',"dealerPlanIdList":'+JSON.serialize(dealerPlanIdList)+'}');
       req.setHeader('Authorization', 'Bearer '+ sessionId);
       req.setHeader('Content-Type', 'application/json');
       Http http = new Http();
      
       if(!test.isRunningTest())
       {
           HTTPResponse res = http.send(req);
       }
    }
}

Class with @RestResource
@RestResource(urlMapping='/addPDFtoRecord/*')
global with sharing class AddPDFtoRecordREST
{  
  @HttpPost
    global static void doPost(map<String,String> dealerPlanAcctMap, list<String> dealerPlanIdList) {

       list<attachment> insertAttachment = new list<attachment>();
     
        for(String dpId: dealerPlanIdList)
        {
            //create a pageReference instance of the VF page.
            pageReference pdf = Page.PI_Certificate;
            //pass the Account Id parameter to the class.
            pdf.getParameters().put('accountID', dealerPlanAcctMap.get(dpId));
                    
            Attachment attach = new Attachment();
            Blob body;
            if(!test.isRunningTest()){
                body = pdf.getContent();
            }else{
                body=blob.valueOf('TestString');
            }
           
            attach.Body = body;
            attach.Name = 'pdfName'+dpId+'.pdf';
            attach.IsPrivate = false;
            attach.ParentId = dpId;//This is the record to which the pdf will be attached
            insertAttachment.add(attach);
         }
        
         //insert the list
         insert insertAttachment;
    }
}

  • September 11, 2014
  • Like
  • 0
WHat did I do wrong?  I'm unable to dataload any changes.


trigger LOC_on_IP on SVMXC__Installed_Product__c (before insert, before update) {

    List<SVMXC__Installed_Product__c> locationToUpdate = new List<SVMXC__Installed_Product__c>();

    for (SVMXC__Installed_Product__c ip : Trigger.new)
    {    
      if (ip.SVMXC__Company__c != NULL)
      {
          // Find the Loaction for the current Acct
          List<SVMXC__Site__c> loc = [select Loc_ID__c from SVMXC__Site__c
                             where SVMXC__Account__c = :ip.SVMXC__Company__c limit 1];     
               
          // if you found one
          if (loc.size() > 0)
          {   
              //assign the Location to the Accounts Location
              ip.SVMXC__Site__c  = loc[0].Loc_ID__c;
         
              locationToUpdate.add(ip);
         
          }
       }
    }
}
I'm currently getting this error when trying to compile the following piece of code.

if (objectRecordTypeMap.get(objectName) == null){
    for (RecordType r : [select DeveloperName, Id from RecordType where sObjectType =: objectName]){
     recordTypeMap.put(r.DeveloperName, r.Id);
    }
    objectRecordTypeMap.put(objectName, recordTypeMap);
  } else {
   recordTypeMap = objectRecordTypeMap.get(objectName);
  }

I'm using version 30 of the API and it was compiling just a few days ago... I'm unsure what has changed as I haven't really changed much apart from trying out mavensMate. 

any ideas anyone? 

thanks.