• Gunnar
  • NEWBIE
  • 255 Points
  • Member since 2013

  • Chatter
    Feed
  • 9
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 70
    Replies
How do you create a test class over a utility class when the methods are pretty much all just passing parms back and forth? For example I have a method that gets passed a name field and the method just does some formatting like first letter upper case the rest of each word lower case, etc.  finally it passes the name back.
Since tests are all static.  
Thanks for the help.
Hello, 

I am trying to write a trigger that creates a new account when an orphaned Contact is created. The problem that I'm having is when I try to change the Account Record Type. FYI I am completely new to Apex and triggers (In fact this is only the second one I've written).


This is what I have so far :
 
(note:most of this is based on answers to questions I have found here and other websites. Just don't want to try to take credit for something that I didn't create myself :) )

trigger CreateAccountsForContacts on Contact (before insert) {
    Map<Contact, Account> accounts = new Map<Contact, Account>();
    for(Contact record: Trigger.new) {
        if(record.AccountId == null) {
            accounts.put(record, new Account(Name=record.FirstName+' '+record.LastName));
        }
    }
    insert accounts.values();
    for(Contact record: Trigger.new) {
        if(record.AccountId == null) {
            record.AccountId = accounts.get(record).Id;
        }
      
        if(record.RecordType.Name == 'Patient') {
            account.RecordTypeId = '012U000000014g1';
            }
    }
}

If I take out 

if(record.RecordType.Name == 'Patient') {
            account.RecordType.Name = 'Patient';
            }

it works fine, creates the account no problem. However I need it to change the Account Type based on the Contact Record Type, otherwise it could default to the wrong one. My idea was to check to see if the Contact Record Type was Patient, and if it was, set the Account Record Type to Patient as well.
 I'm sure it's something in the syntax I just don't understand. Any help would be appreciated. Thank you!
Hello,

I have the trigger below that fires on updates to my Account objects.  The trigger works fine and tests fine, but when I try to make mass changes via the data loader I get the error message:

UpdateConsultantAcct: System.LimitException: Too many SOQL queries: 101

Can someone help me figure out why I am getting this error?  Thanks,

trigger UpdateConsultantAcct on Account (after update){
       
    List<Account> acct = new List<Account>();

    Opportunity[] oppsToUpdate = new List<Opportunity>();  

    FOR(Account a : Trigger.new){

    // Query Opportunity records realted to Account that is being created/edited
    List<Opportunity> opps = [SELECT AccountId, IsWon, IsClosed, Consultant_Partner__c, Consultant_Type__c
                              FROM Opportunity
                              WHERE AccountId IN: Trigger.newMap.keySet()];
       
        // Iterating through all the Opportunity records and updating them as per the conditions
        for(Opportunity opps2 :opps){

            // Update Consultant Partner field on Opportunity if Opp is Open and Consultant field changes at Account level
            IF(opps2.IsWon == FALSE && opps2.IsClosed == FALSE && opps2.Consultant_Type__c == 'Primary Consultant' && trigger.NewMap.get(opps2.AccountId).Consultant_Partner_Primary__c != trigger.OldMap.get(opps2.AccountId).Consultant_Partner_Primary__c){
                opps2.Consultant_Partner__c = a.Consultant_Partner_Primary__c;
                oppsToUpdate.add(opps2);
            }
           
            ELSE IF(opps2.IsWon == FALSE && opps2.IsClosed == FALSE && opps2.Consultant_Type__c == 'Secondary Consultant' && trigger.NewMap.get(opps2.AccountId).Consultant_Partner_Secondary__c != trigger.OldMap.get(opps2.AccountId).Consultant_Partner_Secondary__c){
                opps2.Consultant_Partner__c = a.Consultant_Partner_Secondary__c;
                oppsToUpdate.add(opps2);
            }
        }
       
        // Update all realted Opportunity records
        //IF(opps.size() > 0)
        //   update opps;
    }
    update oppsToUpdate;
}
  • January 29, 2014
  • Like
  • 0

I'm trying to write trigger that updates records specified in a self referenced lookup.

 

My example would be seats in a theatre and their are two self-referenced fields. One lookup for "Seat To Left" and lookup for "Seat To Right." I want to write a trigger that updates the records you're specifying as lookups.

 

User scenario would be something like the user is updating 192. The user marks "Seat to the Left" as 191. I want the trigger to go to seat 191 and update it's "Seat to the Right" field as being 192, so the user doesn't have to mess around too much.

 

Really roughly, something like this:

 

trigger SeatTrigger on Seat__c (before insert, before update) {
	
	List<Seat__c> triggerSeatsUpdate = new List<Seat__c>(); 
	
	for (Seat__c triggerSeat : Trigger.new) {
		if(triggerSeat.Seat_To_Left__c != null) {
			Seat__c seatToTheLeft = new Seat__c();  
			seatToTheLeft.Id = triggerSeat.Seat_To_Left__c;
			seatToTheLeft.Seat_To_Right__c = triggerSeat.Id;
			triggerSeatsUpdate.add(SeatToTheLeft); 	
		}
		if(triggerSeat.Seat_To_Right__c != null) {
			Seat__c seatToTheRight = new Seat__c(); 
			seatToTheRight.Id = triggerSeat.Seat_To_Right__c;
			seatToTheRight.Seat_To_Left__c = triggerSeat.Id;
			triggerSeatsUpdate.add(SeatToTheRight);
		}
	}
	
	update triggerSeatsUpdate;

}

 Except using an update this way won't work. I don't think I could just add the records to the trigger.new either. Is there a solution for this problem?

  • December 11, 2013
  • Like
  • 0

