• Karthik@TMC
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 24
    Replies

Hi,

 

Please look at the below 2 code snippets:

 1)  

public class selectedRecords {
public List<clsWrapper> accls=new List<clsWrapper>();

 

2)

public class selectedRecords {
public List<clsWrapper> accls{get;set;}
public List<clsWrapper> getAccounts(){
accls=new List<clsWrapper>();
if(accls==null && accls.size()==0){
for(Account a: [select id, Name from Account limit 10]){
accls.add(new clsWrapper(a));
}
}
return accls;
}


}

 mY question is: what is the differnence between allocating memory to the list in starting of class and inside getter ?

 

 

I am trying to compare the account recordtype name to the zone record type name from an Account sObject.  If it matches than further processing should be done.  I tried it this way but realzied the hard way that each object have their own record type id. What is the best way to match the record type name?

 

 

List<Zone__c> zList = [select recordtypeid from Zone_c];
List<RecordType> rtList = [select id, name from RecordType ];

 

for(Account a: aList)
{

if( a.recordtypeid ==zList.get(i).recordtypeid )
{

 

// some processing

 

}

  • October 04, 2012
  • Like
  • 0
I've got a word document as an attachment of a custom object, i can get it as blob by selecting the body of the attachment with a SOQL query : Attachment att = [ SELECT Body FROM Attachment WHERE PARENTID = '**' and ContentType='application/msword'] ; Blob b = att.body ; I tried to use the b.toString() function to have the content, but it didn't work.So is there any other way to convert the blob into a string that represent the text written in my word document. Even tried using EncodingUtil.base64Encode(att.body), but it didn't work. Thanks

Hi,

 

My Controller code is

 

@RemoteAction
    global static void getAttachment(List<String> IdList1){
        
         system.debug('IdList--'+IdList1);
         //IdList.addAll(IdList1);        
        
        List<Attachment> atList = [Select Id,Name,ParentId from Attachment where Id IN: IDList1];
        //attList.addAll(atList);
        
    }

 

how do i invoke this method from js.

 

Thanks in advance

Hi folks,
          Can anyone tell me how to catch the trigger and validation error in visualforce page using javascript remoting?
I wanna sample code to catch the trigger or validation error in visualforce using java script remoting.



Thanks in advance
Karthick
I am currently consulting for small to mid-size businesses and need occassional assistance building triggers as Apex is not something I am familiar with.  I am looking to form a partnership of sorts - when I need this type of help I come to you directly rather than trying to figure it out myself as learning code is not something I am particularly interested in.

If you are willing to be an jj"on-call" developer for me and my clients please message me back with your rates and keep in mind that I work for very small clients, sometimes only one user.  Thank you!

Dea Simon

Hi All,

 

            I hava a written testclass  . i am getting   61% , any one can help me to increase  test coverage  

 

Apex class;

-------------------------

public class IdeaForgotPasswordController extends IdeaController {
public String email {get; set;}

public IdeaForgotPasswordController() {
}

public PageReference forgotPassword() {
if (!isValid()) {
return null;
}

String username = null;
if (email != null && email != '') {
List<User> users = [select username from user where username = :email];
if (users.size() == 1) {
// exact match on username
username = users.get(0).username;
}
else {
users = [select username from user where email = :email];
if (users.size() == 1) {
// exact match on email address
username = users.get(0).username;
}
}
}

if (username == null) {
addErrorMessage('User not found');
return null;
}

boolean success = Site.forgotPassword(username);
if (success) {
PageReference pr = new PageReference(URL_FORGOT_PASSWORD_CONFIRM);
pr.setRedirect(true);
return pr;
}
return null;
}

public boolean isValid() {
boolean valid = true;

if (email == '') {
addErrorMessage('Email address is required.');
valid = false;
}

return valid;
}

private void addErrorMessage(String message) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, message);
ApexPages.addMessage(msg);
}

}

 

 

 

public class IdeaForgotPasswordController extends IdeaController {
public String email {get; set;}

public IdeaForgotPasswordController() {
}

public PageReference forgotPassword() {
if (!isValid()) {
return null;
}

String username = null;
if (email != null && email != '') {
List<User> users = [select username from user where username = :email];
if (users.size() == 1) {
// exact match on username
username = users.get(0).username;
}
else {
users = [select username from user where email = :email];
if (users.size() == 1) {
// exact match on email address
username = users.get(0).username;
}
}
}

if (username == null) {
addErrorMessage('User not found');
return null;
}

boolean success = Site.forgotPassword(username);
if (success) {
PageReference pr = new PageReference(URL_FORGOT_PASSWORD_CONFIRM);
pr.setRedirect(true);
return pr;
}
return null;
}

public boolean isValid() {
boolean valid = true;

if (email == '') {
addErrorMessage('Email address is required.');
valid = false;
}

return valid;
}

private void addErrorMessage(String message) {
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, message);
ApexPages.addMessage(msg);
}

}

 

 

Test Class

---------------------------

Try the below code, you haven't given any email and so it won't go any futher in the code.

