• oen
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
I am looking for a way to hide the "View Dashboard" dropdown so a user cannot select a different dashboard. Is there a way to achieve this?

Thanks
  • June 17, 2014
  • Like
  • 0

Hi Everyone,

 

I am trying to Merge contacts in a do while loop base on Contact's FirstName,LastName and AccountID.

 

I got the code to work on Merging Contacts but for some reason the Do While loop is not looping through all the contacts that need to be merge. Below is the Apex code:

 

public class myContactMerger {

public myContactMerger(ApexPages.StandardController controller) {


}

public integer myii;
public integer myi;


public void doAdd() {

List<aggregateResult> results = new List<aggregateResult>();
do {
myii = [Select count() from Contact Where AccountId <>''];
results.clear();
results = [select count(id) mycount,min(id) mymasterid,Max(id) myslaveid,accountid,FirstName,LastName from Contact Where AccountId <> '' group by accountid,FirstName,LastName having count(id)>1 limit 50];
Id mymasterid;
Id myslaveid;
Contact MasterContact;
Contact SlaveContact;
Contact thismastercontact ;
Contact thissalvecontact;

for (AggregateResult ar : results) {

 


mymasterid = (Id)ar.get('mymasterid');
myslaveid = (Id)ar.get('myslaveid');

thismastercontact = new Contact(Id=String.valueOf(ar.get('mymasterid')));
thissalvecontact = new Contact(Id=String.valueOf(ar.get('myslaveid')));

try {
merge thismastercontact thissalvecontact;
} catch (DmlException e) {
// Process exception
System.debug('An unexpected error has occurred: ' + e.getMessage());
}


}
myi = [Select count() from Contact Where AccountId <>''];

} while (myii >myi);

 


}

}

 

Anyone has any suggestion why this is not working? Also appreciates it if someone can tell me if the code i am currently have is most effienct or it can be improve.

 

Thanks

  • July 19, 2013
  • Like
  • 0

Hi everyone,

 

I need help write a testMethod for my trigger, can anyone help please? Below is a trigger that works in the SandBox, but when i deploy it in production i get a '

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required'

 

----Trigger----

trigger EmailonPost on FeedItem (after insert) {

for (FeedItem f: trigger.new) {
        Id myparentId = f.parentId;
Id myCreatedUser = f.createdbyid;
Milestone1_Milestone__c myMile =  [SELECT id,Name FROM Milestone1_Milestone__c WHERE id =:myparentId]; 
String myMileName = myMile.Name;

User myCreateUser =  [SELECT id,Name FROM User WHERE id =:myCreatedUser]; 
String CreatedName = myCreateUser.Name;

String myPostbody = f.body;

  List<EntitySubscription> newEN = [SELECT id,Parentid,subscriberid FROM EntitySubscription WHERE Parentid =:myparentId]; 
         
          for(EntitySubscription a : newEN){
         id Iduser =a.subscriberid;
        try{

List<Messaging.SingleEmailMessage> email = new List<Messaging.SingleEmailMessage>();  
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   //mail.setToAddresses(new String[] {'klin@evolvediscovery.com'});          
       mail.setTargetObjectId(Iduser);
       // mail.setTemplateID(template.ID);
        mail.setSaveAsActivity(false);
   mail.setSubject('New post on Milestone: ' + myMileName);  
    mail.setPlainTextBody(CreatedName + ' wrote: ' + ' \r\n' + ' \r\n' + myPostbody);
        //mail.setWhatId(c.ID);
        
        email.add(mail);
 Messaging.sendEmail(email);

       
        } catch (DmlException e) {}
          }

    }


}

 

 

What this trigger trying to do is send a email to all the follower that are currently following the custom object.

 

Below is my attempt to write a testMethod, i couldn't get it to work because i don't have a clue how the logic behind a test method.

 

---Apex Class---

@isTest
private class EmailonPostTester {

    static testMethod void myEmailonPostTest() {

FeedItem post = new FeedItem();

post.ParentId = '005G0000002hIbJIAU';
post.Body = 'Enter post text here';

test.StartTest();
insert post;
test.StopTest();

    }
}

I get this error when did a run test:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EmailonPost: execution of AfterInsert

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

Trigger.EmailonPost: line 6, column 1: []

  • June 21, 2013
  • Like
  • 0

Hi everyone,

 

I am new to Salesforce. I can't figure out how to capture value from a lookup field in VF and save it into a varaible in Apex, can someone help please? I have an Custom_Test__c is my object and Custom_Name__c is the lookup field, below is the code:

 

---VF---

<apex:page standardController="Custom_Test__c" recordSetVar=""
extensions="myUserListHandler">
<br/>
<apex:form >

