• Platy IT
  • NEWBIE
  • 319 Points
  • Member since 2011

  • Chatter
    Feed
  • 12
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 56
    Replies
trigger EDC_Account_Number_Trigger on EDC_Account_Number__c (before insert, before update, after insert, after update) {

//Description: Associates all EDC Account Number Records with their previous and next iterations according to
//the EDC Account with the closest end date in both the past and future
    for(edc_account_number__c EDC:trigger.new)
        {
            list<edc_account_number__c> EDCListPrevious = [Select Id, name,start_date__c,end_date__c from edc_account_number__c
            where name = :EDC.name and End_Date__c <= :EDC.End_Date__c and ID != :EDC.id ORDER BY End_Date__c DESC];
            
            if(EDCListPrevious.isEmpty())
                {                   
                }
            Else
                {
                    if(trigger.isbefore)
                        {                       
                            EDC.Previous_EDC_Account_Number_Record__c = EDCListPrevious[0].id;
                        }
                    if(trigger.isafter)     
                        {
                            EDC_Account_Number__c EDCPrevious = [Select Id, name,Next_EDC_Account_Number_Record__c 
                            from EDC_Account_Number__c where Id = :EDCListPrevious[0].id];
                    
                            EDCPrevious.Next_EDC_Account_Number_Record__c = EDC.id;
                            update EDCPrevious;             
                        }
                }
            list<edc_account_number__c> EDCListNext = [Select Id, name,start_date__c,end_date__c from edc_account_number__c
            where name = :EDC.name and End_Date__c >= :EDC.End_Date__c and ID != :EDC.id ORDER BY End_Date__c ASC];
                
            if(EDCListNext.isEmpty())
                {
                }
            Else
                {
                    if(trigger.isbefore)
                        {
                            EDC.Next_EDC_Account_Number_Record__c = EDCListNext[0].id;                      
                        }
                }
        }
}

 I know that this trigger works on a single record but I am struggling as to how I should bulkify it. I appreciate any assistance as this is an area that I struggle with on a regular basis. I am fairly new to APEX development so I will take any feedback I can get. Thanks.

I need a bit of help writing my first test class.  Below is the code that i've modified for our environment.  I've also included the test case.   I've got my test class working now. I've pasted the updated class below.  I'm having a problem getting more than 71% code converage.  When I look at my code coverage in my trigger my test class doesn't cover the two lines below in bold.  Please advise in how I can ensure these lines are covered in my test case.  Thank you in advance for any help you can provide.   

 

closingprojects.add(p.id);

 

trigger.newmap.get( (id)ar.get('Id')).pse__Is_Active__c.adderror('This is a customer Project - You cannot set project to inactive until all Milestones are closed.');


How do I test these above lines in my test class?
----

The Trigger

 

// Looks at active projects and checks to see if any milestones are open
// If a milestone is open and a user tries to set a project to inactive then return a message to user


trigger OpenMilestoneTrigger on pse__Proj__c (before update) {


// Creates set of all active projects
set<id> closingprojects = new set<id>();
for(pse__Proj__c p:trigger.new)


// if(p.RecordTypeId == '012Z00000000JWKIA2'&&(p.pse__Stage__c=='Completed'&&trigger.oldmap.get(p.id).pse__Stage__c!='Completed'))
// sets the RecordTypeID for the Customer record

if(p.RecordTypeId == '012Z00000000JWKIA2'&&(p.pse__Is_Active__c == false && trigger.oldmap.get(p.id).pse__Is_Active__c == true))


// Adds active projects to the closingprojects set
closingprojects.add(p.id);


// Checks to see if there are any open milestones within the closing projects set
for(AggregateResult ar:[SELECT pse__Project__c Id,COUNT(Id) FROM pse__Milestone__c
WHERE pse__Project__c IN :closingprojects AND pse__Status__c != 'Approved' GROUP BY pse__Project__c])

// If there are open milestones then add them to the newmap and send error to user
trigger.newmap.get( (id)ar.get('Id')).pse__Stage__c.adderror('This is a customer Project - You cannot set project to inactive until all Milestones are closed.');


}

 

----

The Test Class

