• Wiz76
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hoping for some help here...I have never done VF development before but I wanted to give it a shot in some prototyping I am doing for a project.

I have an Object (Underwriting__c) which I have created to track our underwriting process. I am building a simplified approval process so I have created a child to trakc these (Approval_history__c). I would like to have a button on the detail page of the underwriting layout take me to a custom VF page to select the next approver, but I am having problems being able to populate the Underwriting__c parent field on this new VF page.

I have read many posts and tried a lot of their code to make this work but I just can't get it to populate when clicking the button from the Undewriting page. Hoping for some help in any way. I know it involves a controller extension but all the ones I have tried on this board do not help.

Here is my page so far:
<apex:page standardController="Approval_History__c">
    <apex:form >
        <apex:pageBlock title="Choose Next Approver">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection >
            <apex:inputField required="TRUE" value="{!Approval_History__c.Next_Approver__c}"/>
            <apex:inputField required="TRUE" value="{!Approval_History__c.Underwriting__c}"/>
        </apex:pageBlockSection>      
        </apex:pageBlock>
    </apex:form>
</apex:page>

The goal would be to substitute {!Approval_History__c.Underwriting__c} with the name or Id (not sure which because the name is what needs to populate when using a URL hack). So the only thing they need to choose is the next approver. I am trying to shy away from the URL hack because I only want them to have the ability to save, not save & new or cancel.

Thanks!
  • April 16, 2014
  • Like
  • 0

Hi everyone. So I have a requirement to share a private child object (underwriting) to the original opportunity owner. This child record is being created via a button running some javascript from the opportunity page. I have created a trigger that auto-shares it to the designated Sales Rep on each underwriting record. I am attempting to do this after insert, but it is not working. It is working perfectly if I change it to after update though.

 

Can anybody help me figure out why this is happening this way? Sorry if its a simple thing, I'm still a newbie in the APEX coding world.

 

Thanks!

trigger ShareToOppOwner on Underwriting__c (after insert) {


List<Underwriting__Share> UndShare = new List<Underwriting__Share>();

For(underwriting__c und:Trigger.new){
    if(und.sales_rep__c!=null){
        Underwriting__Share us = new Underwriting__Share();
        us.ParentId = und.Id;
        us.UserOrGroupId = und.Sales_Rep__c;
        us.AccessLevel = 'Read';
        UndShare.add(us);
        insert us;
      }  
}
}

 

  • July 11, 2013
  • Like
  • 0

Hi all..I'm hoping someone can help me here. I have downloaded the 'Unsubscribe Opt Out' package from the AppExchange and it works great except for one part. I require an email notification to be sent to me if the email address the message is from is not found in Salesforce.

 

The clients my reps deal with have a high turnover rate so a mass mailing may be sent to an email of someone who has left that is just being forwarded to someone elses account. When they send the unsubscribe email back, that email address will not be in our system and we need to be notified of that.

 

Is there an easy way to implement this logic into the code pasted below? All I would require in the email message would be a simple message ' env.FromAddress can not be found within Salesforce.com'.

 

Thank you in advance!

