• MarkLevy
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 18
    Replies
I'm trying to create a custom related list for Attachments to work in a better way than the existing one for my purposes. My thought is to just make a visualforce page that shows the attachments (with links to view) on the object currently being viewed, however I'm not sure how to go about doing that for attachment URLs.

It looks like the URL of the file isn't a part of the attachment object: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm

Instead it would appear that the ID of the attachment has something to do with it, but it looks like it goes to a diferent domain to get that, for instance, on my org:
https://ORGNAME--c.na63.content.force.com/servlet/servlet.FileDownload?file=ATTACHMENTID

It would appear that this is the way to query the attachment ID, but the URL it's using worries me.. is there a way in APEX to get that URL? I'm imagining lets say in the instance I just hard code this to make the file url always https://ORGNAME--c.na63.content.force.com/servlet/servlet.FileDownload?file=ATTACHMENTID and then our server changes and is no longer na63 and it breaks...

Any thoughts on this? How can I get the file URL that isn't quite so messy as hard coding it and then having to fix it if our server changes?

Thanks!
I'm getting this error when trying to run through the test of a trigger on my new custom object:
 
System.DmlException: Update failed. First exception on row 0 with id a1O0S0000001QoIUAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MasterBridgeApplicationTrigger: execution of BeforeUpdate

caused by: System.StringException: Invalid id: BRAPP00019

External entry point
Trigger.MasterBridgeApplicationTrigger: line 17, column 1: []
Stack Trace 

Class.BridgeApplicationProcessingTest.BridgeAppTest: line 44, column 1
My custom object has an autoincrement Name (as you see, BRAPP00019) -- Which seems to keep autoincrementing in my test even though I'm using @isTest(seeAllData=false) for my test -- which is odd.

But furthermore, why is updating the object in the database throwing this error? why is it confusing the Name with the Id when updating??

Here's the code I have that causes the error (error caused by the line: 'update app;')
Contact ourContact = [SELECT Id, Email FROM Contact WHERE Email = 'test1@nope.com'];

		Bridge_Application__c app = new Bridge_Application__c(
			Applicant__c = ourContact.Id
		);

		insert app;

		app = [SELECT Name, Id, Applicant__c,
		First_Decision__c,
		Second_Decision__c,
		Third_Decision__c,
		FROM Bridge_Application__c WHERE Applicant__c = :ourContact.Id];

		app.First_Decision__c= 'Admit';
		app.Second_Decision__c= 'Admit';
		app.Third_Decision__c= 'Admit';

		update app;

I'm completely dumbfounded here.

Why is APEX itself getting confused about what the Id is and what the Name is when it pulled all this information from the select statement that got the app in the first place?

Why is the Id auto incrementing every time I run through this test even though i'm using @isTest(seeAllData=false)?

Any help here is appreciated, I've been searching the forums heavily and can't find anything remotely like this problem.

Thanks!
I'm assigning Leads to specific users using APEX triggers. When this happens and a user gets assigned a Lead they are getting an email notification that the lead is being assigned to them. I do not want this to happen. Why are they getting emails? How can I turn this off? I can't seem to find a solution to this that works.

Thanks!
I have data (in APEX) from an AggregateResult that consists of 3 items: 'Company', 'Division', and 'Count' pulled by a SOQL query on contacts grouping by Company / Division and giving the count for each Company / Division pair that it found.

I'm looking to create a bar chart from this AggregateResult that will group bars by Company, and display each bar grouped by Company titled with Division and the bar value itself being the 'Count'. So you'll see multiple groups of Company, and then bars for the Divisions that exist for that company and counts for those bars.