This question might seem silly: Batches inside a batch job are executed simultaneously or in a sequential way?

 

Let's say a batch job has 20 batches, after the batch job is started by SFDC, the batches inside it are executed simultaneously?

Below is the snippet from the test method moved successfully in production so far never had issues. but now in winter 14 it fails.

 

 

-----

Test.starttest();

ReassignmentBatch lrb = new ReassignmentBatch(strSOQL);
ID batchprocessid = Database.executeBatch(lrb,100);
System.debug('strSOQL: ' + strSOQL);
System.abortJob(batchprocessid);
Test.stoptest();

-----

 

When I comment "System.abortJob(batchprocessid);" it succeeds.  

 

But found a wierd behaviour i created only 3 records in test class for tesing but it started itterating for more than 100 of scope. and it fails.



Has anyone come accross the same.

 

May be a SF Known Issue

Unit tests that have been in existence for some time, and pass, broke.

Created a new developer sandbox from our Production.

Ran all tests in the new sandbox.

A LOT of code is breaking.

The unit tests create their own data as such ...

// Create Account
    Account a01 = new Account();
    a01.name              = 'Guess Things Happen That Way';
    a01.ownerid           = JohnnyCash.id;

When it hits this line "a01.name              = 'Guess Things Happen That Way';"

It breaks, saying "Compile Error: Variable does not exist: name at line 31"

Again, this has been working for a LONG time, it's in a unit test.
  • January 27, 2014
  • Like
  • 0
I have a SOQL query.
Ran it in the Dev Console in our production and got a full years worth of results - just what I needed.
Did NOT get 'too many query rows' error in console.

So I thought I was good to go and programmed up the class module to get the data.

Run the apex program containing the exact SQL and get too many query rows.

How do I know it's exact?  Because I assemble the SQL string and system.debug it. Then get the SQL and paste into Dev Console.

So question?  Why 'too many query rows in apex, but not in Dev Console?

  • January 07, 2014
  • Like
  • 0

Used to be able to see the percent of code coverage in the Apex Classes Screen. When clicking on the code coverage, used to see the lines coverd in green and not covered lines in red.

 

That is now gone?

 

So I have to use Eclipse to see what is and is not covered?

 

It used to be easy to see what needed to be covered and make sure the test hit the uncovered lines.

 

Is this a new feature?

  • October 11, 2013
  • Like
  • 0

I can't find any docs on the apex destructor. It has one, right? Even VB6 and VBA have destructors.

  • October 08, 2013
  • Like
  • 0

I'm running some apex in the developer console.

The log size is 2.11 mb - small.

 

When I go to view it, it takes forever and then finally says

 

Long running operation did not complete, continuing in background.

 

Bottom Line: I cannot open it and see my system.debug() statements.

 

The logs are worthless unless I can get to them.

 

Any ideas?

  • September 25, 2013
  • Like
  • 0

I can get the number of batches running by running SOQL on the AsyncApexJob table, here.

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_asyncapexjob.htm

 

My question is, how long can my apex program loop around in a DO | WHILE, waiting for an open slot (of the -5- available)????

 

Next question? Any word on when I can have more than -5- jobs in the queue, which is a beyond absurdly small number??

 

 

 

 

 

 

Lots of stuff in the change set.

 

Would like to get a report of all the components so I can check off one-by-one.

 

But the view is all I see. And I have to page through it.

 

Hoping there is a better way than copy-paste pages into Excel???

 

Batch inserting records. Have a problem with dates.

Salesforce assigns something different.

 

// run the following two lines in the immediate window of the developer console.

Date TodaysDate = date.today();
system.debug(TodaysDate);

 

You will get this ...

12:39:07:022 USER_DEBUG [2]|DEBUG|2013-07-01 00:00:00

 

Perfect!

 

Now, I'm creating the record and the following is one of the lines in the create object code.

    Received_Date_Time__c = todaysDate.addDays(-d)

 

Received_Date_Time__c is a date/time field.

 

When I look at the object.Received_Date_Time__c, the value is 6/30/2013 5:00 PM

 

I need the value from the debug - 2013-07-01 00:00:00 to appear in the field.

 

6/30/2013 <> 2013-07-01.

 

For laughs, I created another field, this being a 'DATE' field, and it does record the 2013-07-01. However, we cannot change the Received_Date_Time__c to a DATE field.

 

Any ideas on how to get 2013/07/01 into the DateTime field?

 

thanks in advance.

 

 

 

 

In the developer console, I get the following back ...

11:28:54:335 USER_DEBUG [708]|DEBUG|----------Limit DML Rows - 10000 Actual 1317

 

