• jd_06
  • NEWBIE
  • 20 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 22
    Replies
Hi All - We have a situation where we have a public website (not a SF Site) where we capture lead information - web to lead.  When the lead gets inserted to SF we are generating a promotion code and emailing that code to the lead...everything works fine.  However, our business partners would like that code sent back to the page and displayed on the thank you.  The thank you is not a VF page.

Does anyone have any experience passing data back to a non VF page using web to lead?

Any information you can share would be greatly appreciated.

Thank you.
  • June 01, 2015
  • 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
Hello - I need some assistance from the great minds in the SFDC dev community.  I've been asked to automatically add the count of Opportunity Team Members to a field on the Opportunity (basically just a roll-up).  For the most part this can't be done declaratively, so created a trigger.  The Non-Bulkified version of the trigger is very simple.  However, I can't see a way with collections (maps, lists, etc.) to bulkify it and keep my SOQL out of the For Loop.  Can anyone offer any ideas or suggestions as to how I could bulkify and keep the query out of a loop?  Here is my trigger code.


Thank you very much!
Jason

trigger CountOppTeam on OpportunityTeamMember (after insert, after delete)
{
List<Opportunity> oppList = new List<Opportunity>();
set<Id>oppIds = new set<Id>();

if(Trigger.isInsert || Trigger.isUpdate)
{
  List<id> oppId = new List<id>();
  for (OpportunityTeamMember oppTm: trigger.new)
  {
   oppIds.add(oppTm.OpportunityId);
  }

  for(Opportunity o: [Select id, CountTeamMembers__c From Opportunity Where id IN: oppIds])
  {
   List<OpportunityTeamMember> oppTmList = [Select id, Opportunityid From OpportunityTeamMember Where Opportunity.id =: o.id];
   o.CountTeamMembers__c = oppTmlist.Size();
   oppList.add(o);
  }

  update oppList;
}
else if (Trigger.isDelete)
{
  List<id> oppId = new List<id>();
  for (OpportunityTeamMember oppTm: trigger.old)
  {
   oppIds.add(oppTm.OpportunityId);
  }

  for(Opportunity o: [Select id, CountTeamMembers__c From Opportunity Where id IN: oppIds])
  {
   List<OpportunityTeamMember> oppTmList = [Select id, Opportunityid From OpportunityTeamMember Where Opportunity.id =: o.id];
   o.CountTeamMembers__c = oppTmlist.Size();
   oppList.add(o);
  }

  update oppList;
}
}
  • August 02, 2014
  • Like
  • 1
Hi All -
Here is my situation.  I am doing some work for a small company.  They were out of liscenses.  They just got a new liscense in production for an SFDC developer (me).  They just refreshed their partial sanbox a couple days ago and are not eligible for a refresh.

They are going to manually add another user account in the Sandbox for me.  Obviously my user ids are going to be different in the Sandbox and Production.  My sandbox user id will not exist in production.

Am I correct in that I will not be able to migrate any changes I make in the Sandbox to Production due to the fact that my Sandbox User Id is not in Production?

If so, has anyone else ran into this issue and how did you work around it?

Thank you
Jason

  • July 28, 2014
  • Like
  • 0
Hi All - I am troubleshooting an issue with a visualforce redirect to a Conga Merge URL.  I have a custom save button on my page.  When user clicks the button I call a method in the controller that performs several actions.  At the end of the method I return the pagereference.  

What I'm finding is that after I instantiate the PageReference with a URL the resulting reference is different.

Here is my example:  Again this is just for troubleshooting purposes.  This is not my actual URL, my main question is why the url is getting modified.

