• jova
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies

Hi All,

 

I have the following requirement.

 

I want a TASK trigger (AFTER UPDATE) to execute a code that will write the Activity Type to a Google Spreadsheet in my Google Enterprise Account. 

 

Since this trigger will fire off any time a user records an Activity, I want the code to authenticate using a general Google account to write to this spreadsheet.

 

How can this be accomplished? The tutorials online are not helpful. As they do not cover Google Spreadsheets API inside Triggers. 

  • April 30, 2011
  • Like
  • 0

Hey All, 

 

I'm trying to retrieve a list of distinct Account IDs by the most recent closed--won opportunity. 

 

In theory, the query below would get me somewhat close, but of course I can't structure my query this way....

 

SELECT id, (SELECT id from Opportunity WHERE iswon = true ORDER BY closedate DESC) from Account

 

any kind and smart souls out there?

  • December 29, 2011
  • Like
  • 0

Hey Devs,

 

Just wanted to see what people thought their TOP 3 APEX TRIGGERS were. Could be triggers you've developed, are developing or wish to develop.

 

Mine are 

 

1) Prevent Lead/Contact dupes based on standard Email field **already implemented**

2) Prevent New Account Conversion based on existing email domain. (e.g. the Lead john@acme.com will be prevented from being converted if an account with Email syntax "@acme.com" already exists) **wish to build**

3) Unassign leads based on inactivity criteria

  • October 19, 2010
  • Like
  • 0

Hi All,

 

Is there a step by step tutorial on how to compile APEX code / deploy to server? I see code snippets everywhere, but not quite sure how to apply it to my Salesforce instance?

 

I realliy need the basics mapped out for me (i.e., Open Eclips IDE, Create New  Project, Paste Code Into....etc etc etc) Even a Hello World type example would be extremely helpful!

 

Thank you Salesforce Community.

  • September 01, 2010
  • Like
  • 0

With Winter '11, if you create a Site, a new Salesforce-provided class gets deployed to your org: MyProfilePageController.cls

 

There is test code in this class that fails if you don't have a portal user installed. This prevents you from doing anything in that org that requires running all tests.

 

Here is the error:

 

System.QueryException: List has no rows for assignment to SObject

Class.MyProfilePageController.testSave: line 78, column 35 External entry point

 

and the line in question:

 

 

User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];

 

This failure prevents doing any save from Eclipse. You can't deploy new code, edit object metadata files, etc. Complete showstopper.

 

Can anyone:

 * confirm this (we think reproducing will require that you create a new Site, perhaps the first Site in the org, after Winter 11)

 * think of a work-around (tried enabling self-service portal, but it doesn't create the required user type)

 

Anyone from Salesforce confirm that this is a bug and not something we're doing wrong?

 

Thanks!

 

Here is the entire class:

 

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public class MyProfilePageController {

    private User user;
    private boolean isEdit = false;
    
    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }
    
    public Boolean getIsEdit() {
        return isEdit;
    }
    
    public void edit() {
        isEdit=true;
    }    
    
    public void save() {
        if (user.contact != null) {              
            setContactFields(user.contact);
        }
        
        try {
            update user;
            if (user.contact != null) { 
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }
    
    public PageReference changePassword() {
        return Page.ChangePassword;
    }
    
    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }
    
    private void setContactFields(Contact c) {
        c.title = user.title;
        c.firstname = user.firstname;
        c.lastname = user.lastname;
        c.email = user.email;
        c.phone = user.phone;
        c.mobilephone = user.mobilephone;
        c.fax = user.fax;
        c.mailingstreet = user.street;
        c.mailingcity = user.city;
        c.mailingstate = user.state;
        c.mailingpostalcode = user.postalcode;
        c.mailingcountry = user.country;
    }

    static testMethod void testSave() {         
        // Modify the test to query for a portal user that exists in your org
        User existingPortalUser = [SELECT id, profileId, userRoleId FROM User WHERE UserRoleId <> null AND UserType='CustomerSuccess' LIMIT 1];
        System.assert(existingPortalUser != null, 'This test depends on an existing test portal user to run');
        
        String randFax = Math.rint(Math.random() * 1000) + '5551234';
        
        System.runAs(existingPortalUser) {
            MyProfilePageController controller = new MyProfilePageController();
            System.assertEquals(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
            System.assert(controller.isEdit == false, 'isEdit should default to false');
            controller.edit();
            System.assert(controller.isEdit == true);
            
            controller.cancel();
            System.assert(controller.isEdit == false);
            
            controller.getUser().Fax = randFax;
            controller.save();
            System.assert(controller.isEdit == false);
        }
        
        // verify that the user and contact were updated
        existingPortalUser = [Select id, fax, Contact.Fax from User where id =: existingPortalUser.Id];
        System.assert(existingPortalUser.fax == randFax);
        System.assert(existingPortalUser.Contact.fax == randFax);
    }

}

 

 

 

  • October 15, 2010
  • Like
  • 0