Here is the statement in the code that generates the above...

        system.debug('----------Limit DML Rows - ' + Limits.getLimitDMLRows() + ' Actual ' +Limits.getDMLRows());

The code is declaring a new list.

Rows are being added to the list.

Then the list is inserted.

 

I am NOT inserting each record individually. And there are 1317 records being inserted.

 

I'm curious why I'm racking up on the DML Limit Rows, when in fact, I'm doing one database insert... of a list that contains 1317 new records  ??

 

 

 

In Firefox, icons for people go missing, filled in with their name.

Run it in IE, looks correct.

 

Typically on dashboards using the 'table' object. But other places too within SFDC.

 

Is this a known issue?

Any ideas on what to do for Firefox?

 

Can provide screenshot examples.

I would like to programmatically get to the folder permissions where dashboards and reports are stored.

I can't find an API, and when using Data Loader, can't find a table that says this folder has these users/groups with permission.

 

This would save me a LOT of time. Any ideas?

 

Thx in advance.

 

I'm pretty good with writing the unit tests - typically over 90% coverage.

 

But !  I can't figure out how to write a test for a web service.

 

I get around this by the web service instantiating a class and passing whatever it gets. And structure it so that I can call this class from another program and get the class to pass testing.

 

But the web service ??

Developer console looks a bit different.

 

I'm not complain'   :-)

 

Where can I find some docs or release notes about what they are doing with it?

 

 

I have a typical 1-to-many, a header form with detail lines.

 

Standard forms, not VFP.

 

User enters data to the header. Saves.

 

Then enters detail lines.

 

Then the user is done.

 

How do I tell when the user is done? I need to run some code when the user completes the detail lines.

 

What I'm looking for is the equivalent of an event firing when the user moves off of the header record.

 

Any ideas?

 

 

BACKGROUND

As you know, there is no ‘SELECT *’ with Apex. You have to specify every field.

When you do a clone, you have to select all the fields.

If someone adds a field after you write the ‘clone’ program, you have to update the clone program with the field changes. PITA and not reliable.

 

OR

 

Another way is to use the ‘Describe’, get a list of fields, and assemble the SOQL statement.

That is what I did.

 

TESTING

As I was testing the program that creates the dynamic SOQL, I let it run, and grabbed the SOQL from the Developer Console. (system.debug).

I then pasted this into the SOQL window in Developer Console.

 

AND THE PROBLEM IS…

Fields that show in the ‘Account’  (Setup | Customize |Accounts | Fields), these same fields are in the ‘Describe’. Some are NOT in the WSDL, and will not SELECT when doing a SOQL statement.

 

That does not sound normal to me.  Any ideas???

 

Thanks in advance.

  • April 23, 2013
  • Like
  • 0

I have assembled XML with APEX. Want to write the XML to a file in a documents folder.

 

But can't find any reference on how to do this.

 

Any ideas?

 

Thx.

  • April 18, 2013
  • Like
  • 0

I have a regular dashboard that has a VisualForce page in one of the spaces, uses it's own controller.

 

This page has a call to Google Charts.

 

That all works, the chart picks up the data via the controller, via javascript, works perfect.

 

All this is in our DEV sandbox.

 

In Production, we are emailing the dashboards to the executives.

 

The question is ...

 

With a dashboard that has a Visual Force page in one of the spaces - and this page has a Google Chart - will this page email correctly???

 

. . .

You are probably asking why I'm building something new and still using Google? Because the new Salesforce Charting - the Gauge does not have the functionality.

 

Thanks in advance for your responses.

 

 

 

  • April 12, 2013
  • Like
  • 0

REPORT ISSUE:

 

The fields are defined numeric(4,0), no default value.

 

The records and fields are created/populated via apex.

 

My interest is only in fields where a WRITTEN value of zero (0) is created.

 

I'm not interested in records where I wrote some other value other than -0-.

 

I do have fields with a null, and this is correct, I did not write a value.

 

When I filter, I say where the field = 0.

 

Run the report, and I get records with 0 and with NULL.

 

Don't want that, just 0 - zero.

 

Any ideas?

 

Thx.

  • February 21, 2013
  • Like
  • 0

In the START, I'm setting values on some properties.

But in EXECUTE, the values are back to default - null.

 

I'm assuming my instantiated class stays in memory between calls to EXECUTE???

 

Here is the top part of the class...

 

