• nununi
  • NEWBIE
  • 120 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 21
    Replies
Hi, I am trying to copy data from Lead to a custom object using javascript button. When a lead rich text field contains line spaces, it gives me an error. So i used URLencode which resolves the error but the spaces are substituted with '+'. Is there a way to copy the text as is (including line spaces)?
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 


var p1 = new sforce.SObject("Place__c"); 
p1.Name = '{!Lead.Place_1__c}';
p1.Place_Text__c = '{!URLENCODE(Lead.Place_1_About__c)}';


var result = sforce.connection.create([p1]);


if(result[0].getBoolean("success")){
   alert('New record updated successfully');
}
else{
  alert('Error : '+result);
}

example:
Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro v v v vPlace 1 Intro Place 1 IntroPlace 1.

Intro Place 1 Intro Place 1 Intro. Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro Place 1 Intro v v Place 1 Intro

gets converted to

Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+v+v+v+vPlace+1+Intro+Place+1+IntroPlace+1.%3Cbr%3E%3Cbr%3EIntro+Place+1+Intro+Place+1+Intro.%C2%A0Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+Place+1+Intro+v+v+Place+1+Intro
I have a requirement to create a button on the lead object that creates two custom object records with fields pre-opulated from the Lead record. Can someone provide me a sample code to start with? 
Hello developers,

I have a text field test__c on an object TestObject__c. This filed has values seperated by commas (a,b,c,d). In my apex class, I would like to pass these values into a list TestList. Can someone please provide me with the correct syntax?

Thanks!
How do I share an account record (and associated contacts), so that it is available to external customer community users? The account record will be owned by an Internal user. 

This is basically for a VF page in my customer community where there is a contact lookup field. The external users have to select contacts accociated with a particular account "ABC" only. I have put in a lookup filter, but it is only working for the internal users. The external users are not able to see anything, most probably because they do not have access to he "ABC" account record. Please help!!!
Hello,
I am trying to write a schedulable apex class where emails are sent to users who have not logged in past 30 days. Here is what I have but I get the following error:
Error: Compile Error: Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setTargetObjectIds(LIST<User>) at line 14 column 17