@isTest
private clAss IdeaForgotPasswordControllerTest
{
static TestMethod Void TestIdeaForgetpassword()
{

Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
User u = new User(Alias = 'eerer',
EmailEncodingKey='UTF-8', LastName='bbbbb', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id, Email='adityavyas.sf@gmail.com',
TimeZoneSidKey='America/Los_Angeles', UserName='adityavyas.sf@gmail.com');
List<User> users = [select username from user where username = :U.email];
System.runAs(u) {
// The following code runs as user 'u'

System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId()); }

IdeaForgotPasswordController ideaforget= New IdeaForgotPasswordController();
ideaforget.email = 'test@test.com';
Pagereference page=ideaforget.forgotPassword();

}
}

 

  The red lines are not covering plz help me  to cover that code

 

Hi,

 

Can you please give me the code to show video files on my menu page.

 

Thanks in advance,

Sricloud

  • October 09, 2012
  • Like
  • 0

Hi,

 

My Controller code is

 

@RemoteAction
    global static void getAttachment(List<String> IdList1){
        
         system.debug('IdList--'+IdList1);
         //IdList.addAll(IdList1);        
        
        List<Attachment> atList = [Select Id,Name,ParentId from Attachment where Id IN: IDList1];
        //attList.addAll(atList);
        
    }

 

how do i invoke this method from js.

 

Thanks in advance

if i check one list of checkboxes  how to diable another list of check boxes in pageblock table

Hi.

 

I read the documentation for the ''runes'' method, and found that the method 'runes' can only be used in a test method.

 

I wanted to implement the same 'runes' functionality in the normal APEX class. That is , I wanted to execute certain block of code according to the user context specifid by me in the code.

 

So is this possible in normal APEX class? if yes then how can this be implemented.

 

Any pointers regarding this issue would be of great help.

 

 

  • October 04, 2012
  • Like
  • 0

Hi all,

 

I'm getting below Error while installing Force.com IDE

 

 "A Java Runtime Environment (JRE) or Java Development Kit (JDK)

must be available in order to run Force.com-ide-installer. No Java virtual machine
was found after searching the following locations:
/home/salesforce4/Downloads/force.com-ide-installer-linux-gtk-x86/jre/bin/java
java in your current PATH"

 

Please let me know what to do now?

  • October 04, 2012
  • Like
  • 0

There is a statement called

 

so.Last_Stage_Change__c = system.now();

system.debug('Current time:'so.Last_Stage_Change__c);

 

 

and the value of so.Last_Stage_Change__c should be today's date and time which is 10/4/2012 hh:mm:ss

 

but am getting yesterday's date and time. I mean the value which is being assigned to so.Last_Stage_Change__c is 10/3/2012 hh:mm:ss

 

Can anyone tell me what is the problem here and how does this system.now() work?

 

 

 

 

How can i fetch record id of object in visualforcepage controller?

  • October 04, 2012
  • Like
  • 0

Hi,

 

Please look at the below 2 code snippets:

 1)  

public class selectedRecords {
public List<clsWrapper> accls=new List<clsWrapper>();

 

2)

public class selectedRecords {
public List<clsWrapper> accls{get;set;}
public List<clsWrapper> getAccounts(){
accls=new List<clsWrapper>();
if(accls==null && accls.size()==0){
for(Account a: [select id, Name from Account limit 10]){
accls.add(new clsWrapper(a));
}
}
return accls;
}


}

 mY question is: what is the differnence between allocating memory to the list in starting of class and inside getter ?

 

 

I got an object with name Question where i post a question, and i got another object called Responses which is an child object of Question, Each question may contain multiple Responses.my query is how to achieve multiple questions and its respective multiple responses in a visualforce page. 

I am trying to compare the account recordtype name to the zone record type name from an Account sObject.  If it matches than further processing should be done.  I tried it this way but realzied the hard way that each object have their own record type id. What is the best way to match the record type name?

 

 

List<Zone__c> zList = [select recordtypeid from Zone_c];
List<RecordType> rtList = [select id, name from RecordType ];

 

for(Account a: aList)
{

if( a.recordtypeid ==zList.get(i).recordtypeid )
{

 

// some processing

 

}

  • October 04, 2012
  • Like
  • 0

Posting this in order to help others who, months from now, might Google "OP_WITH_INVALID_USER_TYPE_EXCEPTION" and find this explanation.

 

We wrote an Apex trigger on the User object, to insert a custom object record anytime a user updates their Chatter status.  This was done to fulfill a client's requirement to audit all Chatter activity.

 

The trigger worked fine, until one day the client signed up some Chatter Free users.  When such a user tried to update their status, they got a pop-up with an OP_WITH_INVALID_USER_TYPE_EXCEPTION error.

 

We scratched our collective heads for awhile.  After all, Apex triggers run in "system mode," right?  That is supposed to mean that "object and field-level permissions of the current user are ignored."  And yet this trigger seemed like it was running in "user mode," enforcing restrictions based on who the current user was.

 

The root cause turned out to be that a Chatter Free user cannot be the owner of a custom object record, and SFDC by default sets the current user as a new record's first owner.  We discovered this when we realized, via experiment, that Apex triggers fired as the result of actions by Chatter Free users could definitely update an existing record, but were having problems creating records.

 

So the simple solution was to explicitly set the owner of the new record to some fully-licensed user prior to inserting it.