PageReference ref = new PageReference('https://www.appextremes.com/apps/Conga/PM.aspx?SessionId=00DR0000001tYhK%21AQ0AQMPOzH5tBpCxtW_UfXfHoGV5PK4G2FPYVeXbgJQMyNXA04ukVuMy7WkF4ZfA6D8Are43sfTxIwaD9uxBReE0N4rUJrpy&ServerUrl=https%3A%2F%2Fcs2.salesforce.com%2Fservices%2FSoap%2Fu%2F8.0%2F00DR0000001tYhK&Id=0065000000M0zpq&TemplateId=a0M50000000QzTl&ReportId=00O50000002keBY?pv0=T33367&ReportId=00O50000002keBd?pv0=T33367&ReportId=00O50000002keBi?pv0=T33367&ReportId=00O50000002keBn?pv0=T33367&lg0=0&lg1=ALI%20Project%20Discount%20Form%20Generated&OFN=Discount+form+Calabrese+Res+5%2F27%2F2014&lg4=1&ds7=2&EmailRelatedToId=0065000000M0zpq&CETID=a1D50000000C7d4&EmailToID=+&lg3=1&MFTSId0=a0aR0000004tY1s&MFTS0=SpecialDiscountCode__c&MFTSValue0=Created&FP0=1');

If I include a system debug right here for the value of ref it is the following

https://www.appextremes.com/apps/Conga/PM.aspx?CETID=a1D50000000C7d4&ds7=2&EmailRelatedToId=0065000000M0zpq&EmailToID=+&FP0=1&Id=0065000000M0zpq&lg0=0&lg1=ALI+Project+Discount+Form+Generated&lg3=1&lg4=1&MFTS0=SpecialDiscountCode__c&MFTSId0=a0aR0000004tY1s&MFTSValue0=Created&OFN=Discount+form+Calabrese+Res+5%2F27%2F2014&ReportId=00O50000002keBY%3Fpv0%3DT33367&ServerUrl=https%3A%2F%2Fcs2.salesforce.com%2Fservices%2FSoap%2Fu%2F8.0%2F00DR0000001tYhK&SessionId=00DR0000001tYhK%21AQ0AQMPOzH5tBpCxtW_UfXfHoGV5PK4G2FPYVeXbgJQMyNXA04ukVuMy7WkF4ZfA6D8Are43sfTxIwaD9uxBReE0N4rUJrpy&TemplateId=a0M50000000QzTl

Notice the difference between what I put into the Reference and what is coming out of it.

Can someone please explain why my URL is getting changed?

Thank you very much.
Jason
  • May 27, 2014
  • Like
  • 0
Hi All - I'm somewhat familiar with the Non-Selective query problem, however, this one has got me stumpped.  My company has a full sandbox and I have my own development sandbox.  The same piece of code in our Full Sandbox and Production is causing a non-selective query in my dev sandbox.  No issue at all in Full SB or Production.

The query is as follows:  Note that this is in an After Update / After Insert Opportunity Trigger helper class.

for(CampaignMember cm: [SELECT id, ContactId FROM CampaignMember WHERE Campaign.Id =: campaignId])
{
    existingCampMembers.add(cm.ContactId);
}

I have one campaign member on one campaign in my dev sandbox.....that's it!!

If I execute query in developer console it returns the record.  If I execute anonymous, it finds the record no problem.  Also, if I were to change the filter to specify a contactid instead of campaign.id I do not get non-selective error.  So clearly there is something going on with Campaign.Id, but why here and not in Full SB or Production?

So does anyone have any ideas as to why I'm getting a non-selective query in my dev sandbox but not full sb or production?

Thank you in advance for any suggestions.

Jason

Below is the complete error message.

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Class.OpportunityTriggerLogic.addCampMbrToBldrPrgm: line 79, column 1
  • May 06, 2014
  • Like
  • 0
Hi All - I am new to the SFDC Migration Tool and am having issues with circular dependencies when performing a validation.  The issue is with a VF Controller and a VF page.  These are not new files,  I am making updates to both.  In the controller I have deprecated some getter methods and have added new ones.  I have updated the page accordingly, removing references to the old and adding references to the new.

I have included both of these files (controller & page) in my package.xml.  When validating I get an error telling me that the page is looking for one of the deprecated methods eventhough the updated page that I am deploying does not reference that method (I have checked...and double checked).