Global class unsubscribe implements Messaging.inboundEmailHandler{

Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, 
                            Messaging.InboundEnvelope env ) {

// Create an inboundEmailResult object for returning 
//the result of the Apex Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
 
// Contact and Lead lists to hold all the updated records
List<Contact> lc = new List <contact>();
List<Lead> ll = new List <lead>();
 
// Convert the subject line to lower case, so I can match on lower case
String mySubject = email.subject.toLowerCase();
// String I am searching for in the subject line
String s = 'unsubscribe';
 
// Check variable to see if the word "unsubscribe" was found in the subject line 
Boolean unsubMe;
// Look for the unsubcribe word in the subject line, 
// if it is found return true, otherwise false is returned
unsubMe = mySubject.contains(s);
 
 // If unsubscribe is found in the subject line enter the if statement
 
 if (unsubMe == true) {
    
    try {
        
    // Lookup all contacts with a matching email address
        
     for (Contact c : [Select Id, Name, Email, HasOptedOutOfEmail
                        From Contact
                        Where Email = :env.fromAddress
                        And hasOptedOutOfEmail = false
                        Limit 100]) {
                        
        // Add all the contacts into the List   
                            c.hasOptedOutOfEmail = true;
                            lc.add(c);                                 
    }    
        // update all the Contact records
        
        update lc;
            }
    catch (System.QueryException e) {
        System.debug('Contact Query Issue: ' + e);
        }   

    try {
        // Lookup all leads matching the email address
     for (Lead l : [Select Id, Name, Email, HasOptedOutOfEmail
                        From Lead
                        Where Email = :env.fromAddress
                        And isConverted = false
                        And hasOptedOutOfEmail = false
                        Limit 100]) {
        // Add all the leads to the List        
        l.hasOptedOutOfEmail = true;
        ll.add(l);
                               
           System.debug('Lead Object: ' + l);   
    }    
        // Update all Lead records in the query
        update ll;
            }

    catch (System.QueryException e) {
        System.debug('Lead Query Issue: ' + e);
        }   

    System.debug('Found the unsubscribe word in the subject line.');
 } 
 else {
    System.debug('No Unsuscribe word found in the subject line.' );
 }
// Return true and exit
// True will confirm it is complete and no bounced email 
// should be send the sender of the unsubscribe request. 
result.success = true;
return result;
    }   
    
    // Test method to ensure you have enough code coverage
    // Have created two methods, one that does the testing
    // with a valid "unsubcribe" in the subject line
    // and one the does not contain "unsubscribe" in the
    // subject line
    
static testMethod void testUnsubscribe() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail() ;
   Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();

// Create a new test Lead and insert it in the Test Method        
   Lead l = new lead(firstName='Rasmus', 
            lastName='Mencke',
            Company='Salesforce', 
            Email='rmencke@salesforce.com', 
            HasOptedOutOfEmail=false);
   insert l;

// Create a new test Contact and insert it in the Test Method  
   Contact c = new Contact(firstName='Rasmus', 
                lastName='Mencke', 
                Email='rmencke@salesforce.com', 
                HasOptedOutOfEmail=false);
   insert c;
   
   // test with subject that matches the unsubscribe statement
   email.subject = 'test unsubscribe test';
   env.fromAddress = 'rmencke@salesforce.com';
   
   // call the class and test it with the data in the testMethod
   unsubscribe unsubscribeObj = new unsubscribe();
   unsubscribeObj.handleInboundEmail(email, env );
                        
   }
 
static testMethod void testUnsubscribe2() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Create a new test Lead and insert it in the Test Method        
   Lead l = new lead(firstName='Rasmus', 
            lastName='Mencke',
            Company='Salesforce', 
            Email='rmencke@salesforce.com', 
            HasOptedOutOfEmail=false);
   insert l;

// Create a new test Contact and insert it in the Test Method    
   Contact c = new Contact(firstName='Rasmus', 
                lastName='Mencke', 
                Email='rmencke@salesforce.com', 
                HasOptedOutOfEmail=false);
   insert c;
   
   // Test with a subject that does Not contain unsubscribe
   email.subject = 'test';
   env.fromAddress = 'rmencke@salesforce.com';

   // call the class and test it with the data in the testMethod
   unsubscribe unsubscribeObj = new unsubscribe();
   unsubscribeObj.handleInboundEmail(email, env );                      
   }    
   
}

 

  • April 23, 2013
  • Like
  • 0

Hi everyone. So I have a requirement to share a private child object (underwriting) to the original opportunity owner. This child record is being created via a button running some javascript from the opportunity page. I have created a trigger that auto-shares it to the designated Sales Rep on each underwriting record. I am attempting to do this after insert, but it is not working. It is working perfectly if I change it to after update though.

 