global class Class implements Schedulable {

global void execute(SchedulableContext ctx){

    dateTime dt = date.today()-30;    
    id sysAdm = [SELECT id from Profile where Name =: 'System Administrator' LIMIT 1].id;
    List <User> userList = [SELECT Name, Email, LastLoginDate, ISActive, Id From User WHERE IsActive = true AND LastLoginDate <: +dt AND ProfileId !=: sysAdm LIMIT 10000];
    
    if(userList.size() > 0)
        {
            for(User usr : userList)
            {
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTargetObjectIds(userList); // List of  ids of the contact, lead, or User
                mail.setTemplateId('00***********XU'); // Id of the email template
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
        }
    update userList;
}
}
Hello! I would like to display my account records on a VF page in the following JSON format. I need help with the class and the VF page. Thanks a bunch!
[
    {
        "AccountId": 1,
        "AccountName": "account1",
        "AddressBook": [
            {
                "Id": 1,
                "Name": "test",
                "Attn": "test",
    "StreetName": "test",
                "CityName": "test",
                "State": "TT",
                "PostCode": 89098,
                "Tel": "(000)- 000-0000",
                "Favorite": true,
                "AccountId": 1
            },
            {
                "Id": 2,
                "Name": "test2",
                "Attn": "test2",
    "StreetName": "test2",
                "CityName": "test2",
                "State": "TU",
                "PostCode": 3000,
                "Tel": "(000)- 000-0000",
                "Favorite": true,
                "AccountId": 1
            },
            
        ]
    },
    {
        "AccountId": 2,
        "AccountName": "Account2",
        "AddressBook": [
            {
                "Id": 1,
                "Name": "Test3",
                "Attn": "Test3",
    "StreetName": "Test3",
                "CityName": "Test3",
                "State": "TI",
                "PostCode": 3000,
                "Tel": "(000)- 000-0000",
                "Favorite": true,
                "AccountId": 1
            },
            {
                "Id": 2,
                "Name": "Test4",
                "Attn": "Test4",
    "StreetName": "Test4",
                "CityName": "Test4",
                "State": "TO",
                "PostCode": 75000,
                "Tel": "(000)- 000-0000",
                "Favorite": false,
                "AccountId": 1
            },
            
        ]
    },
    
]

I am trying to write an apex test class for the following trigger

 

Trigger updateParentAccountName on Contact(before insert, before update){

List<Id> idList = new List<Id>();

for(Contact con : trigger.new ){
    if(con.AccountId != '001Q000000b32BD'){
        idList.add(con.AccountId);
        Map<Id,Account>accMap = new Map<Id,Account>([select ParentId from Account where id in:idList]);
        con.Parent_Account__c = accMap.get(con.AccountId).ParentId;
        }
    }
}

 

this is what i came up with so far:

 

@isTest
private class TestUpdateParentaccountName
{
  static testMethod void mytest()
  {
    //Create the 2 different categories the contact name may fall in

    List<Contact> testContacts = new List<Contact>();
    Contact testCase = new Contact();
    testCase.LastName = 'test1';
    testCase.AccountId = '001Q000000agMR5';
    testCase.RPCD_Functional_Area__c = 'General';
Test.startTest();
 insert testCase;
    testCase.Parent_Account__c = 'Department of Health and Human Services';
    update testCase;
 Test.stopTest();
Contact ct=[select  Parent_Account__c from Contact where id =: testCase.Id];
system.assert(ct.Parent_Account__c =='Department of Health and Human Services', ' Parent not changed');
    }
}

 

I get 100% code coverage but the test method fails. This is the error that i get

 

Time Started2/13/2013 9:45 AM
ClassTestUpdateParentaccountName
Method Namemytest
Pass/FailFail
Error MessageSystem.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateParentAccountName: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.updateParentAccountName: line 9, column 1: []
Stack Trace

Class.TestUpdateParentaccountName.mytest: line 14, column 1

 

Any help would be appreciated! Thanks!!

Hello! This is my trigger. If the Account filed on Contact is not equal to "Not Available" then it populates Parent Account Field on Contacts with the Account.Parent.

 

Trigger updateParentAccountName on Contact(before insert,before update){

List<Contact> conList = new List<Contact>();
List<Contact> accList = new List<Contact>();
List<Id> idList = new List<Id>();

for(Contact con :Trigger.new){
if(con.Account.Name != 'Not Available'){
idList.add(con.AccountId);

}
}

Map<Id,Account>accMap = new Map<Id,Account>([select ParentId from Account where id in:idList]);

for(Contact c : trigger.new){
if(c.Account.Name != 'Not Available'){
c.Parent_Name__c = accMap.get(c.AccountId).ParentId;
}
}
}

Can anyone help me write a test class for this?

 

I have written the following but doesnt seem to work.

 

@isTest
private class TestUpdateParentaccountName
{
  static testMethod void mytest()
  {
    //Create the 2 different categories the contact name may fall in
    List<Contact> testContacts = new List<Contact>();
    Contact testCase = new Contact();
    testCase.LastName = 'test1';
    testCase.Account.Name = 'Food and Drug Administration';
    testContacts.add(testCase);
    
    Contact testCase2 = new Contact();
    testCase2.LastName = 'test2';
    testCase2.Account.Name = 'Not Available';
    testContacts.add(testCase2);
    
    insert testContacts;
    
    }

Can anyone help me with the following trigger?

 

I have "Contacts" object. On the "Contacts" object i have a field called "Parent Account Name" and "Account Name"

On the "Accounts" object i have a field called "Parent Name".

 

If "Account Name" is not equal to "Not Available", then "Parent Account Name" should populate the value from "Parent Name" from the "Accounts" object for that particular account. I hope i am clear!

 

Thanks!!!