Obviously if I try just deploying the new page I get an error telling me that the updated VF page references methods that are not in the controller.

I believe that I can come up with an ugly multistep workaround, but wondering if others have a more elegant way of handling this scenario?

Thank you for any information that you could provide.

Jason
  • January 10, 2014
  • Like
  • 0

Hello - The company I work for has an integration with a .NET application that updates Account records on a nightly basis.  The business wants the Account records updated on a more frequent basis.  However when we try to update the records more frequently we run into the issue of getting locked records, particularly during business hours, which prevents the record updates.

 

Our integration uses Informatica to map the data and update records.  Informatica allows us to use the Bulk API to update records (for those that know Informatica, it's a checkbox on the Session).  The advantage of using the Bulk API is that it runs asynchronously.  By running asynchronously, we would/should avoid our locked record issues.

 

My question is, is there any ill side effects of running Bulk API despite not having large record sets?  Our record sets would probably be in the 5 to 10 range every time the job runs.

 

...or are there any other options for running a frequent integration asynchronously to avoid record locks?

 

Any advice or knowledge share would be greatly appreciated.

 

Thank you

Jason

  • September 23, 2013
  • Like
  • 0

Hello - I've been banging my head too long on this one.  I'm trying to show a shadowbox of the claim activity when user clicks on the outputlink.  When I click on link nothing happens.  I've noticed that when I hover over the outputlink for a given claim the path shown in IE8 (lower left hand corner) looks something like

 

javascript&colon;showClaim(&#34;/a1NRxxxxxxxxxxxx&#34;,%20&#34;B-000008%20Quick%20View&#34;);

 

It should show up as

 

javascript&colon;showClaim("a1NRxxxxxxxxxxxx", "B-000008 Quick View");

 

The quot is for some reason getting passed as ascii....or so it seems.

 

Please share any thoughts and/or ideas.  Thank you!

 

function showClaim(src, title) {

 

     var box = new parent.SimpleDialog("hersh"+Math.random(), true);

     parent.box = box;

     box.setTitle(title);

     box.createDialog();

     box.setWidth(850);

     src='<a href=\"#\" onclick=\"box.hide();\">Close</a><br/><br/><p><iframe src="' + src + '" style="border:0; width:810px; min-height:           600px"></iframe></p>'

     box.setContentInnerHTML(src);

     box.setupDefaultButtons();

      box.show();

    if( 0 > 0 )

    setTimeout("box.hide();",0);

}

 

Here is my outputpannel

 

<

apex:outputpanelid="DuplicateClaimTable">

     <apex:pageblocksectiontitle="Possible Duplicate Claims"columns="1"rendered="{!dupeClaimToggle}">

          <apex:pageBlockTablevalue="{!dupeClaimList}"var="dupeClaim"style="width:100%">

               <apex:columnstyle="background-color:yellow">

                    <apex:facetname="header">

                                Claim Name

                     </apex:facet>

                                  {!dupeClaim.Name}

                </apex:column>

                <apex:columnstyle="background-color:yellow">

                     <apex:facetname="header">

                                 View claim

                     </apex:facet>

                         <apex:outputLinkvalue="javascript&colon;showClaim(&quot;/{!dupeClaim.Id}&quot;, &quot;{!dupeClaim.Name} Quick View&quot;);"title="View Claim">View Claim</apex:outputLink>

                </apex:column>

           </apex:pageBlockTable>

      </apex:pageblocksection>

</apex:outputpanel>

 

  • March 11, 2013
  • Like
  • 0

Hello - I am very new to Visualforce and Apex dev and have run into a roadblock.  There are two objects here, Interactions and Contacts.  Interactions is a related list on Contacts.  I have been given the task to populate the most current Interaction Date on a VF table made up of Contacts and make that column sortable.  Using a function in the controller I loop through all of the interactions and set the date for the most current interaction.  I have successfully added the most current date to the table, however the sort is causing a problem.  We are currently using the following sort function.

 

public

PageReference sortContacts() {

 

if (sortExpression == 'Reset') {

sortExpression =

'Workspace_Sort__c';

sortDirection =

'desc nulls last';

}

 

String queryString = (

'Select Id, Account.Id, Account.Name, Name, AccountSite2__c, Phone, Read__c, Account.Total_Open_Opportunity_Dollars__c, '+

 

'createdDate, Account_Contact_Score__c, Account_Contact_Score_Numeric__c, Last_Interaction_Date__c, InteractionScoreFormula__c, Interaction_Score_Numeric__c,Workspace_Sort__c, Action__c '+

 

'from Contact where AW_Contact_Status__c = \'Active\' and Account.OwnerId = \'' + UserInfo.getUserId() + '\' and Account.Is_Trade_Account__c = \'True\' and OwnerId = \''

+ UserInfo.getUserId() +

'\' and Name != \'General Contact\' and (Hide_From_Workspace_Until__c = null or Hide_From_Workspace_Until__c <= ' + dateString + ') '+

 

'order by ' + sortExpression + ' '+ sortDirection);

 

 

contactsCon =

newApexPages.StandardSetController(Database.getQueryLocator(queryString));

 

// sets the number of records in each page set

contactsCon.setPageSize(contactPageSize);

buildContacts();

returnnull;

}

 

 

As you can see we are sorting on the available fields on the Contact Object.  I need to sort on a field where I established the value (date) in the controller.  This field does not exist on the Contact Object or any other object.

 

I thought about creating new hidden fields on the Contact Object and trying to write (upsert?) the calculated value from the Controller.  However, I don't know that this would be advisable.

 

Any help that anyone could provide would be greatly appreciated.  Thanks!!

  • July 23, 2012
  • Like
  • 0
Hello - I need some assistance from the great minds in the SFDC dev community.  I've been asked to automatically add the count of Opportunity Team Members to a field on the Opportunity (basically just a roll-up).  For the most part this can't be done declaratively, so created a trigger.  The Non-Bulkified version of the trigger is very simple.  However, I can't see a way with collections (maps, lists, etc.) to bulkify it and keep my SOQL out of the For Loop.  Can anyone offer any ideas or suggestions as to how I could bulkify and keep the query out of a loop?  Here is my trigger code.


Thank you very much!
Jason

trigger CountOppTeam on OpportunityTeamMember (after insert, after delete)
{
List<Opportunity> oppList = new List<Opportunity>();
set<Id>oppIds = new set<Id>();

if(Trigger.isInsert || Trigger.isUpdate)
{
  List<id> oppId = new List<id>();
  for (OpportunityTeamMember oppTm: trigger.new)
  {
   oppIds.add(oppTm.OpportunityId);
  }

  for(Opportunity o: [Select id, CountTeamMembers__c From Opportunity Where id IN: oppIds])
  {
   List<OpportunityTeamMember> oppTmList = [Select id, Opportunityid From OpportunityTeamMember Where Opportunity.id =: o.id];
   o.CountTeamMembers__c = oppTmlist.Size();
   oppList.add(o);
  }

  update oppList;
}
else if (Trigger.isDelete)
{
  List<id> oppId = new List<id>();
  for (OpportunityTeamMember oppTm: trigger.old)
  {
   oppIds.add(oppTm.OpportunityId);
  }

  for(Opportunity o: [Select id, CountTeamMembers__c From Opportunity Where id IN: oppIds])
  {
   List<OpportunityTeamMember> oppTmList = [Select id, Opportunityid From OpportunityTeamMember Where Opportunity.id =: o.id];
   o.CountTeamMembers__c = oppTmlist.Size();
   oppList.add(o);
  }

  update oppList;
}
}
  • August 02, 2014
  • Like
  • 1
Hello Developer Community,

I was deploying a community today from Sandbox to Production via change sets and I got this error message on the standard Site.com Component that is automatically created by Salesforce with each new community:
Sorry, your target org is running on an earlier version of Salesforce and can't accept the current file. Please wait for your target org to be updated and try again.

Naturally this prevented the Network component from deploying which created a series of cascading errors, I think that the source error is the one above though.
The community was configured on a Spring '19 Sandbox while the production is still in a winter '19, it is a partner community configured with point and click features so nothing too complex about it.

I have a deadline to deploy the community today and I am short on time, has anyone had this problem before and does anyone know any workarounds to this.

Thanks in advance and Best Regards,

 
Hi All - We have a situation where we have a public website (not a SF Site) where we capture lead information - web to lead.  When the lead gets inserted to SF we are generating a promotion code and emailing that code to the lead...everything works fine.  However, our business partners would like that code sent back to the page and displayed on the thank you.  The thank you is not a VF page.

Does anyone have any experience passing data back to a non VF page using web to lead?

Any information you can share would be greatly appreciated.

Thank you.
  • June 01, 2015
  • Like
  • 0
Can you correct me if i am missing something.  

My controller class

public with sharing class BillingAddresses {
 public List<Account> AccountsList {get;set;}
 public BillingAddresses() {
  AccountsList = [SELECT ID, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry FROM Account LIMIT 10];
 } 
}

----- VF Page

<apex:page sidebar="false" showHeader="false" cache="false" controller="BillingAddresses">
    <style>
      html, body, #map_canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style>
    
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>    
      <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
    <script src="https://code.jquery.com/jquery-2.1.3.js"></script>
      
    <script>
        var map;       
                
        function initialize() {
            alert('Initializing');
            // set the map options in the format that V3 of googlemaps expects
            var mapOptions = {
                zoom: 4,
                center: new google.maps.LatLng(32.5206608,-86.80249),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            
            // attach our map to the map_canvas div
            map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
            
            // Pull the data in from the SOQL and use visualforce to create the javascript calls            
            <apex:repeat value="{!AccountsList}" var="Account">              
                
                showAddress("{!JSENCODE(Account.Name)}", "{!JSENCODE(Account.Name)}  <a href='../{!Account.id}' target='_blank'>Details</a>", "{!Account.BillingStreet}", "{!Account.BillingCity}","{!Account.BillingState}", "{!Account.BillingPostalCode}","{!Account.BillingCountry}");
                
            </apex:repeat>        
            
        } // function initialize()

        google.maps.event.addDomListener(window, 'load', initialize);
            
        function showAddress(title, content, street, city, state, postalcode, country) 
        {
        
            var address = street + city + state + postalcode + country;
                sforce.connection.sessionid = '{!$Api.Session_ID}';
                
                var geocoder = new google.maps.Geocoder();
                var geocoderRequest = { address: address }
                
                geocoder.geocode(geocoderRequest, function(results, status)
                {
                if(status == google.maps.GeocoderStatus.OK) 
                {
                    var googleAddress = results[0].formatted_address;
                    var Lat = results[0].geometry.location.lat();
                    var Long = results[0].geometry.location.lng();
                    
                }
                
                }
        
            // convert our raw values to the format that google expects                                 
            var latlng = new google.maps.LatLng(parseFloat(Lat), parseFloat(Long));
            
            if (latlng != null) {
                                            
                // create an info window            
                var infowindow = new google.maps.InfoWindow({
                    content: content
                });
                                            
                // Create a marker on the map                   
                var marker = new google.maps.Marker({
                    position: latlng,
                    map: map,
                    title: title                        
                });
                
                // Add an event to the marker so the info window will appear when it is clicked
                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map,marker);
                });
                                                        
            } // check for null latlng due an error parsing
                                            
        } // end show address    
        
                   
    </script>

    <div id="map_canvas" style="width: 100%; height: 100%"></div>

</apex:page>
 
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
Hello - I need some assistance from the great minds in the SFDC dev community.  I've been asked to automatically add the count of Opportunity Team Members to a field on the Opportunity (basically just a roll-up).  For the most part this can't be done declaratively, so created a trigger.  The Non-Bulkified version of the trigger is very simple.  However, I can't see a way with collections (maps, lists, etc.) to bulkify it and keep my SOQL out of the For Loop.  Can anyone offer any ideas or suggestions as to how I could bulkify and keep the query out of a loop?  Here is my trigger code.


Thank you very much!
Jason

trigger CountOppTeam on OpportunityTeamMember (after insert, after delete)
{
List<Opportunity> oppList = new List<Opportunity>();
set<Id>oppIds = new set<Id>();

if(Trigger.isInsert || Trigger.isUpdate)
{
  List<id> oppId = new List<id>();
  for (OpportunityTeamMember oppTm: trigger.new)
  {
   oppIds.add(oppTm.OpportunityId);
  }

  for(Opportunity o: [Select id, CountTeamMembers__c From Opportunity Where id IN: oppIds])
  {
   List<OpportunityTeamMember> oppTmList = [Select id, Opportunityid From OpportunityTeamMember Where Opportunity.id =: o.id];
   o.CountTeamMembers__c = oppTmlist.Size();
   oppList.add(o);
  }

  update oppList;
}
else if (Trigger.isDelete)
{
  List<id> oppId = new List<id>();
  for (OpportunityTeamMember oppTm: trigger.old)
  {
   oppIds.add(oppTm.OpportunityId);
  }

  for(Opportunity o: [Select id, CountTeamMembers__c From Opportunity Where id IN: oppIds])
  {
   List<OpportunityTeamMember> oppTmList = [Select id, Opportunityid From OpportunityTeamMember Where Opportunity.id =: o.id];
   o.CountTeamMembers__c = oppTmlist.Size();
   oppList.add(o);
  }

  update oppList;
}
}
  • August 02, 2014
  • Like
  • 1
Hi All -
Here is my situation.  I am doing some work for a small company.  They were out of liscenses.  They just got a new liscense in production for an SFDC developer (me).  They just refreshed their partial sanbox a couple days ago and are not eligible for a refresh.

They are going to manually add another user account in the Sandbox for me.  Obviously my user ids are going to be different in the Sandbox and Production.  My sandbox user id will not exist in production.

Am I correct in that I will not be able to migrate any changes I make in the Sandbox to Production due to the fact that my Sandbox User Id is not in Production?

If so, has anyone else ran into this issue and how did you work around it?

Thank you
Jason

  • July 28, 2014
  • Like
  • 0
Hi All - I am troubleshooting an issue with a visualforce redirect to a Conga Merge URL.  I have a custom save button on my page.  When user clicks the button I call a method in the controller that performs several actions.  At the end of the method I return the pagereference.  

What I'm finding is that after I instantiate the PageReference with a URL the resulting reference is different.

Here is my example:  Again this is just for troubleshooting purposes.  This is not my actual URL, my main question is why the url is getting modified.

PageReference ref = new PageReference('https://www.appextremes.com/apps/Conga/PM.aspx?SessionId=00DR0000001tYhK%21AQ0AQMPOzH5tBpCxtW_UfXfHoGV5PK4G2FPYVeXbgJQMyNXA04ukVuMy7WkF4ZfA6D8Are43sfTxIwaD9uxBReE0N4rUJrpy&ServerUrl=https%3A%2F%2Fcs2.salesforce.com%2Fservices%2FSoap%2Fu%2F8.0%2F00DR0000001tYhK&Id=0065000000M0zpq&TemplateId=a0M50000000QzTl&ReportId=00O50000002keBY?pv0=T33367&ReportId=00O50000002keBd?pv0=T33367&ReportId=00O50000002keBi?pv0=T33367&ReportId=00O50000002keBn?pv0=T33367&lg0=0&lg1=ALI%20Project%20Discount%20Form%20Generated&OFN=Discount+form+Calabrese+Res+5%2F27%2F2014&lg4=1&ds7=2&EmailRelatedToId=0065000000M0zpq&CETID=a1D50000000C7d4&EmailToID=+&lg3=1&MFTSId0=a0aR0000004tY1s&MFTS0=SpecialDiscountCode__c&MFTSValue0=Created&FP0=1');

If I include a system debug right here for the value of ref it is the following

https://www.appextremes.com/apps/Conga/PM.aspx?CETID=a1D50000000C7d4&ds7=2&EmailRelatedToId=0065000000M0zpq&EmailToID=+&FP0=1&Id=0065000000M0zpq&lg0=0&lg1=ALI+Project+Discount+Form+Generated&lg3=1&lg4=1&MFTS0=SpecialDiscountCode__c&MFTSId0=a0aR0000004tY1s&MFTSValue0=Created&OFN=Discount+form+Calabrese+Res+5%2F27%2F2014&ReportId=00O50000002keBY%3Fpv0%3DT33367&ServerUrl=https%3A%2F%2Fcs2.salesforce.com%2Fservices%2FSoap%2Fu%2F8.0%2F00DR0000001tYhK&SessionId=00DR0000001tYhK%21AQ0AQMPOzH5tBpCxtW_UfXfHoGV5PK4G2FPYVeXbgJQMyNXA04ukVuMy7WkF4ZfA6D8Are43sfTxIwaD9uxBReE0N4rUJrpy&TemplateId=a0M50000000QzTl

Notice the difference between what I put into the Reference and what is coming out of it.

Can someone please explain why my URL is getting changed?

Thank you very much.
Jason
  • May 27, 2014
  • Like
  • 0
Hi All - I'm somewhat familiar with the Non-Selective query problem, however, this one has got me stumpped.  My company has a full sandbox and I have my own development sandbox.  The same piece of code in our Full Sandbox and Production is causing a non-selective query in my dev sandbox.  No issue at all in Full SB or Production.

The query is as follows:  Note that this is in an After Update / After Insert Opportunity Trigger helper class.

for(CampaignMember cm: [SELECT id, ContactId FROM CampaignMember WHERE Campaign.Id =: campaignId])
{
    existingCampMembers.add(cm.ContactId);
}

I have one campaign member on one campaign in my dev sandbox.....that's it!!

If I execute query in developer console it returns the record.  If I execute anonymous, it finds the record no problem.  Also, if I were to change the filter to specify a contactid instead of campaign.id I do not get non-selective error.  So clearly there is something going on with Campaign.Id, but why here and not in Full SB or Production?

So does anyone have any ideas as to why I'm getting a non-selective query in my dev sandbox but not full sb or production?

Thank you in advance for any suggestions.

Jason

Below is the complete error message.

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Class.OpportunityTriggerLogic.addCampMbrToBldrPrgm: line 79, column 1
  • May 06, 2014
  • Like
  • 0
Hi All - I am new to the SFDC Migration Tool and am having issues with circular dependencies when performing a validation.  The issue is with a VF Controller and a VF page.  These are not new files,  I am making updates to both.  In the controller I have deprecated some getter methods and have added new ones.  I have updated the page accordingly, removing references to the old and adding references to the new.

I have included both of these files (controller & page) in my package.xml.  When validating I get an error telling me that the page is looking for one of the deprecated methods eventhough the updated page that I am deploying does not reference that method (I have checked...and double checked).

Obviously if I try just deploying the new page I get an error telling me that the updated VF page references methods that are not in the controller.

I believe that I can come up with an ugly multistep workaround, but wondering if others have a more elegant way of handling this scenario?

Thank you for any information that you could provide.

Jason
  • January 10, 2014
  • Like
  • 0

public with sharing class RestClass {
public void RestClass(){
HttpRequest req = new HttpRequest();
req.setEndpoint('https:/*********/services/apexrest/v1/showAccount/');
req.setMethod('GET');

// Specify the required user name and password to access the endpoint

// As well as the header and header information

 

String username = '*******';
String password = '******';

Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);

// Create a new http object to send the request object

// A response object is generated as a result of the request


Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}
}

 

 