global class clsMyBatchClass implements Database.Batchable<sObject>
{

// --------------------------
// PROPERTIES
// --------------------------

private map<Integer, String> mapMonths;
private map<String,Integer> mapPeriods;
private map<Integer,String> mapPeriodsBack;
private String strThisPeriod;
private Integer intThisPeriodIndex;


//-----------------------------------------------------------------
global Database.QueryLocator start(Database.BatchableContext bcObj) // QueryLocator represents a server-side cursor
//-----------------------------------------------------------------
{

system.debug('IN Start');
String strQuery = 'SELECT ID FROM Account';
LoadMap();

 

strThisPeriod = date.today().Year() + '-' + mapMonths.get(date.today().Month());

 

- - - -

There is a private method 'Load Map'. It will get a value to the string 'ThisPeriod'.

However, in EXECUTE, the maps won't work and I have to LoadMap on every EXECUTE.

 

Any idea what I'm doing wrong??

  • February 06, 2013
  • Like
  • 0

I have deployed a small app - with Apex, Tests - via a Change Set.

Usually use packages.

 

Well, as usual, there are changes to the functionality.

 

I need to remove the Apex code from production. But can't.

 

Removing the 'Change Set' won't remove the code.

 

So the question is, how do I remove apex classes and triggers that deployed via a Change Set??

 

Uber Thx In Advance.

  • January 29, 2013
  • Like
  • 0
I wonder instead of using select statement like this to work with sales force Api:
SOQL = "select AuthorId,Name, Description,Type from Document";

Is there any way that  can use store procedure?
Hi,

I have the below triggr to add in a contact to a contact role, whenever a contact is created and the account name  is the same as the opportunity name. It works fine but over the wwkened it threw ut a loan of LimitExceptions...I assume this was due to some Salesforce batch process, as it wasn't anything we were running. Nevertherless it highlights an issue with the code.
I have looked a blulkifacation, but can't see how I would get this inplace. 

Any thoughts?

Thx

trigger UpdateRoles on Opportunity (after insert, after update)
{
    for (Opportunity triggerOpportunity : Trigger.new)
    { 
        for(Contact contact : [Select ApplicantType__c from Contact where AccountId =: triggerOpportunity.AccountId and IsActive__c =: true])
        {
             if (contact.ApplicantType__c == 'Guarantor')
                {
              LIST<OpportunityContactRole> CR = [Select ContactId from OpportunityContactRole where OpportunityId =: triggerOpportunity.Id and Role =: 'Guarantor'];
             
                  if (CR.isEmpty())
                        {
                            OpportunityContactRole OCR = new OpportunityContactRole(OpportunityId = triggeropportunity.Id, ContactId = contact.id, Role = contact.ApplicantType__c, IsPrimary = false);
                            insert OCR;
                        }
                   
                }
        }
    }

}
right now im doing this

for(Integer i = 0 ; i < numOfAccounts; i++){
   Account tempAccount = new Account(Name = accountPrefix + '_test_' + i);
   tempAccount.BillingStreet = string.valueof(i) + ' test street';
   tempAccount.BillingCity = 'cityville';
   tempAccount.BillingState = 'aa';
   tempAccount.BillingPostalCode = '12345';
   tempAccount.BillingCountry = 'USA';
   accounts.add(tempAccount);
  }
  insert accounts;

for(integer x = 0 ; x < Accounts.size(); x++){
   // create account contats
   // emails will be username+icann_test_X_Y@gmail.com where X is number of account and Y is number of contact
   for(Integer y = 0 ; y < numOfContactsPerAccount; y++){
    Contact tempContact = new Contact(firstName = 'First_' + y, LastName = 'Last_' + y);
    tempContact.accountId = accounts[x].id;
    tempContact.email = gmailAccount + '+_test_' + x + '_' + y + '@gmail.com';
    contacts.add(tempContact);
   }
  }
  insert contacts;

Is there a way to add the map the accounts before theyre inserted so that when i create the contacts the id gets auto populated?
or should i continue with this method to add the parents, get the ids, loop through them and add children as needed?
How do you create a test class over a utility class when the methods are pretty much all just passing parms back and forth? For example I have a method that gets passed a name field and the method just does some formatting like first letter upper case the rest of each word lower case, etc.  finally it passes the name back.
Since tests are all static.  
Thanks for the help.
good day;

I am currently trying to bulk load data from a csv file to an object called vista_vasa__c, what I want is that from this view a trigger which tests the other catalogs based on the new record is triggered that view, for obvious reasons the load gives me problems because it exceeds the limit of 100 queries.

For my part I decided to change the method and let the load occurs without firing the trigger, ie the event did trigger off after upgrading instead of after insert. And to trigger the information update and create other catalogs based on the records made a scheduled hearing to make a list of records that were updated view and one to one by changing the value of a checkbox class false to true.

The problem is that when trying to do this if it is set to trigger on the object vista_vasa__c scheduled class does not perform the upgrade logs and catalogs are not created and updated.

My question is:
There any way you can trigger the shutter calling this from a scheduled class?

In the scheduled class can be configured to allow the execution of triggers?

Some details:
1. The burden will pretend to perform more than 10,000 records. Currently another co-development is setting the load from the tool informaticaCloud.

Two. Importantly, within the trigger object vista_vasa__c create and update records from other catalogs, which in turn triggers some fire themselves.

I'm sorry if I do not understand at some point, the truth'm using the google translator because I have not an advanced English language proficiency.

Expect an answer soon

greetings,
When we try to format some datetime using DateTime.format(dateTime,'EST'). Does it observes the daylight-time or not?
I mean does salesforce format the datetime as per EDT if EDT is running?

How to display a picklist combining picklists from two Salesforce accounts (one company has two branches). For eg.,

Salesforce Account picklist 1
Item 1
Item 3

Salesforce Account picklist 2
Item 2
Item 4

Combined picklist
Item 1
Item 2
Item 3
Item 4

What feature do I have to use? Is Salesforce to Salesforce one option? How far can I achieve this without any coding?
  • February 07, 2014
  • Like
  • 0
Unable to create Master - Detail Field on Child Object.
If I am trying to create 2nd level  Master - Detail. Or making Standard Object Account as Master.

Error is not showing you cannot create 2nd level Master Detail OR you cannot make Standard Object as Master.

Below if link to same discussion:

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008ybkIAA

This link provides 3 points to do to create this Master Detail relationship:
1. Create a lookup from the child object to the parent object.
2. Populate ALL the records with a valid lookup value to the parent.
3. Change the Lookup relationship to a Master - Detail relationship. This is only allowed if ALL RECORDS HAVE A VALID LOOKUP. Otherwise you'll get the error you describe.

What is 2nd point in this?

I have Customer who can have multiple accounts. In Customer there should be field which tell no. of accounts that Customer is having (through Roll Up Summary Field).
This seems a bit vague to me but someone recently approaced us  about a program that when injected into our existing classes, improves test coverage.

Is there any such  App/program  ?
Does anyone have experience or feedback on this?

Thanks.
Hello, 

I am trying to write a trigger that creates a new account when an orphaned Contact is created. The problem that I'm having is when I try to change the Account Record Type. FYI I am completely new to Apex and triggers (In fact this is only the second one I've written).


This is what I have so far :
 
(note:most of this is based on answers to questions I have found here and other websites. Just don't want to try to take credit for something that I didn't create myself :) )