Can anybody help me figure out why this is happening this way? Sorry if its a simple thing, I'm still a newbie in the APEX coding world.

 

Thanks!

trigger ShareToOppOwner on Underwriting__c (after insert) {


List<Underwriting__Share> UndShare = new List<Underwriting__Share>();

For(underwriting__c und:Trigger.new){
    if(und.sales_rep__c!=null){
        Underwriting__Share us = new Underwriting__Share();
        us.ParentId = und.Id;
        us.UserOrGroupId = und.Sales_Rep__c;
        us.AccessLevel = 'Read';
        UndShare.add(us);
        insert us;
      }  
}
}

 

  • July 11, 2013
  • Like
  • 0

Hi all..I'm hoping someone can help me here. I have downloaded the 'Unsubscribe Opt Out' package from the AppExchange and it works great except for one part. I require an email notification to be sent to me if the email address the message is from is not found in Salesforce.

 

The clients my reps deal with have a high turnover rate so a mass mailing may be sent to an email of someone who has left that is just being forwarded to someone elses account. When they send the unsubscribe email back, that email address will not be in our system and we need to be notified of that.

 

Is there an easy way to implement this logic into the code pasted below? All I would require in the email message would be a simple message ' env.FromAddress can not be found within Salesforce.com'.

 

Thank you in advance!

Global class unsubscribe implements Messaging.inboundEmailHandler{

Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, 
                            Messaging.InboundEnvelope env ) {

// Create an inboundEmailResult object for returning 
//the result of the Apex Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
 
// Contact and Lead lists to hold all the updated records
List<Contact> lc = new List <contact>();
List<Lead> ll = new List <lead>();
 
// Convert the subject line to lower case, so I can match on lower case
String mySubject = email.subject.toLowerCase();
// String I am searching for in the subject line
String s = 'unsubscribe';
 
// Check variable to see if the word "unsubscribe" was found in the subject line 
Boolean unsubMe;
// Look for the unsubcribe word in the subject line, 
// if it is found return true, otherwise false is returned
unsubMe = mySubject.contains(s);
 
 // If unsubscribe is found in the subject line enter the if statement
 
 if (unsubMe == true) {
    
    try {
        
    // Lookup all contacts with a matching email address
        
     for (Contact c : [Select Id, Name, Email, HasOptedOutOfEmail
                        From Contact
                        Where Email = :env.fromAddress
                        And hasOptedOutOfEmail = false
                        Limit 100]) {
                        
        // Add all the contacts into the List   
                            c.hasOptedOutOfEmail = true;
                            lc.add(c);                                 
    }    
        // update all the Contact records
        
        update lc;
            }
    catch (System.QueryException e) {
        System.debug('Contact Query Issue: ' + e);
        }   

    try {
        // Lookup all leads matching the email address
     for (Lead l : [Select Id, Name, Email, HasOptedOutOfEmail
                        From Lead
                        Where Email = :env.fromAddress
                        And isConverted = false
                        And hasOptedOutOfEmail = false
                        Limit 100]) {
        // Add all the leads to the List        
        l.hasOptedOutOfEmail = true;
        ll.add(l);
                               
           System.debug('Lead Object: ' + l);   
    }    
        // Update all Lead records in the query
        update ll;
            }

    catch (System.QueryException e) {
        System.debug('Lead Query Issue: ' + e);
        }   

    System.debug('Found the unsubscribe word in the subject line.');
 } 
 else {
    System.debug('No Unsuscribe word found in the subject line.' );
 }
// Return true and exit
// True will confirm it is complete and no bounced email 
// should be send the sender of the unsubscribe request. 
result.success = true;
return result;
    }   
    
    // Test method to ensure you have enough code coverage
    // Have created two methods, one that does the testing
    // with a valid "unsubcribe" in the subject line
    // and one the does not contain "unsubscribe" in the
    // subject line
    