<apex:pageBlock title="Select project" id="selectionBlock2">
<apex:inputField value="{!Custom_Test__c.Custom_Name__c}" required="true">
</apex:inputField>
<apex:commandButton value="selected Users(" action="{!dodelete}" onclick="return confirm('Are you sure you?');" />
</apex:pageBlock>


</apex:form>

</apex:page>

 

 

 

 

 

----Apex---

 

public void docreate() {

Id Iduser;

Custom_Test__c myObject = (Custom_Test__c) controller.getRecord();

for (String s: selectedNames) {

if (s <> NULL ){

List<User> accs = [SELECT Id, Name FROM User WHERE Name =:s];

for(User a : accs){
Iduser =a.Id;
EntitySubscription newEN = new EntitySubscription(ParentID =myObject.id,SubscriberId=Iduser);
try{
insert newEN;
} catch (DmlException e) {}
}


}

}

}

 

Thanks,

  • June 18, 2013
  • Like
  • 0

Hi everyone,

 

I need help write a testMethod for my trigger, can anyone help please? Below is a trigger that works in the SandBox, but when i deploy it in production i get a '

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required'

 

----Trigger----

trigger EmailonPost on FeedItem (after insert) {

for (FeedItem f: trigger.new) {
        Id myparentId = f.parentId;
Id myCreatedUser = f.createdbyid;
Milestone1_Milestone__c myMile =  [SELECT id,Name FROM Milestone1_Milestone__c WHERE id =:myparentId]; 
String myMileName = myMile.Name;

User myCreateUser =  [SELECT id,Name FROM User WHERE id =:myCreatedUser]; 
String CreatedName = myCreateUser.Name;

String myPostbody = f.body;

  List<EntitySubscription> newEN = [SELECT id,Parentid,subscriberid FROM EntitySubscription WHERE Parentid =:myparentId]; 
         
          for(EntitySubscription a : newEN){
         id Iduser =a.subscriberid;
        try{

List<Messaging.SingleEmailMessage> email = new List<Messaging.SingleEmailMessage>();  
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   //mail.setToAddresses(new String[] {'klin@evolvediscovery.com'});          
       mail.setTargetObjectId(Iduser);
       // mail.setTemplateID(template.ID);
        mail.setSaveAsActivity(false);
   mail.setSubject('New post on Milestone: ' + myMileName);  
    mail.setPlainTextBody(CreatedName + ' wrote: ' + ' \r\n' + ' \r\n' + myPostbody);
        //mail.setWhatId(c.ID);
        
        email.add(mail);
 Messaging.sendEmail(email);

       
        } catch (DmlException e) {}
          }

    }


}

 

 

What this trigger trying to do is send a email to all the follower that are currently following the custom object.

 

Below is my attempt to write a testMethod, i couldn't get it to work because i don't have a clue how the logic behind a test method.

 

---Apex Class---

@isTest
private class EmailonPostTester {

    static testMethod void myEmailonPostTest() {

FeedItem post = new FeedItem();

post.ParentId = '005G0000002hIbJIAU';
post.Body = 'Enter post text here';

test.StartTest();
insert post;
test.StopTest();

    }
}

I get this error when did a run test:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EmailonPost: execution of AfterInsert

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

Trigger.EmailonPost: line 6, column 1: []

  • June 21, 2013
  • Like
  • 0

Hi everyone,

 

I am new to Salesforce. I can't figure out how to capture value from a lookup field in VF and save it into a varaible in Apex, can someone help please? I have an Custom_Test__c is my object and Custom_Name__c is the lookup field, below is the code:

 

---VF---

<apex:page standardController="Custom_Test__c" recordSetVar=""
extensions="myUserListHandler">
<br/>
<apex:form >

<apex:pageBlock title="Select project" id="selectionBlock2">
<apex:inputField value="{!Custom_Test__c.Custom_Name__c}" required="true">
</apex:inputField>
<apex:commandButton value="selected Users(" action="{!dodelete}" onclick="return confirm('Are you sure you?');" />
</apex:pageBlock>


</apex:form>

</apex:page>

 

 

 

 

 

----Apex---

 

public void docreate() {

Id Iduser;

Custom_Test__c myObject = (Custom_Test__c) controller.getRecord();

for (String s: selectedNames) {

if (s <> NULL ){

List<User> accs = [SELECT Id, Name FROM User WHERE Name =:s];

for(User a : accs){
Iduser =a.Id;
EntitySubscription newEN = new EntitySubscription(ParentID =myObject.id,SubscriberId=Iduser);
try{
insert newEN;
} catch (DmlException e) {}
}


}

}

}

 

Thanks,

  • June 18, 2013
  • Like
  • 0