• Stephanie Akin
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
Hi. I received help with an apex trigger and have tested it out and it is working but I need a test class in order to push it to production. Any help is appreciated.  Trigger is below:

trigger updateContactSageCaller on Scorecard__c (before insert,before update){
Set<Id> conId = new Set<Id>();
Map<Id,Contact> conMap = new Map<Id,Contact>(); 
    // start SFDC code
    List<Contact> l1 = new List<Contact>();
    // end SFDC code
for(Scorecard__c score : trigger.new){
if(score.Primary_Training_Contact__c != null){
    conId.add(score.Primary_Training_Contact__c);
}
}
for(Contact con : [Select Id,Sage_Caller__c from Contact where Id IN: conId]){
conMap.put(con.Id,con);
}

for(Scorecard__c score : trigger.new){
if(conMap.containsKey(score.Primary_Training_Contact__c) && conMap.containsKey(score.Primary_Training_Contact__c) != null){
conMap.get(score.Primary_Training_Contact__c).Sage_Caller__c = score.Sage_Caller__c;
    //start sfdc code
     l1.add(conMap.get(score.Primary_Training_Contact__c));
    //end sfdc code
}
}
// sfdc code
// if(!conMap.isEmpty()){
if(!l1.isEmpty()){
    update l1;
}
//}

    // start SFDC code
    List<Contact> l2 = new List<Contact>();
    // end SFDC code

for(Scorecard__c score : trigger.new){
if(score.Primary_Training_Contact__c != null){
conId.add(score.Primary_Training_Contact__c);
}
}
for(Contact con : [Select Id,Sage_Caller__c from Contact where Id IN: conId]){
conMap.put(con.Id,con);
}

for(Scorecard__c score : trigger.new){
if(conMap.containsKey(score.Primary_Training_Contact__c) && conMap.containsKey(score.Primary_Training_Contact__c) != null){
conMap.get(score.Primary_Training_Contact__c).Sage_Caller__c = score.Sage_Caller__c;
    //start sfdc code
     l2.add(conMap.get(score.Primary_Training_Contact__c));
    //end sfdc code
}
}
// sfdc code
// if(!conMap.isEmpty()){
if(!l2.isEmpty()){
update l2;
}
}

Thanks!
Hi.

I am new to apex and I need some help with a trigger. I've looked around online and can't even piece together some code to test it, so I am asking for your help.

I have a lookup field on the contact object named Sage Caller (which is a user object lookup field), I need this field to be updated when the field from my custom object Scorecard named Caller is filled out. (Caller is a lookup field to the user object).

Basically, when I create a Scorecard record and fill out the Caller field, whomever is in that field I need that same user to be updated into the Sage Caller field on the contact.

I can't use a workflow because it is just a lookup relationship and not master detail. 

Thanks in advance! 


Hi, I have an apex trigger that I pieced together and tested out and it works. But now I need a test class in order to move it to production. Any help is appreciated. 
Here is my trigger:

trigger InsertOppTeam on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS
set<Id> setOpp = new set<Id>();
set<Id> setOTM = new set<Id>();


for (OpportunityTeamMember oppTeam : trigger.new) {
setOpp.add(oppTeam.OpportunityId);
setOTM.add(oppTeam.id);
}
//Loop through opportunity team members and grab Users who have these roles 'OL Assignment' or 'Sage Buddy' or 'Mentor'.

list<OpportunityTeamMember> listOTM = new list<OpportunityTeamMember>
([SELECT Id, UserId, OpportunityId, TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id in :setOTM AND (TeamMemberRole = 'OL Assignment' OR

TeamMemberRole = 'Sage Buddy' OR TeamMemberRole = 'Mentor') ]);


// Create a map that grabs the Opportunity Id being worked with
Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;

Opportunity tempOpp;


//Load the ID's
for(OpportunityTeamMember otm : listOTM ){
tempOpp = mapOpps.get(otm.OpportunityId);

if(otm.TeamMemberRole == 'OL Assignment') {
tempOpp.OL_Assignment1__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Mentor') {
tempOpp.Mentor__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Sage Buddy') {
tempOpp.Sage_Buddy__c = otm.User.Name;
}

}

// Load values

update mapOpps.values();
}

