• sfdc_ninja
  • NEWBIE
  • 180 Points
  • Member since 2013


  • Chatter
    Feed
  • 5
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 53
    Replies
On Opportuntities we have the default "Next Steps" field, but it's not very long and we'd like to retain back history of the progress of a deal.  I've created a long text field "Sales Progress".  Here's what I'd like to do using a workflow trigger and field update:  Whenever a new entry is made in Next Steps, copy that entry over to Sales Progress and add it to the bottom (or top) of the existing text.  What would the formula look like?
Hey Everyone,

Beginner here, hoping if somebody could help me with my trigger. I'm attempting to create a new contract when a custom object is updated.

It allows me to save the trigger, but when i update the custom object I'm getting the following error:

Apex trigger AutoContract caused an unexpected exception, contact your administrator: AutoContract: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.AutoContract: line 11, column 1

Here is the code i'm using:

/////////////////////////////////////////////////

trigger AutoContract on Zuora__SubscriptionProductCharge__c (After Update) {
List<Contract> listContracts= new List<Contract>();
for(Zuora__SubscriptionProductCharge__c S: Trigger.new){
Contract C= new Contract();
C.Description=S.Zuora__ProductDescription__c;
C.accountid=S.Zuora__Account__r.Id;
C.Type_of_Sale__c=S.Zuora__ProductName__c;
C.Payment_Plan__c=S.Zuora__BillingPeriod__c;
C.Contract_Total__c=S.Zuora__ExtendedAmount__c;
C.StartDate=S.Zuora__EffectiveStartDate__c;
C.Account.Name=S.Zuora__Account__r.Name;
C.User__c='00550000002TLtx';
listContracts.add(c);
}

   if(listContracts.isEmpty()== false)
{Database.insert(listContracts);

}


  }

//////////////////////////////////////////////////

It seems that the line that is causing the error is the line where i'm trying to map the Contract account name. Can anybody help explain why i'm getting the error and what I need to add to fix?

Thank you!
hi, 

I am writing a trigger 

There are tow Objects 
1. Case (standard $Object)
2. Ticket__C (Custom $Object) 

Ticket has a lookup to Case, and a Case can have multiple ticket_C records but a ticket__c can be allocated to one case only. 

The requirement is when all the tickets associated to the case are closed but the case status is not closed after 5 days of the ticket__c being closed. the trigger should change the status of the Case to closed. 


fields on the objects
Case  - Status (Field)
Ticket__C- GLOBAL_Ticket_Status__c (Field)

The trigger should look at all the records of a ticket__c associated to case and check for GLOBAL_Ticket_Status__c== 'Closed' . 
If the status of all records are closed and case status is not changed to close for 5 days then change the status of the Case to closed. 

This is what i came up with 

Trigger Ticket on Ticket__c (after insert, after update) {
    Set<Id> closedTicketIds = new Set<Id>();
     for (Ticket__c ticket: Trigger.new) {
        if (ticket.GLOBAL_Ticket_Status__c == 'closed') {
            closedTicketIds.add(ticket.id);
        }   
    }
    List<Case> ticketForClosing= [SELECT Status FROM Case
                                  WHERE Ticket__c IN: closedTicketIds];
    for (Case c: ticketForClosing) {
        c.Status = 'closed';
    }
    update ticketForClosing;
}


Compile Error: No such column 'Ticket__c' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 34

Any help is appreciated

Thanks
Can we edit the Value Of Trigger.new in Before or After Trigger . If yes then in which case ? 

Thanks,
Wrote a very simple VF Page and Controller to show the Accounts that voted on certain Ideas. Here is the controller. Just aggregates the Up and Down votes on the Idea excluded internal votes. Pretty straight forward.

public class IdeaVotesByAccountController {

    public Idea thisIdea                                            {get;set;}
    public list<AggregateResult> upResults                          {get;set;}
    public list<AggregateResult> downResults                        {get;set;}