static testMethod void testUnsubscribe() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail() ;
   Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();

// Create a new test Lead and insert it in the Test Method        
   Lead l = new lead(firstName='Rasmus', 
            lastName='Mencke',
            Company='Salesforce', 
            Email='rmencke@salesforce.com', 
            HasOptedOutOfEmail=false);
   insert l;

// Create a new test Contact and insert it in the Test Method  
   Contact c = new Contact(firstName='Rasmus', 
                lastName='Mencke', 
                Email='rmencke@salesforce.com', 
                HasOptedOutOfEmail=false);
   insert c;
   
   // test with subject that matches the unsubscribe statement
   email.subject = 'test unsubscribe test';
   env.fromAddress = 'rmencke@salesforce.com';
   
   // call the class and test it with the data in the testMethod
   unsubscribe unsubscribeObj = new unsubscribe();
   unsubscribeObj.handleInboundEmail(email, env );
                        
   }
 
static testMethod void testUnsubscribe2() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Create a new test Lead and insert it in the Test Method        
   Lead l = new lead(firstName='Rasmus', 
            lastName='Mencke',
            Company='Salesforce', 
            Email='rmencke@salesforce.com', 
            HasOptedOutOfEmail=false);
   insert l;

// Create a new test Contact and insert it in the Test Method    
   Contact c = new Contact(firstName='Rasmus', 
                lastName='Mencke', 
                Email='rmencke@salesforce.com', 
                HasOptedOutOfEmail=false);
   insert c;
   
   // Test with a subject that does Not contain unsubscribe
   email.subject = 'test';
   env.fromAddress = 'rmencke@salesforce.com';

   // call the class and test it with the data in the testMethod
   unsubscribe unsubscribeObj = new unsubscribe();
   unsubscribeObj.handleInboundEmail(email, env );                      
   }    
   
}

 

  • April 23, 2013
  • Like
  • 0

Unable to get hyperlink in add.error code, In trigger.

 

I have seen codes in forum, but wrkg out, as its giving like output text, i need in clickable format.

 

i tried this:

o.addError('ERROR TRM100: There is already an identical record: <a href=\'https://cs2.salesforce.com/' + Acctid.id + '\'>Record Number ' + Acctid.id + '</a>');

 

  • March 14, 2013
  • Like
  • 0

So, here's a newbie question (this is my very FIRST development project). I have a custom object called Account Corrections (Account_Correction__c), that we're using to document Account Owner change requests. On the form, there is a lookup field where the user looks up the Proposed Account Owner (Proposed_Account_Owner__c). Consequently, I want another lookup field to self-populate with the Proposed Account Owner's Manager (Proposed_Account_Owner_s_Manager__c). The reason I'm doing this is to facilitate an Approval Process on the backend that works best with lookup fields to dynamically specify approvers.

Anyway, I'm trying to use an "after insert" trigger to do the job , but I'm not clear on the approach to take. If someone could just put me on the right track, I would be VERY appreciative. If it helps, here are the fields from the Account Corrections object:
Status__c, Request_Details__c, Related_Account__c, Proposed_Account_Owner_s_Manager__c, Proposed_Account_Owner__c, OwnerId, Name, Id, Current_Acct_Owner_s_Manager__c, Current_Account_Owner__c, Assigned_To__c

 

The code below is as far as I've gotten:

trigger TRG_AccountCorrectionRequest_ChangeOwner on Account_Correction__c (after insert, after update) {

	for (Account_Correction__c ac: Trigger.new){
		if (ac.Status__c == 'Submitted' && ac.Request_Details__c == 'Assign Different Account Owner'){
			ac.Current_Acct_Owner_s_Manager__c = ac.Current_Account_Owner__r.ManagerId;
			ac.Proposed_Account_Owner_s_Manager__c = ac.Proposed_Account_Owner__r.ManagerId;
		}
	}
}

 Any assistance is very much appreciated.  Thanks in advance!