I am getting Unauthorised Error .. 

 

I have added this to Remote site settings but cannot go through the athentication .. 

 

Any suggestions ...

Hello - The company I work for has an integration with a .NET application that updates Account records on a nightly basis.  The business wants the Account records updated on a more frequent basis.  However when we try to update the records more frequently we run into the issue of getting locked records, particularly during business hours, which prevents the record updates.

 

Our integration uses Informatica to map the data and update records.  Informatica allows us to use the Bulk API to update records (for those that know Informatica, it's a checkbox on the Session).  The advantage of using the Bulk API is that it runs asynchronously.  By running asynchronously, we would/should avoid our locked record issues.

 

My question is, is there any ill side effects of running Bulk API despite not having large record sets?  Our record sets would probably be in the 5 to 10 range every time the job runs.

 

...or are there any other options for running a frequent integration asynchronously to avoid record locks?

 

Any advice or knowledge share would be greatly appreciated.

 

Thank you

Jason

  • September 23, 2013
  • Like
  • 0

Hello - I've been banging my head too long on this one.  I'm trying to show a shadowbox of the claim activity when user clicks on the outputlink.  When I click on link nothing happens.  I've noticed that when I hover over the outputlink for a given claim the path shown in IE8 (lower left hand corner) looks something like

 

javascript&colon;showClaim(&#34;/a1NRxxxxxxxxxxxx&#34;,%20&#34;B-000008%20Quick%20View&#34;);

 

It should show up as

 

javascript&colon;showClaim("a1NRxxxxxxxxxxxx", "B-000008 Quick View");

 

The quot is for some reason getting passed as ascii....or so it seems.

 

Please share any thoughts and/or ideas.  Thank you!

 

function showClaim(src, title) {

 

     var box = new parent.SimpleDialog("hersh"+Math.random(), true);

     parent.box = box;

     box.setTitle(title);

     box.createDialog();

     box.setWidth(850);

     src='<a href=\"#\" onclick=\"box.hide();\">Close</a><br/><br/><p><iframe src="' + src + '" style="border:0; width:810px; min-height:           600px"></iframe></p>'

     box.setContentInnerHTML(src);

     box.setupDefaultButtons();

      box.show();

    if( 0 > 0 )

    setTimeout("box.hide();",0);

}

 

Here is my outputpannel

 

<

apex:outputpanelid="DuplicateClaimTable">

     <apex:pageblocksectiontitle="Possible Duplicate Claims"columns="1"rendered="{!dupeClaimToggle}">

          <apex:pageBlockTablevalue="{!dupeClaimList}"var="dupeClaim"style="width:100%">

               <apex:columnstyle="background-color:yellow">

                    <apex:facetname="header">

                                Claim Name

                     </apex:facet>

                                  {!dupeClaim.Name}

                </apex:column>

                <apex:columnstyle="background-color:yellow">

                     <apex:facetname="header">

                                 View claim

                     </apex:facet>

                         <apex:outputLinkvalue="javascript&colon;showClaim(&quot;/{!dupeClaim.Id}&quot;, &quot;{!dupeClaim.Name} Quick View&quot;);"title="View Claim">View Claim</apex:outputLink>

                </apex:column>

           </apex:pageBlockTable>

      </apex:pageblocksection>

</apex:outputpanel>

 

  • March 11, 2013
  • Like
  • 0

I am attempting to initiate a visual workflow upon the saving of an opportunity that meets certain criteria. The criteria are rather simple:

  1. The record type = "Standard New Business"
  2. The stage = "Closed Won" OR "Closed Lost"

If, upon save, the Opp is Closed Won, then I want to kick off a flow called "StandardOppWon." If Closed Lost, then kick off the flow "StandardOppLost."

 

I'm not even sure if kicking off flows via a trigger is possible, but this is the place to find out, right?! Can anyone help me get started in the right direction. I am a button-click admin who loves flows and understands them pretty well, but Apex triggers are a pretty new game for me.

 

Cheers!

  • November 27, 2012
  • Like
  • 0