    public IdeaVotesByAccountController() {

        thisIdea = [Select Id, Title 
                    From Idea 
                    Where Id =: system.currentPageReference().getParameters().get('ideaid')];

        upResults = [SELECT Count(Id) Votes, CreatedBy.Contact.Account.Name Name
                    From Vote Where ParentId =: thisIdea.Id And Type = 'up' And CreatedBy.Contact.Account.Name != 'My Company Name' And CreatedBy.Contact.Account.Name != null
                    Group By CreatedBy.Contact.Account.Name 
                    Order By Count(Id) desc, CreatedBy.Contact.Account.Name];

        downResults = [SELECT Count(Id) Votes, CreatedBy.Contact.Account.Name Name
                    From Vote Where ParentId =: thisIdea.Id And Type = 'down' And CreatedBy.Contact.Account.Name != 'My Company Name' And CreatedBy.Contact.Account.Name != null
                    Group By CreatedBy.Contact.Account.Name 
                    Order By Count(Id) desc, CreatedBy.Contact.Account.Name];

    }

    public PageReference returnToIdea() {

        PageReference pg = new PageReference('/' + thisIdea.Id);
        pg.setRedirect(true);
        return pg;

    }
}

My problem is coming when trying to write a unit test. When I say that we are excluding internal votes, basically, we are only counting portal user votes, from portal users that do not have a company name of my company name. So in order to test, I need to be able to test all 3 scenarios scenarios
  1. a vote from within the SF UI, not through the portal (No Issue)
  2. a vote by a portal user outside of my company (ISSUE)
  3. a vote by a portal user inside of my company (ISSUE)

The issue comes with trying to create a vote from a portal user. Here is my test code that I have. The first test method works fine, the second method is throwing an error

@isTest
private class IdeaVotesByAccountControllerTest {

    private static final Profile nonPortalProf = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
    private static final Profile portalProf = [SELECT Id FROM Profile WHERE Name Like '%portal%' limit 1];
    private static final Account a = TestClassObjectUtility2.accountCreator('Test Account');
    private static final Contact con = TestClassObjectUtility2.contactCreator(a.Id, 'Joe', 'Schmoe');
    public static final Community zone = [Select Id From Community Limit 1];
    public static final PageReference pg = Page.IdeaVotesByAccount;
    public static final User nonPortalUser = TestClassObjectUtility2.userCreator(true, nonPortalProf);
    public static final User portalUser;
    public static IdeaVotesByAccountController controller;

    static {
        portalUser = TestClassObjectUtility2.userCreator(false, portalProf);
        portalUser.ContactId = con.Id;
        insert portalUser;
    }
    //WORKS FINE
    static testmethod void BaseTestNonPortalUser() {

        Idea myIdea = TestClassObjectUtility2.ideaCreator(true, 'Title', 'Body', zone.Id);
        myIdea = [Select Id From Idea Where Id =: myIdea.Id];

        pg.getParameters().put('ideaid', myIdea.id);
        Test.setCurrentPage(pg);

        controller = new IdeaVotesByAccountController();

        system.assertEquals(0, controller.upResults.size());
        system.assertEquals(0, controller.downResults.size());

        system.runAs(nonPortalUser){
            Vote v = TestClassObjectUtility2.voteCreator(true, myIdea.Id, 'up');
        }

        controller = new IdeaVotesByAccountController();
        system.assertEquals(0, controller.upResults.size());

    }
    //FAILS
    static testmethod void BaseTestPortalUser() {

        Idea myIdea = TestClassObjectUtility2.ideaCreator(true, 'Title', 'Body', zone.Id);

        pg.getParameters().put('ideaid', myIdea.id);
        Test.setCurrentPage(pg);

        controller = new IdeaVotesByAccountController();

        system.assertEquals(0, controller.upResults.size());
        system.assertEquals(0, controller.downResults.size());

        system.runAs(portalUser){
             //THIS LINE IS FAILING
             Vote v = TestClassObjectUtility2.voteCreator(true, myIdea.Id, 'up');
        }

        controller = new IdeaVotesByAccountController();
        system.assertEquals(1, controller.upResults.size());

    }
}

It throws the error on the line where I am trying to insert the Vote object. The error is shown below

User-added image

System.DmlException: Insert failed. First exception on row 0; first error: COMMUNITY_NOT_ACCESSIBLE, You do not have permission to access the zone that this entity belongs to. You must be given permission to the zone before you can access this entity.: [ParentId]

So apparently the portal user needs permission to the community. The issue is I have searched around for documentation but I can't seem to find out how to do this. Has anyone seen this before. How can I overcome this error???