@isTest (seealldata=true)
private class OpenMilestoneTriggerTestClass {

private static testMethod void validateOpenMilestoneTriggerNegative() {

//setup variables to be used for building projects. Region and Record type are required
//It is important not to hardcode these values as the Id's will differ in production
RecordType rectype = [Select id from RecordType where Name = 'Customer'];
pse__Region__c regtype = [Select id from pse__Region__c where name = 'West' LIMIT 1];

//select pse__Billing_Type__c from pse__Proj__c where pse__Billing_Type__c = 'Time and Materials' limit 1
//Setup the Project Record
pse__Proj__c p = new pse__Proj__c();
p.RecordTypeId = rectype.id;
p.Name='TestProject';
p.pse__Region__c = regtype.id;
p.pse__Billing_Type__c = 'Hybrid';
p.pse__Is_Active__c = true;

insert p;

//Setup the Milestone Record
pse__Milestone__c m = new pse__Milestone__c();
m.Name = 'TestMileStone';
m.pse__Project__c = p.ID;
m.pse__Milestone_Amount__c = 0;
m.pse__Target_Date__c = Date.today();

insert m;

Test.startTest();

//Set the project status to inactive
try
{
p.pse__Is_Active__c = false;

}
Catch (System.DMLException e)
{
System.assert(e.getMessage().contains('Project cannot be closed with Open Milestones'));
}
Test.stopTest();
}
private static testMethod void validateOpenMilestoneTriggerPositive() {

RecordType rectype = [Select id from RecordType where Name = 'Customer'];
pse__Region__c regtype = [select id from pse__Region__c where name = 'West'];

//Setup the TestProject2 Record
pse__Proj__c p = new pse__Proj__c();
p.RecordTypeId = rectype.id;
p.Name='TestProject2';
p.pse__Region__c = regtype.id;
p.pse__Is_Active__c = true;
p.pse__Billing_Type__c = 'Time and Materials';

insert p;

//Setup the Milestone2 Record
pse__Milestone__c m = new pse__Milestone__c();
m.Name = 'TestMileStone2';
m.pse__Project__c = p.ID;
m.pse__Milestone_Amount__c = 0;
m.pse__Target_Date__c = Date.today();
m.pse__Actual_Date__c = Date.today();

insert m;

Test.startTest();
//Set the milestone status to approved and the project to inactive
try
{
m.pse__Status__c = 'Approved';
p.pse__Is_Active__c = false;
}
Catch (System.DMLException e)
{
System.assert(e.getMessage().contains('Project can be closed if there are no Open Milestones'));
}
Test.stopTest();
}

private static testMethod void validateOpenMilestoneTriggerClosingProjects() {

RecordType rectype = [Select id from RecordType where Name = 'Customer'];
pse__Region__c regtype = [select id from pse__Region__c where name = 'West'];

//Setup the Project Record
pse__Proj__c p = new pse__Proj__c();
p.RecordTypeId = rectype.id;
p.Name='TestProject3';
p.pse__Region__c = regtype.id;
p.pse__Is_Active__c = false;
p.pse__Billing_Type__c = 'Time and Materials';

pse__Milestone__c m1 = new pse__Milestone__c();
m1.Name = 'TestMileStone1';
m1.pse__Project__c = p.ID;
m1.pse__Milestone_Amount__c = 0;
m1.pse__Target_Date__c = Date.today();
m1.pse__Actual_Date__c = Date.today();

insert m1;

pse__Milestone__c m2 = new pse__Milestone__c();
m2.Name = 'TestMileStone2';
m2.pse__Project__c = p.ID;
m2.pse__Milestone_Amount__c = 0;
m2.pse__Target_Date__c = Date.today();
m2.pse__Actual_Date__c = Date.today();

insert m1;



set<id> closingprojects = new set<id>();


// for(AggregateResult ar:[SELECT pse__Project__c Id,COUNT(Id) FROM pse__Milestone__c
// WHERE pse__Project__c IN :closingprojects AND pse__Status__c != 'Approved' GROUP BY pse__Project__c])

// trigger.newmap.get( (id)ar.get('Id')).pse__Is_Active__c.adderror('This is a customer project with a billing type of time and materials - You cannot set project to inactive until all milestones are closed.');


Test.StartTest();
Try
{
if(p.RecordTypeId == rectype.id &&(p.pse__Is_Active__c == false))
closingprojects.add(p.id);
}
Catch (System.DMLException e)
{
System.assertEquals(closingprojects.size(),1);
}
Test.StopTest();

}
}

Hey guys I'd like to know if its possible to add a button or link to another visualforce page on a page, however I would like to do it in the middle of a page right above another text field in the layout.  Is this possible?  As far as I know custom buttons only go at the top of the page and right above the related lists.

Hello,

 

I was wondering if there is any equivalent string function that can used similar to the charAt function which exists in java?

I know no such method is listed at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

 

I know it's possible to look through the string and to get each character using the substring function in such a loop but it would be much better if a function existed similar to charAt.

 

if anyone knows of a better way of doing this you can let me know.

 

Thanks!

Hi developers,

 

I would like to know if it is possible to use the translation workbench in visualforce.

 

I have my code, that at some stage looks like this:

 

<tr>
<td class="labelCol"><b>Currency to Invoice </b></td>
<td class="dataCol col02"> {!Lead.Currency_to_Invoice__c}</td>
<td class="labelCol"><b> Billing Language</b></td>
<td class="dataCol col02"> {!Lead.Billing_Language__c}</td>
</tr>

 

Lets take Billing_Language_c as example. This field is a picklist with the values: CAS, ENG, FRE that corresponds in the translation workbench to Spanish, English and French. When I show the value of the picklist in my code, instead of showing English, visualforce is showing ENG.

 

Can I somehow show the translated value of ENG,CAS or FRE in my visualforce page?

 

Thanks a lot. Regards,

 

Antonio

hello i have a simple question,

i need a soql query which gets me all records from an object, where the records in a field do not start with a letter.

For example in de Account object the names are

AAA

BBB

1CD

 

The query should get me '1CD'

 

Thank you

I am creating a site where users come in and create records. I was wondering if there was a way to make sure that I the site does not get spammed. I was thinking that I could do something with the IP Addresses.

Hi,

 

I wrote a following trigger for updating a custom object field whenever a stage of  any opportunity is changed. But while doing mass update it is throwing Limit error crossed 500001 rows. Kindly help me in modifying  the code to avoid the error.

 

trigger stageupdate on Opportunity (before update) {
List<Trade_In_Equipments__c> ls=[select id,Opportunity__c,Equipment__c,Unique_check__c from Trade_In_Equipments__c];
List<Trade_In_Equipments__c> ls1=new List<Trade_In_Equipments__c>();
List<Trade_In_Equipments__c> ls2=new List<Trade_In_Equipments__c>();
  
    for(Opportunity op:Trigger.new)
    {
     try{   
  /* If the opportunity stage value is not equal to new value and the new value is closed lost, we are adding opportunity id and equipment id to uniquecheck field, so that other opportunity
can add this equipment */      

    if((!Trigger.oldmap.get(op.Id).stagename.equals(op.stagename)) && (op.stagename.equals('Closed Lost')))
        {
       
            for(Trade_In_Equipments__c tr:ls)

            {
            if(tr.Opportunity__c==op.Id){
             tr.Unique_check__c=(string)tr.Opportunity__c+(string)tr.Equipment__c;
                   
           
        ls1.add(tr);
       
        }

 

}

       
 /* If the old opportunity stage value is closed lost and the new value is not closed lost, we are adding equipment id to uniquecheck field, so that other opportunity cannot add this equipment.
In case if other opportunity already had the equipment added to them and in open stage, this will throw error 'Please delete the Trade_In_Equipments before changing the stage' */
   

  

           if((Trigger.oldmap.get(op.Id).stagename.equals('Closed Lost')) && (!op.stagename.equals('Closed Lost')))
            {
       
                    for(Trade_In_Equipments__c tr:ls)

               {
       
               String q=(string)tr.Equipment__c;

            
                     tr.Unique_check__c=q.substring(0,15);                   
               ls2.add(tr);

        } 

        }

 
   }
 update ls1;    
  update ls2;                   }
     
       catch(Exception e)
{
System.debug('Error');
op.addError('Stage cannot be changed without deleting the associated trade in equipments');
  }
}
  }

  • June 29, 2011
  • Like
  • 0