trigger CreateAccountsForContacts on Contact (before insert) {
    Map<Contact, Account> accounts = new Map<Contact, Account>();
    for(Contact record: Trigger.new) {
        if(record.AccountId == null) {
            accounts.put(record, new Account(Name=record.FirstName+' '+record.LastName));
        }
    }
    insert accounts.values();
    for(Contact record: Trigger.new) {
        if(record.AccountId == null) {
            record.AccountId = accounts.get(record).Id;
        }
      
        if(record.RecordType.Name == 'Patient') {
            account.RecordTypeId = '012U000000014g1';
            }
    }
}

If I take out 

if(record.RecordType.Name == 'Patient') {
            account.RecordType.Name = 'Patient';
            }

it works fine, creates the account no problem. However I need it to change the Account Type based on the Contact Record Type, otherwise it could default to the wrong one. My idea was to check to see if the Contact Record Type was Patient, and if it was, set the Account Record Type to Patient as well.
 I'm sure it's something in the syntax I just don't understand. Any help would be appreciated. Thank you!
I'm suddenly getting this error when pushing unrelated code to production. The class in question has been working fine for over a year. The error lines are anywhere it says tstcont.submitCase();

@isTest
class TestWeb2CaseCont {
    static testMethod void testCaseWithContact(){
        Account a = TestUtils.getAccount('ut Acc1');
        insert a;
        Contact ct = TestUtils.getContact(a, 'ut Contact1');
        ct.Email = 'utContact1@testclass.com';
        insert ct;
       
        Web2CaseCont tstcont = new Web2CaseCont();
        tstcont.c.SuppliedEmail = ct.Email;
        tstcont.submitCase();
        System.assertEquals(ct.Id, tstcont.c.ContactId);
        System.assertEquals(a.Id, tstcont.c.AccountId);
    }
   
    static testMethod void testCaseWithoutContact(){       
        Web2CaseCont tstcont = new Web2CaseCont();
        tstcont.submitCase();
        System.assertEquals(tstcont.c.ContactId, null);
        System.assertEquals(tstcont.c.AccountId, null);
    }
   
    static testMethod void testPageParameters(){       
        Test.setCurrentPageReference(new PageReference('Page.Web2Case'));
        System.currentPageReference().getParameters().put('pline', 'None');
        System.currentPageReference().getParameters().put('Origin', 'None');
        System.currentPageReference().getParameters().put('co', 'None');       
       
        Web2CaseCont tstcont = new Web2CaseCont();
        tstcont.submitCase();
        System.assertEquals(tstcont.c.Product_Line__c,'None' );
        System.assertEquals(tstcont.c.Origin,'None' );
        System.assertEquals(tstcont.c.SuppliedCompany,'None' );
    }
   
    static testMethod void testAttachment(){       
        Attachment att = new Attachment();
        att.Name = 'ut attachment';
        att.Body = Blob.valueOf(att.Name);
        Web2CaseCont tstcont = new Web2CaseCont();
        tstCont.att = att;
        tstcont.submitCase();
    }
   
    static testMethod void testFailure(){          
        Web2CaseCont tstcont = new Web2CaseCont();
        tstcont.c = null;
        tstcont.submitCase();
        System.assertEquals(tstcont.msg, System.label.WebCaseFailure );
    }
}
  • February 03, 2014
  • Like
  • 0
I'm having some difficulty with deploying an Apex Trigger and its Test Class. The trigger works great in my Sandbox environment, and the test class covers 96% code coverage. I'm fairly new to Apex coding and can not seem to figure out what is causing the error. Any suggestions would be great!


Apex Trigger Code:

trigger activeWebsites on Account (before Insert, before Update) {
    //Updating the "Active Website(s)" field
    for(Account a : Trigger.New) {
        // Ford (Elite)
        if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Ford (Elite)';
        }
        //Ford (Elite) & Lincoln (Base)
        else if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c == 'Live') {
            a.Active_Website_s__c = 'Ford (Elite) & Lincoln (Base)';
        }
        //Ford (Elite) & Lincoln (Elite)
        else if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c == 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Ford (Elite) & Lincoln (Elite)';
        }
        //Lincoln (Base)
        else if(a.FordElite_Status__c != 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c == 'Live') {
            a.Active_Website_s__c = 'Lincoln (Base)';
        }
        //Lincoln (Elite)
        else if(a.FordElite_Status__c != 'Live' && a.Lincoln_Elite_Status__c == 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Lincoln (Elite)';
        }
        //Toyota (Lite)
        else if(((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Toyota (Lite)';
        }
        //Toyota (Pro)
        else if(((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Toyota (Pro)';
        }
        //Toyota (Lite) & Scion
        else if((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.Franchise_s__c.contains('Scion') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Toyota (Lite) & Scion';
        }
        //Toyota (Pro) & Scion
        else if((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.Franchise_s__c.contains('Scion') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Toyota (Pro) & Scion';
        }
        //Scion
        else if((a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c != 'Core' || a.FUSION_WEB__c != 'Pro') && a.Web_Effective_Date__c == null) || (a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c == 'Core' || a.FUSION_WEB__c == 'Pro') && a.Web_Effective_Date__c == null) || (a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c != 'Core' || a.FUSION_WEB__c != 'Pro') && a.Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Scion';
        }
        //Acura (Core)
        else if(a.Franchise_s__c == 'Acura' && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Acura (Core)';
        }
        //Acura (Pro)
        else if(a.Franchise_s__c == 'Acura' && a.FUSION_WEB__c == 'Premium' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Acura (Pro)';
        }
        //Honda
        else if(a.Franchise_s__c == 'Honda' && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Honda';
        }
        //Other
        else if((a.RecordTypeId == '012A0000000q4l1' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c != 'Acura' && a.Franchise_s__c != 'Honda' && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Other';
        }
        //Null
        else {
            a.Active_Website_s__c = null;
        }
    }
}


Apex Text Class:

@isTest
public class Test_activeWebsites {
    static testMethod void testRecordCreation() {
  
    //Create Ford (Elite) Account
    Account a1 = new Account();
    a1.RecordTypeId = '012G0000000qG8j';
    a1.Name = 'Ford (Elite)';
    a1.Franchise_s__c = 'Ford';
    a1.FordElite_Status__c = 'Live';
    insert a1;
  
    //Create Ford (Elite) & Lincoln (Base) Account
    Account a2 = new Account();
    a2.RecordTypeId = '012G0000000qH4j';
    a2.Name = 'Ford (Elite) & Lincoln (Base)';
    a2.Franchise_s__c = 'Ford; Lincoln';
    a2.FordElite_Status__c = 'Live';
    a2.Lincoln_Base_Status__c = 'Live';
    insert a2;
  
    //Create Ford (Elite) & Lincoln (Elite) Account
    Account a3 = new Account();
    a3.RecordTypeId = '012G0000000qH4j';
    a3.Name = 'Ford (Elite) & Lincoln (Elite)';
    a3.Franchise_s__c = 'Ford; Lincoln';
    a3.FordElite_Status__c = 'Live';
    a3.Lincoln_Elite_Status__c = 'Live';
    insert a3;
  
    //Create Lincoln (Base) Account
    Account a4 = new Account();
    a4.RecordTypeId = '012G0000000qH4e';
    a4.Name = 'Lincoln (Base)';
    a4.Franchise_s__c = 'Lincoln';
    a4.Lincoln_Base_Status__c = 'Live';
    insert a4;
  
    //Create Lincoln (Elite) Account
    Account a5 = new Account();
    a5.RecordTypeId = '012G0000000qH4e';
    a5.Name = 'Lincoln (Elite)';
    a5.Franchise_s__c = 'Lincoln';
    a5.Lincoln_Elite_Status__c = 'Live';
    insert a5;
  
    //Create Toyota (Lite) Account
    Account a6 = new Account();
    a6.RecordTypeId = '012A0000000q4l3';
    a6.Name = 'Toyota (Lite)';
    a6.Franchise_s__c = 'Toyota';
    a6.FUSION_WEB__c = 'Core';
    a6.Web_Effective_Date__c = system.TODAY();
    insert a6;
  
    //Create Toyota (Pro) Account
    Account a7 = new Account();
    a7.RecordTypeId = '012A0000000q4l3';
    a7.Name = 'Toyota (Pro)';
    a7.Franchise_s__c = 'Toyota';
    a7.FUSION_WEB__c = 'Pro';
    a7.Web_Effective_Date__c = system.TODAY();
    insert a7;
  
    //Create Toyota (Lite) & Scion Account
    Account a8 = new Account();
    a8.RecordTypeId = '012A0000000q4l3';
    a8.Name = 'Toyota (Lite) & Scion';
    a8.Franchise_s__c = 'Toyota; Scion';
    a8.FUSION_WEB__c = 'Core';
    a8.Web_Effective_Date__c = system.TODAY();
    a8.Scion_Web__c = 'Pro';
    a8.Scion_Web_Effective_Date__c = system.TODAY();
    insert a8;
  
    //Create Toyota (Pro) & Scion Account
    Account a9 = new Account();
    a9.RecordTypeId = '012A0000000q4l3';
    a9.Name = 'Toyota (Pro) & Scion';
    a9.Franchise_s__c = 'Toyota; Scion';
    a9.FUSION_WEB__c = 'Pro';
    a9.Web_Effective_Date__c = system.TODAY();
    a9.Scion_Web__c = 'Pro';
    a9.Scion_Web_Effective_Date__c = system.TODAY();
    insert a9;
  
    //Create Scion Account
    Account a10 = new Account();
    a10.RecordTypeId = '012A0000000q4l3';
    a10.Name = 'Scion';
    a10.Franchise_s__c = 'Scion';
    a10.Scion_Web__c = 'Pro';
    a10.Scion_Web_Effective_Date__c = system.TODAY();
    insert a10;
  
    //Create Acura (Core) Account
    Account a11 = new Account();
    a11.RecordTypeId = '012G0000000qF9V';
    a11.Name = 'Acura (Core)';
    a11.Franchise_s__c = 'Acura';
    a11.FUSION_WEB__c = 'Core';
    a11.Web_Effective_Date__c = system.TODAY();
    insert a11;
  
    //Create Acura (Pro) Account
    Account a12 = new Account();
    a12.RecordTypeId = '012G0000000qF9V';
    a12.Name = 'Acura (Pro)';
    a12.Franchise_s__c = 'Acura';
    a12.FUSION_WEB__c = 'Premium';
    a12.Web_Effective_Date__c = system.TODAY();
    insert a12;
  
    //Create Honda Account
    Account a13 = new Account();
    a13.RecordTypeId = '012G0000000qF9V';
    a13.Name = 'Honda';
    a13.Franchise_s__c = 'Honda';
    a13.FUSION_WEB__c = 'Pro';
    a13.Web_Effective_Date__c = system.TODAY();
    insert a13;
  
    //Create Other Account
    Account a14 = new Account();
    a14.RecordTypeId = '012A0000000q4l1';
    a14.Name = 'Other';
    a14.Franchise_s__c = 'Jeep';
    a14.FUSION_WEB__c = 'Pro';
    a14.Web_Effective_Date__c = system.TODAY();
    insert a14;
  
    }
}


Deployment Failure Error:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, activeWebsites: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.activeWebsites: line 41, column 1: []", Failure Stack Trace: "Class.M...
Hi Team,

I am trying to do a automated deployment every day. Every night querys for the latest change and then deploy only the changes to sandbox or prod.

I would like to use SVN as the source repository and Jenkins as the integration server to deploy with Ant script.

I have installed Force.com Migration Tool, the SVN and Jenkins successfully.
Now I need to configure Jenkins, is there any reference for me to accomplish this?

i have a concrete question:
The Ant script has a property file with password and URL, it will be needed during the deployment, where will it be saved and what can i do to keep the password not visible?

Regards,
Leo
When using force.com technologies (e.g. Apex or the point-and-click app logic),  is there support for Aspect Oriented Programming?
For example I'm looking for an easy way to inject my custom code before/after  major business functions, in order to measure how long they took. Or in order to audit them.

Thanks
I am trying to update a field on the Account object and keep receiving Compile Error: Expression cannot be assigned at line -1 column -1.


trigger UpdatePriceLevel on Account (before insert, before update, after insert, after update)
{
for(Account a : trigger.new)

{Account.Price_Level_Location__c = Ticket__c.Price_Level_Location__c ;}
}
I'm trying to set up the data loader to work with the command line.  The tutorials I've looked at suggest that I save the password key in the same folder that the data loader is in.  Unfortuantely, my work security won't let me save any files there.  Does it matter where they are saved as long as I include the path in the code?  Thanks
I am trying test the apex trigger below:

trigger IndustrytoAcctOpp on Customer_Product_Line_Item__c (Before Insert, Before Update) {

    Map<string, string> imap = new Map<string, string>();
   
    for(Industry_Definition__c i : [select id, Market_Segment__c, Strategic_Industry__c from Industry_Definition__c]){
        imap.put(i.Market_Segment__c, i.strategic_industry__c);
        system.debug('##########i.Market_segment__c:'+ i.market_segment__c);
    }
        
    Map<Id,Customer_Product_Line_Item__c> map_AccountID_CPLI = new Map<Id,Customer_Product_Line_Item__c>();
    Map<Id,Customer_Product_Line_Item__c> mapOpportunity = new Map<Id,Customer_Product_Line_Item__c>();
    Map<Id,Customer_Product_Line_Item__c> mapCPS = new Map<Id,Customer_Product_Line_Item__c>();
    List<Account> list_AccountsToUpdate = new List<Account>();
                     
    for ( Customer_Product_Line_Item__c cpli : trigger.new ) {
         cpli.Strategic_Industry__c = imap.get( cpli.Industry_Segment__c );
         map_AccountID_CPLI.put( cpli.Account__c, cpli );
         mapOpportunity.put(cpli.Opportunity__c, cpli);

         }

    For(Account a : [select id, Strategic_Industrycp__c, Market_Segment__c from account where id in: map_AccountID_CPLI.keySet()]){
        a.strategic_Industrycp__c = map_AccountID_CPLI.get( a.Id ).Strategic_Industry__c;
        if(a.market_segment__c.contains(map_AccountID_CPLI.get( a.Id ).Industry_Segment__c)){
        } else if(a.market_segment__c.contains(map_AccountID_CPLI.get( a.Id ).Industry_Segment__c)){
        } else{
        a.Market_Segment__c = a.market_segment__c + '; '+(map_AccountID_CPLI.get( a.Id ).Industry_Segment__c);
        }
        list_AccountsToUpdate.add( a );   
    }
    list_AccountsToUpdate.sort();
    update list_AccountstoUpdate;
   
    List<Opportunity> list_OpportunitiesToUpdate = new List<Opportunity>();
   
    For(Opportunity o : [select id, Strategic_Industry__c, Industry_Segment__c from Opportunity where id in: mapOpportunity.keySet()]){
    String existingsegments = o.Industry_Segment__c;
    string newSegment =mapOpportunity.get(o.id).Industry_Segment__c;
   
        o.strategic_Industry__c = mapOpportunity.get( o.Id ).Strategic_Industry__c;
        o.Industry_Segment__c = mapOpportunity.get( o.Id ).Industry_Segment__c;
     if(existingSegments == null){
         o.Industry_Segment_text__c = mapOpportunity.get( o.Id ).Industry_Segment__c;
     }else if (existingSegments.contains(mapOpportunity.get( o.Id ).Industry_Segment__c)== true){
         o.Industry_Segment_text__c = existingSegments;
     }else if (existingSegments.contains(mapOpportunity.get( o.Id ).Industry_Segment__c)==false ){
          o.Industry_Segment_text__c =  o.Industry_Segment_text__c + ', ' + mapOpportunity.get( o.Id ).Industry_Segment__c;
     }
   
        list_OpportunitiesToUpdate.add( o ); 
    }
    update list_OpportunitiesToUpdate;

}
This is my test class:


@isTest
private class TestIndustrytoAcctOpp{
     testmethod private static void TestTrigger() {
        Opportunity opt = new Opportunity();
       
    //Setup User
    User u1 = new user (Username = ' test@key.net',
                        alias='test',
                        LastName ='test',
                        email='test@key.net',
                        communityNickname='test',
                        TimeZoneSidKey='America/Los_Angeles',
                        LocaleSidKey='en_US',
                        EmailEncodingKey='ISO-8859-1',
                        ProfileId='00e30000000gAkF',
                        LanguageLocaleKey='en_US' );
    insert u1;
         System.runAs(u1) {
         // The following code runs as user 'u1' 
   
         System.debug('Current User: ' + UserInfo.getUserName());
         System.debug('Current Profile: ' + UserInfo.getProfileId()); }

    u1 = [select id from user where alias = 'test'];
   
   Test.startTest();
        Account a = new account ( name = 'accounttest', type = 'customer');
        Insert a;
       
        Opportunity o = new Opportunity (Recordtypeid = '012300000000Vnm',
                                            Name = 'opportunitytest',
                                            account=a,
                                            stagename = 'Budget',
                                            CloseDate = date.parse('1/1/2020'),
                                            Amount = 5.00,
                                            INCO_Terms__c = 'FCA',
                                            Related_Location__c = 'Walla Walla',
                                            Probability_Key_Will_Win_Order__c = 0.01,
                                            ForecastCategoryName = 'Pipeline',
                                            Equip_Services_Options_to_be_quoted__c = 'tegra',
                                            Op_Market_Position__c = '1 - Existing Equip - Existing App/Market (PB items a known app and current cust base)',
                                            Product_1__c = 'apple',
                                            Product1_Condition__c = 'raw',
                                            Customer_Products_Attached__c = null,
                                            Product1_Line_Capacity__c = '20000 lbs/hr');
        Insert o;
       
        Customer_Product__c c = new Customer_Product__c (name='apple');
        insert c;
       
        Customer_Product_Line_Item__c p = new Customer_Product_Line_Item__c(
                                        Customer_Product__c = c.id,
                                        Account__c = a.id,
                                        Opportunity__c = o.id,
                                        Condition_1__c = 'wet',
                                        Shape_1__c = 'whole',
                                        Capacity__c = '1',
                                        Industry_Segment__c = 'Apples',
                                        Strategic_Industry__c = 'Fresh Processed Fruit & Vegetable');
        insert p;
                    o.Strategic_Industry__c = 'Fresh Processed Fruit & Vegetable';
                    update o;
        Test.stopTest();
       
}
}

How do I test aupdatingthe market segment to the account on line 25?

Here is tyhe line of code:if(a.market_segment__c.contains(map_AccountID_CPLI.get( a.Id ).Industry_Segment__c))

Thank you