Any help is greatly appreciated.
I have been creating a Business Hours Calculation engine in the past few weeks and I have my code working exaclty how I want it and now have moved on to test code. As Bob Buzzard Pointed out, although not well documented Business Hour Data is available in Test Code Context. Holidays, however are not, you have to create your own. This can be verified by this simple test below

@isTest
private class BusinessHoursMathTest {

    static void SimpleTest(){

        List<BusinessHours> bhs = [select id from BusinessHours where IsDefault=true];
        System.assert(bhs.size() == 1);

        List<Holiday> holidays = [Select Id From Holiday];
        system.assert(holidays.size() == 0);

        List<Account> accs = [select id from Account];
        System.assert(accs.size() == 0);
    }  
}


So I would think that it would be as simple as Querying for Default business Hours, creating a new Holiday, and associating that Holiday with the Business Hours. Something like this

BusinessHours defaultBH = [Select Id From BusinessHours Where IsDefault = True];
Holiday hol = new Holiday();
hol.Name='Test holiday';
hol.activitydate = System.Today();
insert hol;


The holiday is inserted, but there is no affiliation of that Holiday with the Business Hours. I have found that there is no way to affiliate the Holiday with the business hours with Apex. This means I can't properly test my class. I can still get the code coverage I need to deploy, but I can't properly test all logic branches this way. If I wanted to package this that would be a big no no.

MY QUESTION

Does anyone know of a workaround for this. How can I properly test business hour logic without being able to create holidays and associate them with business hours in the test class. Has anyone come up with a way to do this or can you let me know if I have missed anything or not going about this the proper way. I'm pulling my hair out with this one.

I have created a page that uses jQuery and javascript remoting in order to allow the end user to quickly add rows to a table on the page.  The table represents top accounts for that users territory.  When a user clicks on the Add button, I use jQuery to add a new row to the table with an input that uses autocomplete to allow the user to choose an account.  That works fione but my issue is I want to add 2 picklist fields (that are picklists on the account object) into the table as well so the user can set these picklists.

 

I am having the hardest time trying to figure out how to dynamically add a select field with the options being pulled from a controller property.  I couls use javascript remoting each time the button is clicked to grab all the picklist values, but this doesnt seem that efficient.  Isnt there a way I can grab the slect options from the controller right within my jQuery

 

Here is the javascript that I have so far and doesnt work

 