Hi,

I have one requirement.

I have embeded a VF page in standard Lead page layout .I have set the height of the page as 200 pixels.

The page is having a command button and when we click on the button a form will display in the VF page section.This functionality has been already implemented.The issue is that since the button height is only 30 pixel ,while loading the page is allocating 200 pixels for the VF page even though only a small button is displaying.

Is there any way to collapse this section while initially loading the page?

 

Please let me know if you need any more details.

I have a batch class that accepts a query string.

 

I"m testing the function and want to pass over a query to the batch for very specific records that I can test. I would like to pass over either a single id or a set.

 

Can I format a query string to include the single quotes necessary when formatting a filter for a single ID? I know I could modify the class to include another variable but I would rather not. I'm only doing this as a test and wouldn't actually use that variable ever again after the test.

 

For example:

 

I want: 
Select MyFied__c from Contract where id = '8003000000021gz';

but as a string literal:

string q = 'select MyField__c from Contract where id =' .... 

 

I am creating a VisualForce page that displays a limited view of a Contact. I am using the call <apex:detail subject="{!contact.Id}" relatedList="false" title="true" /> , and this displays the Contact address, but I want to hide the Contact address.

 

Is there a way to display all fields of the Contact Detail except the address? Is there a way to set rendered="false" for a portion of the apex:detail (the address)?

 

I tried adding the following lines to the apex:page after the apex:detail mentioned above, but it had no impact on the display of the address.

 

      <apex:detail subject="{!contact.MailingStreet}" rendered="false" />
      <apex:detail subject="{!contact.MailingCity}" rendered="false" />
      <apex:detail subject="{!contact.MailingState}" rendered="false" />
      <apex:detail subject="{!contact.MailingPostalCode}" rendered="false" />
      <apex:detail subject="{!contact.MailingCountry}" rendered="false" />

 

Thanks,

When I use the getLabel method of a Schema.DescribeFieldResult object (quick example below), it works fine for every field except Reference fields.  For a Reference field, it's returning the Label of that reference's Id field (e.g. Account Id or Owner Id) instead of the label actually used for that Lookup/Master-Detail field (e.g. Account Name or Owner).  Anyone know a workaround for this?

 

String Label = DescField.getLabel();

I've developed a managed package in a Developer Edition account and included a custom profile for Profile Settings.  That profile has Read (only) rights to the two custom objects in my package.  But when I install that package in another organization using the setting to enable to all users, the profiles are given Read, Create, Edit and Delete rights to those objects.   If I exclude that Profile Setting from the package, they don't get any rights at all to those objects.  Am I missing something?  Seems like my only options are all or nothing.  

I'm sure I'm missing something obvious here.  I've developed a @RestResource class with an @HttpPost method.  Here's the method-

@HttpPost
	global static String ImportContact() {
		RestRequest req = RestContext.request;
		System.debug('req is---------------------- ' +req);
		RestResponse resp = RestContext.response;
		
		
		Contact impContact = new Contact();
		impContact.FirstName = req.params.get('firstname');
		impContact.LastName = req.params.get('lastname');
		impContact.FirstName = req.params.get('email');
		impContact.Website_Id__c = req.params.get('userid');
		impContact.Phone = req.params.get('phone');
		impContact.LinkedIn_Profile_URL__c = req.params.get('linkedin');
		impContact.Facebook_Profile_URL__c = req.params.get('facebook');
		impContact.Website__c = req.params.get('personalwebsite');
		impContact.Twitter__c = req.params.get('twitter');
		try{
			impContact.Startup_Administrator__c = Boolean.valueOf(req.params.get('startupadmin'));
		} Catch (Exception e){
			resp.statusCode = 400;
			return 'startupadmin parameter must equal true or false';
		}
		
		//Check for a matching Contact
		
		
		try{
			upsert impContact;
		} Catch (DMLException e){
			resp.statusCode = 400;
			return 'Error loading Contact into Salesforce- ' +e.getMessage(); 
		}
		
		/*Blob pic = req.requestBody;
		if (pic.size() > 0){
			
		}*/
		
		resp.statusCode = 201;
		return 'Contact created';
		
	}

 Using curl, I can connect to this and pass in a file of JSON parameters as below, but all of those req.params.get calls in the method return null so the post returns an error?  

{
"firstname": "Json",
"lastname": "test",
"email": "email@email.com",
"phone": "914-417-9780",
"startupadmin": "true"
}

 

What confuses me is that in the debug log, I examine the RestRequest and I see the parameter values there-