I've looked at: https://developer.salesforce.com/forums?id=906F000000098R4IAI for how to go about making grouped bar charts similar to this, but the data / grouping in all the examples I've seen so far is static, meaning that in my case for Division since I have several possible Divisions which could exist for any company (or not be there in a company at all, and therefore shouldn't be displayed), I can't make all Divisions for all companies the same and display them like division1,division2,division3 etc. for all the grouped companies -- this would need to be dynamic and the Divisions be based on what is pulled from the original query that generated the AggregateResult. Note that divisions themselves are dynamic as well and could change and the graph would have to allow for that (like a new company enters the database that has a new possible division that didn't exist before -- the graph should display that and not care about what or how many Divisions already exist in the database)

How do I go about grouping by my Companies and having the bars it shows grouped for each Company be dependent on the dynamically pulled Divisions for that company?
I have no idea why but out of nowhere when I coded some additional APEX to assign tasks when leads get created my users started getting email notifications on task assignment. I was already assigning tasks this way, I just added some more that get created so I have no idea why this started happening now.

I don't want my users to be emailed when they are assigned tasks. I've found a workaround but it's really sloppy. The only way I can seem to get this to happen is to go to Activity Settings and 'Enable User Control over Task Assignment Notifications' and then go into every user's account and under Activity Reminders uncheck Email me when someone assigns me a task.

Is there some way I can change a global setting that disables email notifications on task assignment for all users? Or maybe create a trigger in APEX on user creation that sets this field to false? I can't seem to find where the field is if the trigger method is possible.

Any insight as to how to disable all email notifications on task assignemnt globally or find out where in apex I can work with the 'Email me when someone assigns me a task' field would be helpful.

Thanks!
This seems to be happening to me now where I have certain tests that work just fine in my Sandbox but fail assertions when deploying to Production thus failing the test. It seems to be happening all of a sudden on certain tests and I have no idea why.

All of my tests use @isTest(seeAllData=false) so there shouldn't be a problem between Sandbox VS. Production data.

This particular test that is failing is an update on a lead that should be updating properly, but the assertion shows that the update failed. I'm creating users in the test as well and using System.runAs so that shouldn't be different between Sandbox and Production either.

In my Production I have it set to run Apex tests one at a time, so that shouldn't be interfering with my tests either.

I really have no idea what's going on here.
Any assistance as to why a test using only test data would work in Sandbox but fail in Production would be helpful.

I could post my code but it's very very long, and it could be something else on the Production server that is causing the check if update worked assertion to fail as well so I can't very well post all the Apex code on my server. The most helpful thing for me would be strategy on what could be wrong and how to go about investigating this further. Is there some specific Lead Update Failed reason in a log somewhere I can look up or something that I can do shed more light on why this is happening?

Thanks!
Is it possible to query using SOQL for a substring on a multi-select picklist? LIKE seems to not work on multi-select picklists.

Example:

MultiSelectPicklist = 'myfavoritefruitisapple;myfavoritecolorisgreen;ihatered'

I'd want to query using WHERE and search for the substring 'favorite' such that it will pick up anything with 'myfavoritefruitisapple' or 'myfavoritecolorisgreen' but not pick up the 'ihatered' people.

Is something like this possible?

Thanks!
I'm having a difficult time finding the answer to this question.

I coded up a before insert trigger that checks both the insertion set (all leads being currently inserted) as well as existing Leads+Contacts to see if the leads trying to be inserted already exist or are duplicated in the insertion set. The check is a cross-check on their email or alt-email for the insertion set itself, Leads, and Contacts.

I prevent the insertion of duplicate leads by adding an error when a duplicate is found (either in the insertion set, or already existing Lead/Contact in Salesforce), but doing this unfortunately rolls back the insert preventing that lead from being inserted and trying to insert again without that lead (as Salesforce does). This does not work for our purposes because ultimately if 2 leads insert at the same time (in the same insertion set) from our web insert they should merge into 1, not simply stop the second insert.

Instead of removing the duplicated lead from being inserted entirely, in cases where the existing Lead/Contact can be updated, or 2 leads are being inserted in this insertion set that are duplicated and can be merged I would like to update / merge the Leads, but I can't do that if it rolls back the insertion of all leads when I error the insert of 1 lead.

In short:

How can I prevent insertion of a single Lead in my insertion set without it rolling back and restarting the trigger (removing the lead from the insertion set and running the insert again) so that in the trigger itself I can either A: merge the lead with the other lead in the insertion set which is a duplicate, or B: update the existing Lead / contact with the new information.

Right now I'm thinking that this isn't possible and instead I should allow the lead to insert but set some sort of flag on it that says "Duplicate of LEAD_ID / CONTACT_ID" and then run a trigger after insert that merges the duplicated lead with the existing/duplicated-in-set lead/contact. Would that work? Is there a cleaner way of doing this? What am I not thinking about / should I keep in mind with this insertion logic?

Any assistance here is much appreciated. Thanks!
I'm trying to create a new trigger before Lead insertion to check for duplicates from Leads or Contacts and prevent insertion. The duplicate check I'm going for is checking if newLeadEmail = existingEmail or if newLeadEmail = existingAltEmail (etc etc) basically preventing duplicates being added if alt email or email exists anywhere between the email or altEmail fields.

I'm getting a 71% code coverage unfortunately and really don't know how to go about making a test case cover more. I've created a test case that checks over some very basic insertion of Leads but it isn't covering my code.

Here are the lines for Lead checking that are not covered (similar lines for contact checking are also not covered):
*existingLeadList queries the database for existing leads that have Email or Alt Email matches
for(Lead newLead : Trigger.new){
                for(Lead exisitingLead : existingLeadList ){
                    if((newLead.Email == exisitingLead.Email)||(newLead.Alt_Email__c == exisitingLead.Alt_Email__c)||(newLead.Email==exisitingLead.Alt_Email__c)||(newLead.Alt_Email__c == exisitingLead.Email)){
                        newLead.addError('Duplicate Lead');
                    }
                }
            }

Any ideas on how to make a test case for this? Is there something I'm missing? Shouldn't basic Lead insertion test cases work for this?

Also as a side question: when I add the checking for alt email in my test for inserting duplicate leads it fails (naturally) because this trigger isn't in place yet to make it succeed at failing to insert a duplicate based on newEmail = oldAltEmail, but I shouldn't be publishing a test that fails should I? How do I deploy my trigger if the test I create to test it fails unless the trigger is active?

Any help here is appreciated. I'm a bit stuck at the moment. Thanks!
I'm trying to create a custom related list for Attachments to work in a better way than the existing one for my purposes. My thought is to just make a visualforce page that shows the attachments (with links to view) on the object currently being viewed, however I'm not sure how to go about doing that for attachment URLs.

It looks like the URL of the file isn't a part of the attachment object: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm

Instead it would appear that the ID of the attachment has something to do with it, but it looks like it goes to a diferent domain to get that, for instance, on my org:
https://ORGNAME--c.na63.content.force.com/servlet/servlet.FileDownload?file=ATTACHMENTID

It would appear that this is the way to query the attachment ID, but the URL it's using worries me.. is there a way in APEX to get that URL? I'm imagining lets say in the instance I just hard code this to make the file url always https://ORGNAME--c.na63.content.force.com/servlet/servlet.FileDownload?file=ATTACHMENTID and then our server changes and is no longer na63 and it breaks...

Any thoughts on this? How can I get the file URL that isn't quite so messy as hard coding it and then having to fix it if our server changes?

Thanks!
I'm getting this error when trying to run through the test of a trigger on my new custom object:
 
System.DmlException: Update failed. First exception on row 0 with id a1O0S0000001QoIUAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MasterBridgeApplicationTrigger: execution of BeforeUpdate

caused by: System.StringException: Invalid id: BRAPP00019

External entry point
Trigger.MasterBridgeApplicationTrigger: line 17, column 1: []
Stack Trace 

Class.BridgeApplicationProcessingTest.BridgeAppTest: line 44, column 1
My custom object has an autoincrement Name (as you see, BRAPP00019) -- Which seems to keep autoincrementing in my test even though I'm using @isTest(seeAllData=false) for my test -- which is odd.

But furthermore, why is updating the object in the database throwing this error? why is it confusing the Name with the Id when updating??

Here's the code I have that causes the error (error caused by the line: 'update app;')
Contact ourContact = [SELECT Id, Email FROM Contact WHERE Email = 'test1@nope.com'];

		Bridge_Application__c app = new Bridge_Application__c(
			Applicant__c = ourContact.Id
		);

		insert app;

		app = [SELECT Name, Id, Applicant__c,
		First_Decision__c,
		Second_Decision__c,
		Third_Decision__c,
		FROM Bridge_Application__c WHERE Applicant__c = :ourContact.Id];

		app.First_Decision__c= 'Admit';
		app.Second_Decision__c= 'Admit';
		app.Third_Decision__c= 'Admit';

		update app;

I'm completely dumbfounded here.

Why is APEX itself getting confused about what the Id is and what the Name is when it pulled all this information from the select statement that got the app in the first place?

Why is the Id auto incrementing every time I run through this test even though i'm using @isTest(seeAllData=false)?

Any help here is appreciated, I've been searching the forums heavily and can't find anything remotely like this problem.

Thanks!
I have no idea why but out of nowhere when I coded some additional APEX to assign tasks when leads get created my users started getting email notifications on task assignment. I was already assigning tasks this way, I just added some more that get created so I have no idea why this started happening now.

I don't want my users to be emailed when they are assigned tasks. I've found a workaround but it's really sloppy. The only way I can seem to get this to happen is to go to Activity Settings and 'Enable User Control over Task Assignment Notifications' and then go into every user's account and under Activity Reminders uncheck Email me when someone assigns me a task.

Is there some way I can change a global setting that disables email notifications on task assignment for all users? Or maybe create a trigger in APEX on user creation that sets this field to false? I can't seem to find where the field is if the trigger method is possible.

Any insight as to how to disable all email notifications on task assignemnt globally or find out where in apex I can work with the 'Email me when someone assigns me a task' field would be helpful.

Thanks!
This seems to be happening to me now where I have certain tests that work just fine in my Sandbox but fail assertions when deploying to Production thus failing the test. It seems to be happening all of a sudden on certain tests and I have no idea why.

All of my tests use @isTest(seeAllData=false) so there shouldn't be a problem between Sandbox VS. Production data.

This particular test that is failing is an update on a lead that should be updating properly, but the assertion shows that the update failed. I'm creating users in the test as well and using System.runAs so that shouldn't be different between Sandbox and Production either.

In my Production I have it set to run Apex tests one at a time, so that shouldn't be interfering with my tests either.

I really have no idea what's going on here.
Any assistance as to why a test using only test data would work in Sandbox but fail in Production would be helpful.

I could post my code but it's very very long, and it could be something else on the Production server that is causing the check if update worked assertion to fail as well so I can't very well post all the Apex code on my server. The most helpful thing for me would be strategy on what could be wrong and how to go about investigating this further. Is there some specific Lead Update Failed reason in a log somewhere I can look up or something that I can do shed more light on why this is happening?

Thanks!
Is it possible to query using SOQL for a substring on a multi-select picklist? LIKE seems to not work on multi-select picklists.

Example:

MultiSelectPicklist = 'myfavoritefruitisapple;myfavoritecolorisgreen;ihatered'

I'd want to query using WHERE and search for the substring 'favorite' such that it will pick up anything with 'myfavoritefruitisapple' or 'myfavoritecolorisgreen' but not pick up the 'ihatered' people.

Is something like this possible?

Thanks!
I'm having a difficult time finding the answer to this question.

I coded up a before insert trigger that checks both the insertion set (all leads being currently inserted) as well as existing Leads+Contacts to see if the leads trying to be inserted already exist or are duplicated in the insertion set. The check is a cross-check on their email or alt-email for the insertion set itself, Leads, and Contacts.

I prevent the insertion of duplicate leads by adding an error when a duplicate is found (either in the insertion set, or already existing Lead/Contact in Salesforce), but doing this unfortunately rolls back the insert preventing that lead from being inserted and trying to insert again without that lead (as Salesforce does). This does not work for our purposes because ultimately if 2 leads insert at the same time (in the same insertion set) from our web insert they should merge into 1, not simply stop the second insert.

Instead of removing the duplicated lead from being inserted entirely, in cases where the existing Lead/Contact can be updated, or 2 leads are being inserted in this insertion set that are duplicated and can be merged I would like to update / merge the Leads, but I can't do that if it rolls back the insertion of all leads when I error the insert of 1 lead.

In short:

How can I prevent insertion of a single Lead in my insertion set without it rolling back and restarting the trigger (removing the lead from the insertion set and running the insert again) so that in the trigger itself I can either A: merge the lead with the other lead in the insertion set which is a duplicate, or B: update the existing Lead / contact with the new information.

Right now I'm thinking that this isn't possible and instead I should allow the lead to insert but set some sort of flag on it that says "Duplicate of LEAD_ID / CONTACT_ID" and then run a trigger after insert that merges the duplicated lead with the existing/duplicated-in-set lead/contact. Would that work? Is there a cleaner way of doing this? What am I not thinking about / should I keep in mind with this insertion logic?

Any assistance here is much appreciated. Thanks!
I'm trying to create a new trigger before Lead insertion to check for duplicates from Leads or Contacts and prevent insertion. The duplicate check I'm going for is checking if newLeadEmail = existingEmail or if newLeadEmail = existingAltEmail (etc etc) basically preventing duplicates being added if alt email or email exists anywhere between the email or altEmail fields.

I'm getting a 71% code coverage unfortunately and really don't know how to go about making a test case cover more. I've created a test case that checks over some very basic insertion of Leads but it isn't covering my code.

Here are the lines for Lead checking that are not covered (similar lines for contact checking are also not covered):
*existingLeadList queries the database for existing leads that have Email or Alt Email matches
for(Lead newLead : Trigger.new){
                for(Lead exisitingLead : existingLeadList ){
                    if((newLead.Email == exisitingLead.Email)||(newLead.Alt_Email__c == exisitingLead.Alt_Email__c)||(newLead.Email==exisitingLead.Alt_Email__c)||(newLead.Alt_Email__c == exisitingLead.Email)){
                        newLead.addError('Duplicate Lead');
                    }
                }
            }

Any ideas on how to make a test case for this? Is there something I'm missing? Shouldn't basic Lead insertion test cases work for this?

Also as a side question: when I add the checking for alt email in my test for inserting duplicate leads it fails (naturally) because this trigger isn't in place yet to make it succeed at failing to insert a duplicate based on newEmail = oldAltEmail, but I shouldn't be publishing a test that fails should I? How do I deploy my trigger if the test I create to test it fails unless the trigger is active?

Any help here is appreciated. I'm a bit stuck at the moment. Thanks!
So in the Winter 15 the feature Email me when someone assigns me a task is automatically set by default. Is there a way to turn off this feature globally, so the users don't have to do it themselves?