j$('#addAccount').click(function(){
    	
//This does not work
var list = '{!ListValues}'; console.log(list); list.each(function() { console.log(this); });

//I would like these picklists to be working picklists that i can pass back to the controller in a javascript remoting call when the row is saved j$('#topAccounts table tbody').append('<tr data-SFid=""><td><input id="newAccount"></input></td><td>picklist</td><td>another picklist</td></tr>'); //AUTOCOMPLETE j$('#newAccount').autocomplete({ minLength: 2, source: function(request, response) { queryTerm = request.term; TerritotyPageController.searchAccounts(request.term, function(result, event){ if(event.type == 'exception') { alert(event.message); } else { var accountObjects = result; response(accountObjects); } }); }, focus: function( event, ui ) { j$('#newAccount').val( ui.item.Name ); return false; }, select: function( event, ui ) { j$('#newAccount').val( ui.item.Name ); j$(this).closest('tr').attr('data-SFid', ui.item.Id); console.log('Here it is' + j$(this).closest('tr').attr('data-SFid')); return false; }, }).data( "ui-autocomplete" )._renderItem = function( ul, item ) { var entry = "<a>" + item.Name; entry = entry + "</a>"; entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>"); return j$( "<li></li>" ) .data( "ui-autocomplete-item", item ) .append( entry ) .appendTo( ul ); }; j$(this).hide(); j$('.saveButton.account').show(); j$('.cancelButton.account').show(); });

 

 

Here is the controller property to grab the list values

 

public List<String> getListValues() {
		List<String> options = new List<String>();
	        
	    Schema.DescribeFieldResult fieldResult = Account.Territory_Plan_Top_Account_Reason__c.getDescribe();
	    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
	        
	    for( Schema.PicklistEntry f : ple)
	    {
	    	options.add(f.getValue());
	    }       
	    return options;
	}

 

Any help or insight would be greatly appreciated.  Thanks so much

 

Chris

I was working on the Getting Started with Apex Triggers and my code doesn't seem to be working, could someone please, help me find the error. I have stared at it for awhile and can't seem to figure out where my mistake is, any help that can be provided would be greatly appreciated, thank you in advance for your help and cooperation.

trigger AccountAddressTrigger on Account (before insert, before update) {
    for (Account a : [SELECT BillingPostalCode, ShippingPostalCode FROM Account WHERE BillingPostalCode != null AND Match_Billing_Address__c = TRUE AND Id IN :Trigger.New]) {
        a.ShippingPostalCode = a.BillingPostalCode;
    }
}

And my error is: Challenge not yet complete... here's what's wrong: 
Setting 'Match_Billing_Address__c' to true did not update the records as expected.
i write a trigger that copy one obj to another
but when it copy it return a id instated of name
how to solve this
by using formula or some changes in my trigger
(i want name instated of id)
For example, the Owner of an Opportunity record is Jim Smith.  When I use the formula (trigger)to pass his name to the associated new object, I only get his User ID. 
 
Thank you to Deepak K Anand for showing me my first intro to code on the Success Community.  I have a new requirement and thought it would be best to bring it over to this forum.  (my first ever post here... feeling kind of cool at the moment).  Below code is for a custom clone button on cases which forces the user to select a record type.  On the new record that is created from the clone button, can a specific picklist value be selected? (standard picklist field istype)


if("{!Case.RecordTypeId}" == "012a0000001Vtj7"){
    location.replace(
        "/setup/ui/recordtypeselect.jsp?" +
        "ent=Case&" +
        "retURL={!Case.Id}&" +
        "save_new_url=/{!Case.Id}/e?clone=1"
    );
}
else{
    location.replace(
        "/{!Case.Id}/e?clone=1"
    );
}
I have been creating a Business Hours Calculation engine in the past few weeks and I have my code working exaclty how I want it and now have moved on to test code. As Bob Buzzard Pointed out, although not well documented Business Hour Data is available in Test Code Context. Holidays, however are not, you have to create your own. This can be verified by this simple test below

@isTest
private class BusinessHoursMathTest {

    static void SimpleTest(){

        List<BusinessHours> bhs = [select id from BusinessHours where IsDefault=true];
        System.assert(bhs.size() == 1);

        List<Holiday> holidays = [Select Id From Holiday];
        system.assert(holidays.size() == 0);

        List<Account> accs = [select id from Account];
        System.assert(accs.size() == 0);
    }  
}


So I would think that it would be as simple as Querying for Default business Hours, creating a new Holiday, and associating that Holiday with the Business Hours. Something like this

BusinessHours defaultBH = [Select Id From BusinessHours Where IsDefault = True];
Holiday hol = new Holiday();
hol.Name='Test holiday';
hol.activitydate = System.Today();
insert hol;


The holiday is inserted, but there is no affiliation of that Holiday with the Business Hours. I have found that there is no way to affiliate the Holiday with the business hours with Apex. This means I can't properly test my class. I can still get the code coverage I need to deploy, but I can't properly test all logic branches this way. If I wanted to package this that would be a big no no.

MY QUESTION

Does anyone know of a workaround for this. How can I properly test business hour logic without being able to create holidays and associate them with business hours in the test class. Has anyone come up with a way to do this or can you let me know if I have missed anything or not going about this the proper way. I'm pulling my hair out with this one.
I have an error that is caused by the Case.AccountId field equalling NULL when inside a Before Insert Case Trigger. When viewing the page layout before first saving the record, the account is visibly populated. When logged in as an administrator everything works properly, but when logged in as a custom profile the trigger cannot read the account id. I have checked field level security on the Case object and all profiles have the Visible box checked. Does anyone know any other common reasons why a field would show up as NULL for only certain profiles?

Thanks for any help you can provide.
Hi All,

Can the below test class be optimized 

if I am having a class
---------------------------------------------------------
public class TVRemoteControl {
    // Volume to be modified
    Integer volume;
    // Constant for maximum volume value
    static final Integer MAX_VOLUME = 50;  
  
    // Constructor
    public TVRemoteControl(Integer v) {
        // Set initial value for volume
        volume = v;
    }
      
    public Integer increaseVolume(Integer amount) {
        volume += amount;
        if (volume > MAX_VOLUME) {
            volume = MAX_VOLUME;
        }
        return volume;
    }
  
    public Integer decreaseVolume(Integer amount) {
        volume -= amount;
        if (volume < 0) {
            volume = 0;
        }
        return volume;
    }  
  
    public static String getMenuOptions() {
        return 'AUDIO SETTINGS - VIDEO SETTINGS';
    }
     
}
--------------------------------------------------------------
When I will write the test case -

@isTest
class TVRemoteControlTest {
    @isTest static void testVolumeIncrease() {
        TVRemoteControl rc = new TVRemoteControl(10);
        Integer newVolume = rc.increaseVolume(15);
        System.assertEquals(25, newVolume);
    }
  
    @isTest static void testVolumeDecrease() {
        TVRemoteControl rc = new TVRemoteControl(20);
        Integer newVolume = rc.decreaseVolume(15);
        System.assertEquals(5, newVolume);      
    }
      
    @isTest static void testVolumeIncreaseOverMax() {
        TVRemoteControl rc = new TVRemoteControl(10);
        Integer newVolume = rc.increaseVolume(100);
        System.assertEquals(50, newVolume);      
    }
  
    @isTest static void testVolumeDecreaseUnderMin() {
        TVRemoteControl rc = new TVRemoteControl(10);
        Integer newVolume = rc.decreaseVolume(100);
        System.assertEquals(0, newVolume);      
    }
  
    @isTest static void testGetMenuOptions() {
        // Static method call. No need to create a class instance.
        String menu = TVRemoteControl.getMenuOptions();
        System.assertNotEquals(null, menu);
        System.assertNotEquals('', menu);
    }
}
--------------------------------------------
Can TVRemoteControl rc = new TVRemoteControl be initialised once and can be reused.

Regards
Hi Experts i am writing a trigger on account object if  create contact checkbox is checked  then  it should create the contact with the same values given in  account  such as account name ,phone etc

here is my trigger

trigger accctrg on Account (after insert,after update) {
   Account acc = trigger.new[0];
    if(recclass.isrecursive = true){
         recclass.isrecursive=false;       
         account ac = new account(id= acc.Id);
        if(acc.create_contact__c== true){
   Contact con = new Contact();
   con.LastName = ac.Name;
   con.Phone = ac.Phone;
   con.AccountId = acc.Id;
             update con;
         }
       }
}
trigger class to avoid recursion

public with sharing class recclass {
public static Boolean Isrecursive = true;
}

 iam not getting any errors but my code is not working
 Regards
 Raghava
We are facing an issue while deploying Apex Trigger to production.
Please find the issue below.

Failure Message: "System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.", Failure Stack Trace: "External entry point"

Please do the needful.
Regards,
D.Narendra
+91-9940034791
I am getting a null pointer exception on line 23 column 1  ( highlighed in bold in the below code). I am trying to migrate a visualforce page controller and a test class into production. I am not sure what needs to be fixed. 

@isTest
public class CS_NewQuoteRequestFromRepeater_test{

    static testMethod void quoteRequestCreationTest(){
        Repeater__c testRepeater = new Repeater__c();
        insert testRepeater;
       
        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        opp.StageName = 'Prospect';
        opp.CloseDate = System.today();
        insert opp;
       
        Oracle_Ship_To_Account__c oa = new Oracle_Ship_To_Account__c();
        oa.Customer_Name__c = 'Test Oracle Customer';
//added by ckn to troubleshoot deployment issues
        oa.ADDRESSID_CONTACT_ID__c ='12345';
        insert oa;
       
        ApexPages.Pagereference vfPage = Page.NewQuoteRequestFromRepeater2Step;
        Test.setCurrentPage(vfPage);
        ApexPages.currentPage().getParameters().put('repeaterID', testRepeater.Id);
       
        CS_NewQuoteRequestFromRepeater2StepCC controller = new CS_NewQuoteRequestFromRepeater2StepCC();
        controller.QuoteRequest.Oracle_Ship_To_Account_c__c = oa.Id;

        controller.QuoteRequest.Quote_Name__c = 'Test Quote';
        controller.QuoteRequest.Opportunity__c = opp.Id;
       
        //return url test
        system.assertEquals(controller.getReturnUrl(), '/' + testRepeater.Id);
       
        try{
            ApexPages.Pagereference saveRedirectPage = controller.save();
            system.debug(saveRedirectPage.getUrl());
        }catch(Exception e){
            //system.assert(false);
        }
    }
}
I am using sales force API with C#. in the query that I am writing I am not sure how pass parameter to the select query. My query works when it looks like this:
            SOQL = "select AuthorId,Name, Description,Type from Document where AuthorId='005G0000003s4a8IAA'";     

But I am not sure how to replace the value in AuthorId that is '005G0000003s4a8IAA' to variable that I am passing to this method like: id?
Hey everyone,

I successfully deployed my first trigger (and test class) a couple weeks ago. I'm now trying to deploy my second trigger (and test class), but I'm receiving this error when valdiating the deployment:

Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.OppIndustry: line 8, column 1"

From what I understand, my triggers should be bulkified. Perhaps it's a problem with one of my test class? Would someone be kind enough to look through my first trigger and class, and my second trigger and class, and tell me where the problem might be? Thanks!


Here is the first trigger I already deployed successfully:

trigger RenewalProcess on Opportunity (after insert, after update) {
   
   Set<String> allOpps = new Set<String>();
    for(Opportunity renewalOpp : Trigger.new) {
        if (renewalOpp.Renewed_Opportunity__c != null) {
            allOpps.add(renewalOpp.Renewed_Opportunity__c);
         }
    }

    List<Opportunity> potentialOpps = [SELECT Id FROM Opportunity WHERE Id IN :allOpps];

    Map<String,Opportunity> opportunityMap = new Map<String,Opportunity>();
        for (Opportunity o : potentialOpps) {
            opportunityMap.put(o.id,o);
        }
   
    List<Opportunity> firstOppsToUpdate = new List<Opportunity>();

        for (Opportunity renewalOpp : Trigger.new) {
             if (renewalOpp.Renewed_Opportunity__c != null) {
             Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
             renewedOpp.Renewal_Process_Checkbox__c = TRUE;
             firstOppsToUpdate.add(renewedOpp);
           }
           
        }

  update firstOppsToUpdate;
     
     List<Opportunity> oppsToUpdate = new List<Opportunity>();
       
        for (Opportunity renewalOpp : Trigger.new) {
            if (renewalOpp.Renewed_Opportunity__c != null && renewalOpp.StageName.equals('Closed Won')) {
                Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
                renewedOpp.Renewal_Status__c = 'Renewed';
                oppsToUpdate.add(renewedOpp);
            }
            else if(renewalOpp.Renewed_Opportunity__c != null && !renewalOpp.IsClosed) {
                Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
                renewedOpp.Renewal_Status__c = 'In Negotiations';
                oppsToUpdate.add(renewedOpp);
            }
            else if(renewalOpp.Renewed_Opportunity__c != null && (renewalOpp.StageName.equals('Closed Lost') || renewalOpp.StageName.equals('Closed Stalled'))) {
                Opportunity renewedOpp = opportunityMap.get(renewalOpp.Renewed_Opportunity__c);
                renewedOpp.Renewal_Status__c = 'Did Not Renew';
                oppsToUpdate.add(renewedOpp);
            }
           
        }
   
    update oppsToUpdate;
   




Here is the test class I succesfully deployed with that trigger:

@isTest
public class TestRenewalProcess{
    static testMethod void testRenewals() {
       
        Test.startTest();
       
        Contact con1 = new Contact();
        con1.FirstName = 'John';
        con1.LastName = 'Hopkins';
        Insert con1;
       
        Contact con2 = new Contact();
        con2.FirstName = 'Bob';
        con2.LastName = 'Smith';
        Insert con2;
       
        Contact con3 = new Contact();
        con3.FirstName = 'Tom';
        con3.LastName = 'Hill';
        Insert con3;
       
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'Unilever Annual';
        opp1.StageName = 'Closed Won';
        opp1.CloseDate = date.parse('1/30/13');
        opp1.Renewal__c = 'No';
        opp1.Approved__c = TRUE;
        opp1.Lead_Origin__c = 'Inbound Lead';
        opp1.SP__c = TRUE;
        opp1.Primary_Contact__c = con1.Id;
        insert opp1;
       
        Opportunity opp2 = new Opportunity();
        opp2.Name = 'Unilever Annual Renewal';
        opp2.StageName = 'Closed Won';
        opp2.CloseDate = date.parse('6/30/13');
        opp2.Renewal__c = 'Yes';
        opp2.Approved__c = TRUE;
        opp2.Lead_Origin__c = 'Inbound Lead';
        opp2.SP__c = TRUE;
        opp2.Primary_Contact__c = con1.Id;
        opp2.Renewed_Opportunity__c = opp1.Id;
        insert opp2;
       
        Opportunity opp3 = new Opportunity();
        opp3.Name = 'Viacom Annual';
        opp3.StageName = 'Closed Won';
        opp3.CloseDate = date.parse('4/30/13');
        opp3.Renewal__c = 'No';
        opp3.Approved__c = TRUE;
        opp3.Lead_Origin__c = 'Inbound Lead';
        opp3.Primary_Contact__c = con2.Id;
        opp3.SP__c = TRUE;
        insert opp3;
       
        Opportunity opp4 = new Opportunity();
        opp4.Name = 'Viacom Annual Renewal';
        opp4.StageName = 'Call Scheduled';
        opp4.CloseDate = date.parse('7/30/13');
        opp4.Renewal__c = 'Yes';
        opp4.Lead_Origin__c = 'Inbound Lead';
        opp4.Primary_Contact__c = con2.Id;
        opp4.Renewed_Opportunity__c = opp3.Id;
        insert opp4;
       
        Opportunity opp5 = new Opportunity();
        opp5.Name = 'Sony Annual';
        opp5.StageName = 'Closed Won';
        opp5.CloseDate = date.parse('4/30/13');
        opp5.Renewal__c = 'No';
        opp5.Approved__c = TRUE;
        opp5.Lead_Origin__c = 'Inbound Lead';
        opp5.Primary_Contact__c = con3.Id;
        opp5.SP__c = TRUE;
        insert opp5;
       
        Opportunity opp6 = new Opportunity();
        opp6.Name = 'Sony Annual Renewal';
        opp6.StageName = 'Closed Lost';
        opp6.CloseDate = date.parse('9/30/13');
        opp6.Renewal__c = 'Yes';
        opp6.Lead_Origin__c = 'Inbound Lead';
        opp6.Lost_Stalled_Detail__c = 'yo mama';
        opp6.Primary_Contact__c = con3.Id;
        opp6.Renewed_Opportunity__c = opp3.Id;
        opp6.Who_We_Lost_To__c = 'test';
        opp6.Amount = 5000;
        insert opp6;
       
        Test.stopTest();

}
}




Here is the trigger I'm trying to deploy now:

trigger OppIndustry on Opportunity (before insert, before update) {
   
    Set<String> relevantAccountIds = new Set<String>();
     for (Opportunity o : Trigger.new) {
            relevantAccountIds.add(o.AccountId);
        }
   
    List<account> accountsWithIndustry = [SELECT Id, Industry FROM Account WHERE Id IN :relevantAccountIds];
   
    map<string,string> accountsMap = new map<string,string>();
     for(Account a : accountsWithIndustry) {
        accountsMap.put(a.Id,a.Industry);
        }
   
    for(Opportunity oppInTrigger : Trigger.new) {
        String oppAccountIndustry = accountsMap.get(oppInTrigger.AccountId);
        IF(oppAccountIndustry != NULL && oppAccountIndustry != 'Agency') {
            oppInTrigger.Opportunity_Industries__c = oppAccountIndustry;
        }
    }
}




Here is the test class for that trigger I'm trying to deploy:

@isTest
public class TestOppIndustry{
    static testMethod void testOpps() {
       
        Test.startTest();
       
        Contact con1 = new Contact();
        con1.FirstName = 'John';
        con1.LastName = 'Hopkins';
        Insert con1;
       
        Account acc1 = new Account();
        acc1.Name = 'Unilever';
        acc1.Region__c = 'CSA';
        acc1.Industry = 'Consumer Goods';
        acc1.Status__c = 'Prospect';
        acc1.Website = 'www.unilever.com';
        acc1.FB_Page_1_Fans__c = 300;
        acc1.FB_Page_1_Link__c = 'www.facebook.com/unilever';
        insert acc1;
       
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'Unilever Annual';
        opp1.StageName = 'Active Discussions';
        opp1.CloseDate = date.parse('1/30/13');
        opp1.Renewal__c = 'No';
        opp1.Lead_Origin__c = 'Inbound Lead';
        opp1.Primary_Contact__c = con1.Id;
        opp1.AccountId = acc1.Id;
        insert opp1;
       
        Test.stopTest();
    }
}
Hi, 
 
This is my code while creating a portal user i have to checking that user information its showing the error null pointer exception . i highlighted that line. how can i fix this .

public with sharing class SiteRegisterController {
     
   // private static Id PORTAL_ACCOUNT_ID = '001x000xxx35tPN';
    private static Id PORTAL_ACCOUNT_ID;
    public SiteRegisterController () {
    }

    public String username {get; set;}
    public String email {get; set;}
    public String password {get; set {password = value == null ? value : value.trim(); } }
    public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
    public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
     
    private boolean isValidPassword() {
        return password == confirmPassword;
    }
   
    public PageReference registerUser() {
        // it's okay if password is null - we'll send the user a random password in that case
        if (!isValidPassword()) {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
            ApexPages.addMessage(msg);
            return null;
        }   
        User u = new User();
        u.Username = username;
        u.Email = email;
        u.CommunityNickname = communityNickname;
       
        String accountId = PORTAL_ACCOUNT_ID;

        // lastName is a required field on user, but if it isn't specified, we'll default it to the username
        String userId = Site.createPortalUser(u, accountId, password);   //*******  This line showing error null pointer exception.
        if (userId != null) {
            if (password != null && password.length() > 1) {
                return Site.login(username, password, null);
            }
            else {
                PageReference page = System.Page.SiteRegisterConfirm;
                page.setRedirect(true);
                return page;
            }
        }
        return null;
    }
}

Advance Thanks
Maheshwar
we have an out of office checkbox on the User object and an out of office start date and out of office end date.  Would love when the end date = TODAY the checkbox gets unchecked automatically.  I tried a workflow but the user account actually has to be edited in order for it to update.  Is there an apex trigger that can accomplish this?
  • February 19, 2014
  • Like
  • 0
I have only 2 rollup summary fields on the Opportunity object left and need to install an AppExchange package that uses 3 roll-up summary fields. I was told a simple trigger to replace one of the rollups would work but I have no clue how to do it. I need to populate a field called "Inactive Product Count" counting the number of Opportunity Products on the Opportunity that don't have the "Active" box checked (this then feeds a validation rule not allowing users to save Opps as closed-won if the count is greater than zero). Can anyone help?
Hello,

i woul like to delete some old classes in our Production Environment:
I read in an other answer that i cant to this directly in production, i must du this in the sandbox and then Transport.

I now do this:
- make a freh sandbox
- delete there all classes

My question: How can i now make a Transport with the deletet classes? I can only add existing classes to my Transport?

Best regards,
Patrick
I have a custom picklist field Status__c with 6 values ActiveA, ActiveB,ActiveC,ClosedP,ClosedQ,ClosedR


I am trying to write a Workflow rule such that when Status__c is changed from any of the Active values to the Closed values, populate the Closed_Date__c field with date today().


This is my workflow rule but it is giving syntax error
Error: Field Status__c is a picklist field. Picklist fields are only supported in certain functions.

AND(
ISCHANGED(Status__c), ISPICKVAL( PRIORVALUE(CONTAINS(Status__c,"Active"))), ISPICKVAL(CONTAINS(Status__c,"Closed"))
)

User-added image


From the above  the page is "Policy" . we can see policy  (Amount). And from policy related lists we can see "Transaction" object  "Amount"  field and  from "Transfer "  object we see  "Expected Premium"  (All are Marked).

Now,

for a transfer record to update, the match must occur within the same policy record.  Attached is a screenshot of a policy .This would be considered a match. the associated transfer record has an Expected Premium value within 10% of the associated transaction record’s Amount.  A match can only occur if both records (transfer and transaction) are associated to the same Policy ID. If the match occures then I have a checkbox on Transfer record. so it enables to True.

Can we acheive this through formulae or Trigger? If any one pls provide trigger for this scinario.
  • February 18, 2014
  • Like
  • 0
Hi,

I am having issues with the "ant-salesforce.jar: No such file or directory" when installing the migration tool on my mac.

i followed these instructions from the web.  Apparently, there have been a lot people having the same problem.  But this didn't work.

Download the Force.com Migration tool.
Unzip the files.
Open the terminal and goto the unzipped folder (/Download/salesforce_ant_api version)
Copy and Paste this: sudo cp ant-salesforce.jar /usr/share/ant/lib/ant-salesforce.jar
Enter your password.

Any help will be appreciated.