10:39:21.061 (61510000)|USER_DEBUG|[12]|DEBUG|req is---------------------- RestRequest:[headers={Accept=*/*, CipherSuite=RC4-MD5 TLSv1 128-bits, Content-Type=application/x-www-form-urlencoded, Host=cs14.salesforce.com, User-Agent=curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5, X-Salesforce-SIP=108.6.201.115}, httpMethod=POST, params={{"firstname": "Json","lastname": "test","email": "email@email.com","phone": "914-417-9780","startupadmin": "true"}=}, remoteAddress=108.6.201.115, requestBody=Blob[0], requestURI=/NewEntStartup/, resourcePath=/services/apexrest/NewEntStartup/*]

 

Anyone seeing what I'm clearly missing here?  

 

I've hit the non-selective query error in triggers for organizations with a lot of data and know how to deal with it there, but I'm wondering if this same error can occur in Apex code fired by a Visualforce controller/extension as well?  The Salesforce article related to this (http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm) seems to limit it to triggers, but does anyone know for sure if that's the case?

 

Context- I'm developing a managed package that includes a VF page that will query records and I'm wondering if I should be factoring this into the design and help files.

 

Thanks!

I have a Visualforce form used in Sites to submit new Cases.  The form allows people to attach files to the new Case and has been in production working for about 6 months.  In the last couple weeks, suddenly people are receiving errors when attaching more than 2 files, even though this previously worked and the code hasn't been updated.  

 

In my testing, I don't receive an explicit error message but I am finding that if I attach more than 2 files, only the first and last one that's inserted in the code ends up saved on the Case.  So if I select 5 files, only 1 and 5 are saved.  When I review the debug log, it's as if the files in the middle don't even exist, there's no record of the code even trying to insert them, and there's no error messages. 

 

This isn't a view state error, the page correctly gives an error message if any of the files are too big,   I've tried re-writing the actual attachment insert code a few different ways, and the result is always the same- only the first and last files are saved.  Has anyone else experienced similar issues recently?  Since this worked perfectly well before, this is striking me as a bug on the Salesforce side of things, but I'm not sure how to convince support of this so they don't automatically close my help desk case. I'm sadistically hoping others have hit this as well as evidence for my claim.

I'm hitting "Maximum view state size limit (135KB) exceeded" errors when certain actions are performed on my page.  When I look at the View State, about 95% of the content comes from Internal.  I have tried adding "transient" to the few variables that could potentially get large, though right now I'm only dealing with data from 63 records in just a few fields (no blobs or long text fields even).  Any tips on what I can do to reduce that View State, or track down what's causing it?

 

When I use the getLabel method of a Schema.DescribeFieldResult object (quick example below), it works fine for every field except Reference fields.  For a Reference field, it's returning the Label of that reference's Id field (e.g. Account Id or Owner Id) instead of the label actually used for that Lookup/Master-Detail field (e.g. Account Name or Owner).  Anyone know a workaround for this?

 

String Label = DescField.getLabel();

I'm working on a related list of opportunities that tabs the opportunities by Subject.  I have figured out how to do this if I code out each subject individually in the controller but I'd like it to be dynamic so that if a new subject is added the controller/page does not have to be recoded.  I can get my list of subjects via

public list<Schema.Picklistentry> getEntries(){
        return Opportunity.fields.Subject__c.getDescribe().getpicklistvalues();
    }  

But then I need the list for each subject such as I have here in my hardcoded example:

public List<Opportunity> getSubject1() {
        return [select id, name, stagename, closedate, amount, subject__c from Opportunity where accountid = :a.id and subject__c = 'General Chemistry' order by closedate];   
    }

and I also need the list on the visual force page as tabs such as I have here in my hardcoded example:

<apex:tab label="General Chemistry" name="GenChemOpps" id="tabGenChem">
            <apex:pageBlockTable value="{!subject1}" var="s1">     
            <apex:column headerValue="Action">       
                <apex:outputLink value="{!URLFOR($Action.Opportunity.Edit,s1.id)}">Edit</apex:outputLink>
                <apex:outputLabel value=" | "/>     
                <apex:outputLink value="{!URLFOR($Action.Opportunity.Delete,s1.id)}">Del</apex:outputLink>     
            </apex:column>              
            <apex:column headerValue="Opportunity Name"> <apex:outputLink value="{!URLFOR($Action.Opportunity.View,s1.id)}">{!s1.name}</apex:outputLink> </apex:column>  
            <apex:column headerValue="Stage" value="{!s1.StageName}"/>  
            <apex:column headerValue="Amount" value="{!s1.Amount}"/>
            <apex:column headerValue="Class Start Date" value="{!s1.CloseDate}"/>    
            <apex:column headerValue="Subject" value="{!s1.Subject__c}"/>                 
            </apex:pageBlockTable>
      </apex:tab>

 

I can pull just the list of subjects into the vf page via:

<apex:repeat value="{!entries}" var="val">
        {!val.label}<br/>
    </apex:repeat>

but I just can't seem to figure out how to mix it all together into something that works.  If anyone could help me that would be wonderful.

 

Thanks,

Amanda

I'm sure I'm missing something obvious here.  I've developed a @RestResource class with an @HttpPost method.  Here's the method-

@HttpPost
	global static String ImportContact() {
		RestRequest req = RestContext.request;
		System.debug('req is---------------------- ' +req);
		RestResponse resp = RestContext.response;
		
		
		Contact impContact = new Contact();
		impContact.FirstName = req.params.get('firstname');
		impContact.LastName = req.params.get('lastname');
		impContact.FirstName = req.params.get('email');
		impContact.Website_Id__c = req.params.get('userid');
		impContact.Phone = req.params.get('phone');
		impContact.LinkedIn_Profile_URL__c = req.params.get('linkedin');
		impContact.Facebook_Profile_URL__c = req.params.get('facebook');
		impContact.Website__c = req.params.get('personalwebsite');
		impContact.Twitter__c = req.params.get('twitter');
		try{
			impContact.Startup_Administrator__c = Boolean.valueOf(req.params.get('startupadmin'));
		} Catch (Exception e){
			resp.statusCode = 400;
			return 'startupadmin parameter must equal true or false';
		}
		
		//Check for a matching Contact
		
		
		try{
			upsert impContact;
		} Catch (DMLException e){
			resp.statusCode = 400;
			return 'Error loading Contact into Salesforce- ' +e.getMessage(); 
		}
		
		/*Blob pic = req.requestBody;
		if (pic.size() > 0){
			
		}*/
		
		resp.statusCode = 201;
		return 'Contact created';
		
	}

 Using curl, I can connect to this and pass in a file of JSON parameters as below, but all of those req.params.get calls in the method return null so the post returns an error?  

{
"firstname": "Json",
"lastname": "test",
"email": "email@email.com",
"phone": "914-417-9780",
"startupadmin": "true"
}

 

What confuses me is that in the debug log, I examine the RestRequest and I see the parameter values there-

10:39:21.061 (61510000)|USER_DEBUG|[12]|DEBUG|req is---------------------- RestRequest:[headers={Accept=*/*, CipherSuite=RC4-MD5 TLSv1 128-bits, Content-Type=application/x-www-form-urlencoded, Host=cs14.salesforce.com, User-Agent=curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5, X-Salesforce-SIP=108.6.201.115}, httpMethod=POST, params={{"firstname": "Json","lastname": "test","email": "email@email.com","phone": "914-417-9780","startupadmin": "true"}=}, remoteAddress=108.6.201.115, requestBody=Blob[0], requestURI=/NewEntStartup/, resourcePath=/services/apexrest/NewEntStartup/*]

 

Anyone seeing what I'm clearly missing here?  

 

Hi All,

 

 

DefaultHttpClient client = new DefaultHttpClient();

HttpPost oauthPost = new HttpPost(baseUrl);

HttpResponse response = client.execute(oauthPost);

int code = response.getStatusLine().getStatusCode();

Map<String, String> oauthLoginResponse = (Map<String, String>) JSON.parse(EntityUtils
.toString(response.getEntity()));

 

eclipse show the error The method parse(String) is undefined for the type JSON

 

plz need help

trigger EDC_Account_Number_Trigger on EDC_Account_Number__c (before insert, before update, after insert, after update) {

//Description: Associates all EDC Account Number Records with their previous and next iterations according to
//the EDC Account with the closest end date in both the past and future
    for(edc_account_number__c EDC:trigger.new)
        {
            list<edc_account_number__c> EDCListPrevious = [Select Id, name,start_date__c,end_date__c from edc_account_number__c
            where name = :EDC.name and End_Date__c <= :EDC.End_Date__c and ID != :EDC.id ORDER BY End_Date__c DESC];
            
            if(EDCListPrevious.isEmpty())
                {                   
                }
            Else
                {
                    if(trigger.isbefore)
                        {                       
                            EDC.Previous_EDC_Account_Number_Record__c = EDCListPrevious[0].id;
                        }
                    if(trigger.isafter)     
                        {
                            EDC_Account_Number__c EDCPrevious = [Select Id, name,Next_EDC_Account_Number_Record__c 
                            from EDC_Account_Number__c where Id = :EDCListPrevious[0].id];
                    
                            EDCPrevious.Next_EDC_Account_Number_Record__c = EDC.id;
                            update EDCPrevious;             
                        }
                }
            list<edc_account_number__c> EDCListNext = [Select Id, name,start_date__c,end_date__c from edc_account_number__c
            where name = :EDC.name and End_Date__c >= :EDC.End_Date__c and ID != :EDC.id ORDER BY End_Date__c ASC];
                
            if(EDCListNext.isEmpty())
                {
                }
            Else
                {
                    if(trigger.isbefore)
                        {
                            EDC.Next_EDC_Account_Number_Record__c = EDCListNext[0].id;                      
                        }
                }
        }
}

 I know that this trigger works on a single record but I am struggling as to how I should bulkify it. I appreciate any assistance as this is an area that I struggle with on a regular basis. I am fairly new to APEX development so I will take any feedback I can get. Thanks.

Two questions related to each other -

 

1. On the standard event  edit page how can I add a custom button or custom link ? I know this can be done using visual force, I need to know how to do this on the standard edit page.

 

2. Under the Contacts/Attendee Info, when you try to add contacts to the event, it opens up a new page . My requirement is to show only the contacts tied to the Account  on the Available Selected List ( to avoid picking wrong contacts). How do I go about doing this ?

   

The solution I came up for question 2 is this - Create a new custom button and place it on the detail page. When clicked, it opens up a visual force page which displays the contacts tied to the account. It then mimicks the default Salesforce behaviour of adding /removing the contacts, adding /deleting the EventRelation objects.


  

   If question 2 is not do-able then is the solution I came up with good ?

 

Thanks and hope to hear from the architects as well.

hi everyone,

 

I have a class which shares all the records that are in an account with all the contacts in that particular account. Meaning, Account A has contacts c1, c2, c3. If account A has lets say 10000 records then the same number of records should be shared with contacts c1, c2 and c3. Also, if a new contact c4 is created under that account A, then that contact c4 should also have 10000 records. Anytime a new record is added to that account, all these contacts should have that updated records.

 

The code I have works if the record size is less, but I have an account with 78K records so the code hits governor limits.

The records are being fetched to that account from another class Order, Items, Price. I have triggers in all these classes to this class that is supposed to share the records.

 

Does anyone have any suggestion on what can be done to resolve this issue. Any suggestion is helpful.


Thanks!

I need a bit of help writing my first test class.  Below is the code that i've modified for our environment.  I've also included the test case.   I've got my test class working now. I've pasted the updated class below.  I'm having a problem getting more than 71% code converage.  When I look at my code coverage in my trigger my test class doesn't cover the two lines below in bold.  Please advise in how I can ensure these lines are covered in my test case.  Thank you in advance for any help you can provide.   

 

closingprojects.add(p.id);

 

trigger.newmap.get( (id)ar.get('Id')).pse__Is_Active__c.adderror('This is a customer Project - You cannot set project to inactive until all Milestones are closed.');


How do I test these above lines in my test class?
----

The Trigger

 

// Looks at active projects and checks to see if any milestones are open
// If a milestone is open and a user tries to set a project to inactive then return a message to user


trigger OpenMilestoneTrigger on pse__Proj__c (before update) {


// Creates set of all active projects
set<id> closingprojects = new set<id>();
for(pse__Proj__c p:trigger.new)


// if(p.RecordTypeId == '012Z00000000JWKIA2'&&(p.pse__Stage__c=='Completed'&&trigger.oldmap.get(p.id).pse__Stage__c!='Completed'))
// sets the RecordTypeID for the Customer record

if(p.RecordTypeId == '012Z00000000JWKIA2'&&(p.pse__Is_Active__c == false && trigger.oldmap.get(p.id).pse__Is_Active__c == true))


// Adds active projects to the closingprojects set
closingprojects.add(p.id);


// Checks to see if there are any open milestones within the closing projects set
for(AggregateResult ar:[SELECT pse__Project__c Id,COUNT(Id) FROM pse__Milestone__c
WHERE pse__Project__c IN :closingprojects AND pse__Status__c != 'Approved' GROUP BY pse__Project__c])

// If there are open milestones then add them to the newmap and send error to user
trigger.newmap.get( (id)ar.get('Id')).pse__Stage__c.adderror('This is a customer Project - You cannot set project to inactive until all Milestones are closed.');


}

 

----

The Test Class

@isTest (seealldata=true)
private class OpenMilestoneTriggerTestClass {

private static testMethod void validateOpenMilestoneTriggerNegative() {

//setup variables to be used for building projects. Region and Record type are required
//It is important not to hardcode these values as the Id's will differ in production
RecordType rectype = [Select id from RecordType where Name = 'Customer'];
pse__Region__c regtype = [Select id from pse__Region__c where name = 'West' LIMIT 1];

//select pse__Billing_Type__c from pse__Proj__c where pse__Billing_Type__c = 'Time and Materials' limit 1
//Setup the Project Record
pse__Proj__c p = new pse__Proj__c();
p.RecordTypeId = rectype.id;
p.Name='TestProject';
p.pse__Region__c = regtype.id;
p.pse__Billing_Type__c = 'Hybrid';
p.pse__Is_Active__c = true;

insert p;

//Setup the Milestone Record
pse__Milestone__c m = new pse__Milestone__c();
m.Name = 'TestMileStone';
m.pse__Project__c = p.ID;
m.pse__Milestone_Amount__c = 0;
m.pse__Target_Date__c = Date.today();

insert m;

Test.startTest();

//Set the project status to inactive
try
{
p.pse__Is_Active__c = false;

}
Catch (System.DMLException e)
{
System.assert(e.getMessage().contains('Project cannot be closed with Open Milestones'));
}
Test.stopTest();
}
private static testMethod void validateOpenMilestoneTriggerPositive() {

RecordType rectype = [Select id from RecordType where Name = 'Customer'];
pse__Region__c regtype = [select id from pse__Region__c where name = 'West'];

//Setup the TestProject2 Record
pse__Proj__c p = new pse__Proj__c();
p.RecordTypeId = rectype.id;
p.Name='TestProject2';
p.pse__Region__c = regtype.id;
p.pse__Is_Active__c = true;
p.pse__Billing_Type__c = 'Time and Materials';

insert p;

//Setup the Milestone2 Record
pse__Milestone__c m = new pse__Milestone__c();
m.Name = 'TestMileStone2';
m.pse__Project__c = p.ID;
m.pse__Milestone_Amount__c = 0;
m.pse__Target_Date__c = Date.today();
m.pse__Actual_Date__c = Date.today();

insert m;

Test.startTest();
//Set the milestone status to approved and the project to inactive
try
{
m.pse__Status__c = 'Approved';
p.pse__Is_Active__c = false;
}
Catch (System.DMLException e)
{
System.assert(e.getMessage().contains('Project can be closed if there are no Open Milestones'));
}
Test.stopTest();
}

private static testMethod void validateOpenMilestoneTriggerClosingProjects() {

RecordType rectype = [Select id from RecordType where Name = 'Customer'];
pse__Region__c regtype = [select id from pse__Region__c where name = 'West'];

//Setup the Project Record
pse__Proj__c p = new pse__Proj__c();
p.RecordTypeId = rectype.id;
p.Name='TestProject3';
p.pse__Region__c = regtype.id;
p.pse__Is_Active__c = false;
p.pse__Billing_Type__c = 'Time and Materials';

pse__Milestone__c m1 = new pse__Milestone__c();
m1.Name = 'TestMileStone1';
m1.pse__Project__c = p.ID;
m1.pse__Milestone_Amount__c = 0;
m1.pse__Target_Date__c = Date.today();
m1.pse__Actual_Date__c = Date.today();

insert m1;

pse__Milestone__c m2 = new pse__Milestone__c();
m2.Name = 'TestMileStone2';
m2.pse__Project__c = p.ID;
m2.pse__Milestone_Amount__c = 0;
m2.pse__Target_Date__c = Date.today();
m2.pse__Actual_Date__c = Date.today();

insert m1;



set<id> closingprojects = new set<id>();


// for(AggregateResult ar:[SELECT pse__Project__c Id,COUNT(Id) FROM pse__Milestone__c
// WHERE pse__Project__c IN :closingprojects AND pse__Status__c != 'Approved' GROUP BY pse__Project__c])

// trigger.newmap.get( (id)ar.get('Id')).pse__Is_Active__c.adderror('This is a customer project with a billing type of time and materials - You cannot set project to inactive until all milestones are closed.');


Test.StartTest();
Try
{
if(p.RecordTypeId == rectype.id &&(p.pse__Is_Active__c == false))
closingprojects.add(p.id);
}
Catch (System.DMLException e)
{
System.assertEquals(closingprojects.size(),1);
}
Test.StopTest();

}
}

I've hit the non-selective query error in triggers for organizations with a lot of data and know how to deal with it there, but I'm wondering if this same error can occur in Apex code fired by a Visualforce controller/extension as well?  The Salesforce article related to this (http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm) seems to limit it to triggers, but does anyone know for sure if that's the case?

 

Context- I'm developing a managed package that includes a VF page that will query records and I'm wondering if I should be factoring this into the design and help files.

 

Thanks!

global with sharing class Update_Contract_Changed_this_week_Field implements Schedulable {

global list<Contract_Cycle_Discussion__c> AllContracts;
public Update_Contract_Changed_this_week_Field ()
{

}

global void execute(SchedulableContext SC)
{
allcontracts = [ SELECT Additional_Sales_Director_Difference__c,Additional_Sales_Director_Shadow__c,
Additional_Sales_Director__c,Advertiser_Contact_Difference__c,Advertiser_Contact_Shadow__c,
Advertiser_Contact__c,Advertiser_Difference__c,Advertiser_Shadow__c,Advertiser__c,
Agency_Contact_Difference__c,Agency_Contact_Shadow__c,Agency_Contact__c,Agency_del_Difference__c,
Agency_del_Shadow__c,Agency_del__c,Background_Notes_Difference__c,Background_Notes_Shadow__c,
Background_Notes__c,BOR_Special_Rate_Correct_Difference__c,BOR_Special_Rate_Correct_Shadow__c,
BOR_Special_Rate_Correct__c,Brand_Difference__c,Brand_Exclusion_Difference__c,Brand_Exclusion_Shadow__c,Brand_Exclusion__c,Brand_Shadow__c,Brand__c,Category_Discount_Highest_Level_Shadow__c,
Category_Discount_Highest_Level__c,Category_Discount_Planning_Rate_Shadow__c,Category_Discount_Planning_Rate__c,
Category_Discount_Proposal_Contract_S__c,Categ_Discount_Highest_Level_Difference__c,Categ_Discount_Planning_Rate_Difference__c
,Categ_Disc_Proposal_Contr_S_Difference__c,Categ_Disc_Proposal_Contr_S_Shadow__c,Close_Date_Difference__c,Close_Date_Shadow__c,
Close_Date__c,Contract_Changed_this_week_FLAG__c,Contract_Date_Issued_Difference__c,Contract_Date_Issued_Shadow__c,
Contract_Date_Issued__c,Contract_Date_Signed_Difference__c,Contract_Date_Signed_Shadow__c,Contract_Date_Signed__c,
Contract_External_ID_Difference__c,Contract_External_ID_Shadow__c,Contract_External_ID__c,Contract_Notes_Difference__c,
Contract_Notes_Shadow__c,Contract_Notes__c,Contract_Status_Difference__c,Contract_Status_Shadow__c,
Contract_Status_Update_Difference__c,Contract_Status_Update_Shadow__c,Contract_Status_Update__c,Contract_Status__c,
Contract_Type_Difference__c,Contract_Type_Shadow__c,Contract_Type__c,CreatedById,CreatedDate,Current_User__c,
Digital_Discount_Highest_Level_Shadow__c,Digital_Discount_Highest_Level__c,Digital_Discount_Planning_Rate_Shadow__c,
Digital_Discount_Planning_Rate__c,Digital_Discount_Proposal_Cont_Sign_On__c,Digital_Disc_Highest_Level_Difference__c,
Digital_Disc_Planning_Rate_Difference__c,Digit_Disc_Propos_Cont_Sign_On_Shadow__c,Digit_Disc_Prop_Cont_Sign_On_Difference__c,
Division_Difference__c,Division_Shadow__c,Division__c,End_Date_Difference__c,End_Date_Shadow__c,End_Date__c,
Estimated_Net_Revenue_Difference__c,Estimated_Net_Revenue_Shadow__c,Estimated_Net_Revenue__c,
Estimate_Advert_Fiscal_Year_Difference__c,Estimate_Advert_Fiscal_Year_Shadow__c,Estimate_Advert_Fiscal_Year__c,
Estimate_App_Fiscal_Year_Difference__c,Estimate_App_Fiscal_Year_Shadow__c,Estimate_App_Fiscal_Year__c,
Estimate_Print_Fiscal_Year_Difference__c,Estimate_Print_Fiscal_Year_Shadow__c,Estimate_Print_Fiscal_Year__c,
Estimate_Total_Contract_Year_Difference__c,Estimate_Total_Contract_Year_Shadow__c,Estimate_Total_Contract_Year__c,
Estimate_Total_Fiscal_Year_Difference__c,Estimate_Total_Fiscal_Year_Shadow__c,Estimate_Total_Fiscal_Year__c,
Estimate_Web_Fiscal_Year_Difference__c,Estimate_Web_Fiscal_Year_Shadow__c,Estimate_Web_Fiscal_Year__c,Final_Approver_Difference__c,
Final_Approver_Shadow__c,Final_Approver__c,Highest_Amount_Difference__c,Highest_Amount_Shadow__c,Highest_Amount__c,
Highest_Level_CPM_Difference__c,Highest_Level_CPM_Shadow__c,Highest_Level_CPM__c,Id,Includes_Other_Incentives_Difference__c,
Includes_Other_Incentives_Shadow__c,Includes_Other_Incentives__c,Includes_SOM_Difference__c,Includes_SOM_Shadow__c,Includes_SOM__c,
Insert_Discount_Highest_Level_Shadow__c,Insert_Discount_Highest_Level__c,Insert_Discount_Planning_Rate_Difference__c,Insert_Discount_Planning_Rate_Shadow__c,Insert_Discount_Planning_Rate__c,Insert_Discount_Proposal_Contract_Sig__c,Insert_Disc_Proposal_Contract_Sig_Shadow__c,Insert_Disc_Propos_Contr_Sig_Difference__c,IsDeleted,LastActivityDate,LastModifiedById,LastModifiedDate,Media_Services_Difference__c,Media_Services_Shadow__c,Media_Services__c,Name,Name_Difference__c,Name_Shadow__c,Planning_Rates_Difference__c,Planning_Rates_Shadow__c,Planning_Rates__c,Primary_Corporate_Sales_Director_Shadow__c,Primary_Corporate_Sales_Director__c,Primary_Corp_Sales_Director_Difference__c,Proposal_Date_Issued_Difference__c,Proposal_Date_Issued_Shadow__c,Proposal_Date_Issued__c,RecordTypeId,Rob_Discount_Highest_Level_Difference__c,Rob_Discount_Highest_Level_Shadow__c,Rob_Discount_Highest_Level__c,ROB_Discount_Planning_Rate_Difference__c,ROB_Discount_Planning_Rate_Shadow__c,ROB_Discount_Planning_Rate__c,Rob_Discount_Proposal_Contract_Sign_O__c,Rob_Disc_Proposal_Contract_Sign_O_Shadow__c,Rob_Disc_Proposal_Cont_Sign_O_Difference__c,Secondary_Corporate_Sales_Director__c,Secondary_Sales_Director_Difference__c,Secondary_Sales_Director_Shadow__c,Sign_On_CPM_Difference__c,Sign_On_CPM_Shadow__c,Sign_On_CPM__c,Sign_On_Difference__c,Sign_On_Shadow__c,Sign_On__c,Start_Date_Difference__c,Start_Date_Shadow__c,Start_Date__c,SystemModstamp,Two_Year_Deal_Difference__c,Two_Year_Deal_Shadow__c,Two_Year_Deal__c,Insert_Discount_Highest_Level_Difference__c FROM Contract_Cycle_Discussion__c]; // where Committed_Date__c != null

if( allcontracts != null && allcontracts.size() > 0)
{
System.debug('*********Size****'+allcontracts.size());
for(Integer i=0; i < allcontracts.size();i++)
{
if( allcontracts.get(i).Media_Services_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Primary_Corp_Sales_Director_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Additional_Sales_Director_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Secondary_Sales_Director_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Agency_del_Difference__c == 'DIFFERENCE' || allcontracts.get(i).Start_Date_Difference__c == 'DIFFERENCE'
|| allcontracts.get(i).End_Date_Difference__c == 'DIFFERENCE' || allcontracts.get(i).ROB_Discount_Planning_Rate_Difference__c != 0 ||
allcontracts.get(i).Categ_Discount_Planning_Rate_Difference__c != 0 || allcontracts.get(i).Insert_Discount_Planning_Rate_Difference__c != 0 || allcontracts.get(i).Digital_Disc_Planning_Rate_Difference__c != 0 || allcontracts.get(i).Proposal_Date_Issued_Difference__c == 'DIFFERENCE' || allcontracts.get(i).Sign_On_Difference__c != 0

|| allcontracts.get(i).Rob_Disc_Proposal_Cont_Sign_O_Difference__c != 0
|| allcontracts.get(i).Categ_Disc_Proposal_Contr_S_Difference__c != 0 ||
allcontracts.get(i).Insert_Disc_Propos_Contr_Sig_Difference__c != 0 ||
allcontracts.get(i).Digit_Disc_Prop_Cont_Sign_On_Difference__c != 0 || allcontracts.get(i).Includes_SOM_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Includes_Other_Incentives_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Sign_On_CPM_Difference__c != 0
|| allcontracts.get(i).Highest_Amount_Difference__c != 0
|| allcontracts.get(i).Rob_Discount_Highest_Level_Difference__c != 0 ||
allcontracts.get(i).Categ_Discount_Highest_Level_Difference__c != 0 ||
allcontracts.get(i).Insert_Discount_Highest_Level_Difference__c != 0 ||
allcontracts.get(i).Digital_Disc_Highest_Level_Difference__c != 0 ||
allcontracts.get(i).Highest_Level_CPM_Difference__c != 0 ||
allcontracts.get(i).Two_Year_Deal_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Final_Approver_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Contract_Type_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Contract_Status_Update_Difference__c == 'DIFFERENCE'||
allcontracts.get(i).Contract_Date_Issued_Difference__c == 'DIFFERENCE' ||
allcontracts.get(i).Contract_Date_Signed_Difference__c == 'DIFFERENCE'
)
{
allcontracts.get(i).Contract_Changed_this_week_FLAG__c = 'CHANGED';


}
else
{
allcontracts.get(i).Contract_Changed_this_week_FLAG__c = 'UNCHANGED';

}
update allcontracts;
}
}
}

}

Getting the below error with the above code.please help me on this

 

12:30:29.452 (209452055000)|CODE_UNIT_FINISHED|Workflow:01I30000002Fje8
*********** MAXIMUM DEBUG LOG SIZE REACHED ***********
12:31:15.459 (255459867000)|FATAL_ERROR|System.LimitException: Too many DML rows: 10001

Class.Update_Contract_Changed_this_week_Field.execute: line 85, column 1
  • January 07, 2013
  • Like
  • 0

Hey guys I'd like to know if its possible to add a button or link to another visualforce page on a page, however I would like to do it in the middle of a page right above another text field in the layout.  Is this possible?  As far as I know custom buttons only go at the top of the page and right above the related lists.