Thank you!
Hi I have an apex class:
public with sharing class ProfileTabUserController {
// Purpose: Custom Chatter profile page
private ApexPages.StandardController c;
// Getter methods you can call from your Visualforce page, e.g. {!viewingMyProfile }
public User subjectUser { get; set; }
public boolean viewingMyProfile { get; set; } // Whether or not I’m viewing my profile
public String viewerID { get; set; } // UID string for the viewing user
public String subjectID { get; set; } // UID string for the subject user (being viewed)
// Constructor method for the controller
public ProfileTabUserController(ApexPages.StandardController stdController) {
c = stdController;
subjectID = getTargetSFDCUID();
// If we're operating inside a tab running inside of a profile...
if (subjectID != null) {
// Inject the sfdc.userId URL parameter value into the id param
// so the std User controller loads the right User record
ApexPages.currentPage().getParameters().put('id', subjectID);
}
// Load the User record for the user whose profile we’re viewing
this.subjectUser = (User)stdController.getRecord();
Id viewer = Id.valueOf(UserInfo.getUserId());
Id subject = Id.valueOf(subjectID);
viewingMyProfile = (viewer == subject);
viewerID = UserInfo.getUserId();
}
// Fetches URL parameter passed into a profile tab indicating which user is being viewed
private String getTargetSFDCUID() {
return
ApexPages.currentPage().getParameters().get('sfdc.userId');
}
// Overrides StandardController save method to force reload of current page afterwards
public PageReference save() {
c.save();
return ApexPages.currentPage();
}
// Overrides StandardController cancel method to force page reload
public PageReference cancel() {
c.cancel();
return ApexPages.currentPage();
}
}



But I need help with a test class. I have this but I keep getting error and it won't let me save. Can anyone help me fix the test class or help me to create a new one? Thanks in advance, here is the test class. 

@isTest
private class ProfileTabControllerTests {

private static testMethod void testProfileTabController() {

User u = [select Id from User where Id = :UserInfo.getUserId() ];

PageReference pageRef = Page.Chatter_Custom;
Test.setCurrentPage(pageRef);
ApexPages.StandardController con = new ApexPages.StandardController(u);
ProfileTabUserController ext = new ProfileTabUserController(con);

System.assertEquals(u.Id, ext.subjectID);
System.assert(viewingMyProfile);

String cancelPage = ext.cancel().getUrl();
String savePage = ext.save().getUrl();

}
}
Hi. A friend helped me develop a trigger for when an activity with the subject File Forms from Recruit in EE Folder is changed to the status of completed it updates the opportunity stage to Day 1 Complete. 

But I am getting an error and I can't figure out why. Error: Compile Error: Variable does not exist: trigger at line 4 column 18

Any help is appreciated. 

Here is the code:

trigger updateStatus on Task (after insert, after update){
    List<Id> oppy_ids = new List<Id>();
    List<Opportunity> update_oppys = new List<Opportunity>();
    for(Task t : trigger.new()){
        //when subject is this, the opp should be start 10 day cycle
        if(t.Subject == 'File Forms from Recruit in EE Folder' && t.Status == 'Completed' && t.WhatId != null && String.valueOf(t.WhatId).startsWith('006')){
            oppy_ids.add(t.WhatId);
        }
    }

    for(Opportunity o : [SELECT StageName FROM Opportunity WHERE ID IN :oppy_ids]){
        // or whatever you need the stage  name to be
        o.StageName = 'Day 1 Complete';
        //add the opportunity to a list for dml
        update_oppys.add(o);
    }

    if(!update_oppys.isEmpty()){
        update update_oppys;
    }
}
Hi. A friend helped me develop a trigger for when an activity with the subject File Forms from Recruit in EE Folder is changed to the status of completed it updates the opportunity stage to Day 1 Complete. 

But I am getting an error and I can't figure out why. Error: Compile Error: Variable does not exist: trigger at line 4 column 18

Any help is appreciated. 

Here is the code:

trigger updateStatus on Task (after insert, after update){
    List<Id> oppy_ids = new List<Id>();
    List<Opportunity> update_oppys = new List<Opportunity>();
    for(Task t : trigger.new()){
        //when subject is this, the opp should be start 10 day cycle
        if(t.Subject == 'File Forms from Recruit in EE Folder' && t.Status == 'Completed' && t.WhatId != null && String.valueOf(t.WhatId).startsWith('006')){
            oppy_ids.add(t.WhatId);
        }
    }

    for(Opportunity o : [SELECT StageName FROM Opportunity WHERE ID IN :oppy_ids]){
        // or whatever you need the stage  name to be
        o.StageName = 'Day 1 Complete';
        //add the opportunity to a list for dml
        update_oppys.add(o);
    }

    if(!update_oppys.isEmpty()){
        update update_oppys;
    }
}
Hi.

I am new to apex and I need some help with a trigger. I've looked around online and can't even piece together some code to test it, so I am asking for your help.

I have a lookup field on the contact object named Sage Caller (which is a user object lookup field), I need this field to be updated when the field from my custom object Scorecard named Caller is filled out. (Caller is a lookup field to the user object).

Basically, when I create a Scorecard record and fill out the Caller field, whomever is in that field I need that same user to be updated into the Sage Caller field on the contact.

I can't use a workflow because it is just a lookup relationship and not master detail. 

Thanks in advance! 


Hi, I have an apex trigger that I pieced together and tested out and it works. But now I need a test class in order to move it to production. Any help is appreciated. 
Here is my trigger:

trigger InsertOppTeam on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS
set<Id> setOpp = new set<Id>();
set<Id> setOTM = new set<Id>();


for (OpportunityTeamMember oppTeam : trigger.new) {
setOpp.add(oppTeam.OpportunityId);
setOTM.add(oppTeam.id);
}
//Loop through opportunity team members and grab Users who have these roles 'OL Assignment' or 'Sage Buddy' or 'Mentor'.

list<OpportunityTeamMember> listOTM = new list<OpportunityTeamMember>
([SELECT Id, UserId, OpportunityId, TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id in :setOTM AND (TeamMemberRole = 'OL Assignment' OR

TeamMemberRole = 'Sage Buddy' OR TeamMemberRole = 'Mentor') ]);


// Create a map that grabs the Opportunity Id being worked with
Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;

Opportunity tempOpp;


//Load the ID's
for(OpportunityTeamMember otm : listOTM ){
tempOpp = mapOpps.get(otm.OpportunityId);

if(otm.TeamMemberRole == 'OL Assignment') {
tempOpp.OL_Assignment1__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Mentor') {
tempOpp.Mentor__c = otm.User.Name;
}
else if(otm.TeamMemberRole == 'Sage Buddy') {
tempOpp.Sage_Buddy__c = otm.User.Name;
}

}

// Load values

update mapOpps.values();
}

Thank you!
Hi I have an apex class:
public with sharing class ProfileTabUserController {
// Purpose: Custom Chatter profile page
private ApexPages.StandardController c;
// Getter methods you can call from your Visualforce page, e.g. {!viewingMyProfile }
public User subjectUser { get; set; }
public boolean viewingMyProfile { get; set; } // Whether or not I’m viewing my profile
public String viewerID { get; set; } // UID string for the viewing user
public String subjectID { get; set; } // UID string for the subject user (being viewed)
// Constructor method for the controller
public ProfileTabUserController(ApexPages.StandardController stdController) {
c = stdController;
subjectID = getTargetSFDCUID();
// If we're operating inside a tab running inside of a profile...
if (subjectID != null) {
// Inject the sfdc.userId URL parameter value into the id param
// so the std User controller loads the right User record
ApexPages.currentPage().getParameters().put('id', subjectID);
}
// Load the User record for the user whose profile we’re viewing
this.subjectUser = (User)stdController.getRecord();
Id viewer = Id.valueOf(UserInfo.getUserId());
Id subject = Id.valueOf(subjectID);
viewingMyProfile = (viewer == subject);
viewerID = UserInfo.getUserId();
}
// Fetches URL parameter passed into a profile tab indicating which user is being viewed
private String getTargetSFDCUID() {
return
ApexPages.currentPage().getParameters().get('sfdc.userId');
}
// Overrides StandardController save method to force reload of current page afterwards
public PageReference save() {
c.save();
return ApexPages.currentPage();
}
// Overrides StandardController cancel method to force page reload
public PageReference cancel() {
c.cancel();
return ApexPages.currentPage();
}
}



But I need help with a test class. I have this but I keep getting error and it won't let me save. Can anyone help me fix the test class or help me to create a new one? Thanks in advance, here is the test class. 

@isTest
private class ProfileTabControllerTests {

private static testMethod void testProfileTabController() {

User u = [select Id from User where Id = :UserInfo.getUserId() ];

PageReference pageRef = Page.Chatter_Custom;
Test.setCurrentPage(pageRef);
ApexPages.StandardController con = new ApexPages.StandardController(u);
ProfileTabUserController ext = new ProfileTabUserController(con);

System.assertEquals(u.Id, ext.subjectID);
System.assert(viewingMyProfile);

String cancelPage = ext.cancel().getUrl();
String savePage = ext.save().getUrl();

}
}