• Urvik
  • NEWBIE
  • 40 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 38
    Questions
  • 39
    Replies
Hello everyone,

I am tryign to use this validation rule and getting some errors.  Can someone please help me.

ISPICKVAL(Specific_Product_Type__c, "Trust Services")&& RecordType.Name="Investments/Insurance - BCIS"  OR(
ISPICKVAL(Probability__c,"50%",ISPICKVAL(Probability__c,"75%"),ISPICKVAL(Probability__c,"100%")) 
&& ISBLANK(Specialty_Partner__c)
I would like to override New button with visualforce pages on opportunity and drive visualforce display based on the record type selected. I have three record types A,B,C. I have two visualforce pages pertaining to record type A and B. So if A is selected I want to take user to visuaforce page pertaining to that record type and vice versa. If a user selects C record type the I want to take them to standard record creation page. How do I do that?
  • October 11, 2016
  • Like
  • 0
I have 3 record types and 2 visualforce pages. I want to override "New" button and display visualforce pages based on the record type selected. But there is a record type for which I want to display standard record creation page and not a visualforce page. How do I do that?
  • October 11, 2016
  • Like
  • 0
Hi All,
How do I display opportunity product related list on a visualforce page? I am trying to use <apex:relatedlist> markup but its not working. I guess its because both are standard objects. What is the best way to display opportunity product related list on visualforce page? How about using <apex:facet> markup. But Opportunity.Product2 gives me an error (invalid field).

Thanks,
Rick
  • May 05, 2016
  • Like
  • 0
I'm trying to display opportunity product names to opportunity custom field. The trigger is working fine but it displays only last record name. eg. If I have 4 products related to opportunity, it display 4th product name and not display the first three. I would like to display each product name with ',' in between. here is my code. Any idea what need to ​be added in order to display all related products name.
Trigger OppProdLine on Opportunity (before update) {

list<opportunity> sl = trigger.new;

list<opportunityLineItem> slnu = new list<opportunityLineItem>([select id ,product2.name, opportunityId from opportunitylineitem where opportunityId =: trigger.new[0].id]);

string productName='';

for(opportunityLineItem opp : slnu){

 productName = opp.product2.name;

}

for(Opportunity opp : trigger.new){

 opp.Opportunity_Prod__c = productName;


}


}
  • May 03, 2016
  • Like
  • 0
I have a field with data type long text area. I am displaying it on visualforce page. But I want to allow that field to display only first 200 characters and end it with ellipses (.....). Someone please help.
  • June 04, 2015
  • Like
  • 0
Hi,
How do I fire trigger only when a record is created by Connection User in salesforce to salesforce integration. i.e. We have SF2SF integration and a trigger updates certain lookup fields but I want to fire that trigger only when a record is created by connection user. I tried CreatedById = '[Id of the connection user] ' but that did not work. Please assist.

Thanks
UT
  • April 02, 2015
  • Like
  • 0
I have a following trigger to update the record type lookup. I'm taking value from the text field and trying to update lookup but its not working. can someone please help?
 
trigger UpdateLookup on Manager__c (after insert, after update) {
try {
set<string> rtset = new set<string>();
for (Manager__c inq : trigger.new) {
   rtset.add(inq.Record_Type__c);
}

Map<String, RecordType> rtmap = new Map<String, RecordType>([Select id from RecordType Where Name in :rtset]); 



for (Manager__c inq : trigger.new) {
     inq.RecordTypeId = rtmap.get(inq.Record_Type__c).id;
   
     
  
}
} catch(Exception e) {  
}
}

 
  • March 31, 2015
  • Like
  • 0
Hi,
I have the following jscript button. It checks the users permission set and work accordingly but it requies user to have "View Setup and Configuration" permission at the user level. We have users without that permission and not able to submit the records. Can someone please assist how to make this button work without assigning "View Setup and Configuration" permission to users? I am getting the following error.
User-added image
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
try {
    var result = 
        sforce.connection.query(
            "SELECT Id " +
            "FROM PermissionSetAssignment " +
            "WHERE PermissionSetId = '0PSK00000004T11' " +
            "AND AssigneeId = '{!$User.Id}'"
        );

    var psAssignment = result.getArray("records");
    if (
        "{!Pims__c.Status__c}" !== "Under Review" &&
        psAssignment.length === 1
    ) {
        var isContinue = confirm("Are you sure you want to submit ? Click OK to continue or Cancel to remain on the screen.");

        if (isContinue) {
            var PimstoUpdate = new sforce.SObject("Pims__c");

            PimstoUpdate.Id = "{!Pims__c.Id}";
            PimstoUpdate.Status__c = "Under Review";

            var result = sforce.connection.update([PimstoUpdate]);

            if (result[0].success === "true") {
                location.reload();
            } else {
                alert(
                    "An Error has Occurred. Error: \r\n" +
                    result[0].errors.message
                );
            }
        }
    } else {
        alert(
            "Nopes"
        );
    }
} catch (e) {
    alert(
        "An unexpected Error has Occurred. Error: \r\n" +
        e
    );
}

 
  • March 03, 2015
  • Like
  • 0
Hi - I have the the following visualforce page. I have been trying to display fields based on the record type selected. I'm using fieldsets. This is based on one fieldset. I have 10 record types and each has separate page layout. How do I make it dynamic so that based on the record type, it display fields?
 
<apex:page standardController="Auto__c" renderAs="pdf">

 <apex:form >
  <apex:pageBlock title="Details">
      <apex:pageblockSection columns="1">
          
          <apex:repeat value="{!$ObjectType.Auto__c.FieldSets.Cars}" var="f">
                <apex:outputfield value="{!Auto__c[f]}">
                </apex:outputfield>
          </apex:repeat>
  
      </apex:pageblockSection>
  </apex:pageBlock>

 </apex:form>
</apex:page>

 
  • December 30, 2015
  • Like
  • 0
Hi, I have a few record types in our system and each record type has different page layout. Each page has almost sames fields with small variations. I have created a visualforce page pdf for the detail page and a button on detail page, which by clicking generates pdf of the detail page. But since there is a small variation in each page layout, I don't want to create many visualforce pages. Is there a way to display fields dynamically on visualforce pdf based on the record type/page layout?
  • December 29, 2015
  • Like
  • 0
I am trying to create a contact record upon user record creation. It should only create a contact record if certain user role are selected. I have the following trigger which works fine if I remove IF statement for ROLE...could someone please help? Again, I have been trying to create a contact record upon creating user record only when certain ROLE are set for the user...Thanks..
trigger CreateContact on User (after insert) {    
    List<Contact> ur = new List<Contact>();
    for (User usr: Trigger.New){
	     if(usr.UserRole.Name=='role name'|| usr.UserRole.Name=='role name')      
              ur.add (new Contact(
                         FirstName = usr.FirstName,
                         LastName = usr.LastName));
                         
    }
	if(!ur.isEmpty())
        insert ur; 
}

 
  • November 25, 2014
  • Like
  • 0
I have been trying to create a contact record once a user record of a specific profile has been created. I am able to save the trigger but cannot create a user record. I have posted a code below. 
trigger createContact on User (before insert) {     
List<Contact> ur = new List<Contact>();
    for (User usr: Trigger.New)
    //IF(Usr.UserRoleId == '00EK0000000KRUR'){
          ur.add (new Contact(
                     FirstName = Usr.FirstName,
                     LastName = Usr.LastName));
                  //  }   
         
   
   insert ur;
 }
  • November 19, 2014
  • Like
  • 1
Hi,

I have custom approval process which uses visualforce email template. In which when an approver respond to email, I would like to display approver's name or email address in subject line or the body of the response. How do I that? Anyone please assist.

Thanks,

Urvik
  • July 25, 2014
  • Like
  • 0
Hi
I have created a simple visualforce page using salesforce account tabbed view logic in order to accomodate background color/watermark requirement . It's nothing fancy - very simple. I also have inline editing enabled but when a user edits a field using inline editing, I want to change the color of the edited field - just like Salesforce standard page. My code is below. Could someone please help how to change color of the font when a field is edited using inline editing...

<apex:page standardController="Project_Governance_Form__c" showHeader="true">


<style type="text/css">
        [id*=myId2] { font-size:small; weight: bold; color: Black; background-image:url('{!$Resource.GovForm_BG_6}'); 
        background-attachment:fixed;
        background-position:center; }    
</style>


 <apex:tabPanel switchType="client"  >          
      <apex:tab label="Details" name="GovFrmDetails">
         <apex:detail relatedList="true" inlineEdit="true" id="myId2" /> 
      </apex:tab>
 </apex:tabPanel>
 
</apex:page>


  • July 19, 2014
  • Like
  • 0
I am getting the following error.
Id value is not valid for the Project_Governance_Form__c standard controller

Here is my code..Could someone please help why I am getting this error?

<apex:page standardController="Project_Governance_Form__c" action="{!URLFOR(CASE(Project_Governance_Form__c.RecordType.Name, 'AIP Form', '/apex/GovForm_Edit_Override_AiP?id={!Project_Governance_Form__c.id}' ,'Commitment', '/apex/GovForm_Edit_Override_Commitment?id={!Project_Governance_Form__c.Id}', 'Commitment / FMA', '/apex/GovForm_Edit_Override_FMA_Commit', '/apex/GovForm_Edit_Override_FMA'))}" >
    
<apex:variable value="{!Project_Governance_Form__c.RecordType.Name}" var="recTypeName"/>
</apex:page>


  • July 16, 2014
  • Like
  • 0
Hi,
I have been trying to pass a record ID to the URL. I have four record types and based on the record type, the edit button is overridden but not able to pass the record id. it gives me error.. see my vfp below.. So if the Record Type if TER Form then if the user clicks EDIT, it should pick up TER Visualforce page and populate fields from the record..Please help..

<apex:page standardController="Project_Governance_Form__c" action="{!URLFOR(CASE(Project__c.RecordType.Name, 'TER Form', '/apex/Form_Edit_Override_TER?id={!Project__c.Id}'))}" >
    <apex:variable value="{!Project__c.RecordType.Name}" var="recTypeName"/>
</apex:page>


  • July 16, 2014
  • Like
  • 0
Is there an easy wasy to override edit button using visualforce page? Currently I have mentioned all the fields I want to display on my visualforce page. I am looking for an easy way so that it can be maintained using the standard page layouts. e.g. override tab view - https://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_tabs.htm
  • July 12, 2014
  • Like
  • 0
Hi,
I have two custom objects with Master-Detail relationship. I would like to send email to the records displayed in the child object using the visualforce email template. Could someone please assist? I came across to the following link but seems like its not helping me.

https://www.salesforce.com/us/developer/docs/pages/Content/pages_email_custom_controller.htm

Thanks,

Urvik
  • July 10, 2014
  • Like
  • 0
I have created an email service to capture response from contacts/approvers for our custom approval process. When an approver responses to email, it is coming from my email address (Context User). I want the response to come from Approver's email address. Below is my code..Could someone please help?
----------------------------------------------------------------------------------------------------------------------------------------------
global class Capture_Approval_From_Email implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        Set<String> bccEmails = new Set<String>();
        String roleName = '';
      
       
        Approval_Process_Setting__c appSetting = Approval_Process_Setting__c.getInstance();
        if(appSetting != null)
            roleName = appSetting.Leadership_Role_Name__c;
           
        String recID = '';
       
        for(User usr : [SELECT Email FROM User WHERE UserRole.DeveloperName = :roleName and Get_Approval_Mail_To_Leadership__c= true ])
        {
            bccEmails.add(usr.Email);
        }       

        try
        {
            recID = email.subject.substring(email.subject.indexOf('<') + 1, email.subject.indexOf('>'));
           
        }
        catch (System.StringException e)
        {
             System.debug('No <> found in email: ' + e);
        }
       
        if(recID != null && recID != '')
        {
            try
            {
                Project_Governance_Form_Approval_Request__c govFormReq = [SELECT id,Project_Governance_Form__r.Project__r.ERDI_S_E_Lead__r.Email,Project_Governance_Form__r.Project__r.Transaction_Lead__r.Email FROM Project_Governance_Form_Approval_Request__c WHERE id = :recID LIMIT 1];
               
                if(govFormReq.Project_Governance_Form__r.Project__r.ERDI_S_E_Lead__r.Email != null)
                    bccEmails.add(govFormReq.Project_Governance_Form__r.Project__r.ERDI_S_E_Lead__r.Email);
               
                if(govFormReq.Project_Governance_Form__r.Project__r.Transaction_Lead__r.Email != null)
                    bccEmails.add(govFormReq.Project_Governance_Form__r.Project__r.Transaction_Lead__r.Email);               
               
                String emailText = '';
                String reply = '';
               
                Project_Governance_Form_Approval_Request__c req = new Project_Governance_Form_Approval_Request__c(id = recID);
                if(email.plainTextBody.length() >=32768)
                    emailText = email.plainTextBody.subString(0,32766);
                else emailText = email.plainTextBody;
               
                try
                {
                    reply = emailText.split('\n')[0].toLowerCase();
                }
                catch(Exception e)
                {
                   system.debug('***********Exception encountered***********'+e.getMessage());
                }
               
                if(reply.contains('approve') || reply.contains('approved') || reply.contains('yes')||
                reply.contains('Approve') || reply.contains('Approved') || reply.contains('Yes'))
                    req.Status__c = 'Approved';
               
                if(reply.contains('reject') || reply.contains('rejected') || reply.contains('no')||
                reply.contains('Reject') || reply.contains('Rejected') || reply.contains('No'))
                    req.Status__c = 'Rejected';
                    req.email__c = env.fromAddress;
                   
                req.Approver_Email_Text__c = emailText;
               
                update req;
            }
            catch(Exception e)
            {
                system.debug('***********Exception encountered***********'+e.getMessage());
            }
            if(!bccEmails.isEmpty())
            {   
                mail.setSaveAsActivity(false);
                mail.setHTMLBody(email.htmlBody); 
                mail.setToAddresses(new List<String>(bccEmails));
                mail.setSubject(email.subject);
               
                try
                {
                    Messaging.sendEmail(new Messaging.Email[] { mail });
                }
                catch(Exception e)
                {
                    system.debug('***********Exception encountered***********'+e.getMessage());
                }               
            }
        }
        return result;
    }
}

  • June 22, 2014
  • Like
  • 0
Hi everyone,
I have the following controller for sending emails for our custom approval process. There are two emails going out - for Approver and Reviewer. The first issue is, Approvers are getting Approver email and Reviewer email too. The second issue is, Reviewers are getting emails based on number of Approvers. e.g. If there are three approvers then reviewer gets three emails, which is incorrect. Each reviewer should get only one email. Could someone please tell me what is incorrect in my controller?

---------

global class Submit_Form_For_Approval
{
    webService static String submitForApproval(String govID, String attIDs)
    {
        Messaging.SingleEmailMessage attMail = new Messaging.SingleEmailMessage();
        List<Messaging.SingleEmailMessage> allMails = new List<Messaging.SingleEmailMessage>();
        List<Messaging.SingleEmailMessage> bccMails = new List<Messaging.SingleEmailMessage>();
        List<Messaging.EmailFileAttachment> attList = new
        List<Messaging.EmailFileAttachment>();
        List<Project_Governance_Form_Approval_Request__c> requestsToAdd = new List<Project_Governance_Form_Approval_Request__c>();
        List<Project_Governance_Form_Approval_Request__c> formReq = new List<Project_Governance_Form_Approval_Request__c>();
        Set<String> bccEmails = new Set<String>();
        Boolean sendFailMail = false;
        Decimal attSize = 0.0;
        String emailToApexEmailAddress = '';
        String templateID = '';
        String BcctemplateID = '';
        String roleName = '';
        String msg = System.Label.Approval_Process_Request_Submitted_Success_Msg;
        Approval_Process_Setting__c appSetting = Approval_Process_Setting__c.getInstance();


      
        if(appSetting != null)
            roleName = appSetting.Leadership_Role_Name__c;
        
        Project_Governance_Form__c govForm = [SELECT id,Name, Date_of__c,Date_of_Commitment_Request__c,
        Date_of__c,Project__c,isLocked__c,Project__r.Name,Project__r.Owner.Email,
        Project__r.Lead__r.Email,Project__r.Transaction_Lead__r.Email, Override_Lock_Toggle__c,
        Project__r.External_Company_Contact__r.Email, Project__r.Addiitonal__r.Email,
        Project__r.Additional__r.Email, Project__r.Additional__r.Email,
        Recordtype.DeveloperName FROM Project_Governance_Form__c WHERE id = :govID LIMIT 1];

        try
        {
            UserRecordAccess usr = [SELECT HasEditAccess,RecordId FROM UserRecordAccess WHERE UserId = :UserInfo.getUserID() AND RecordId =:govForm.Project__c LIMIT 1];
          
            if(!usr.HasEditAccess)
            {
                return 'NOACCESS';
            }
        }
        catch(Exception e)
        {
            system.debug('**************Exception encountered**************'+e.getMessage());
        }

        if(govForm.Project__r.ERDI_S_E_Lead__r.Email != null)
            bccEmails.add(govForm.Project__r.ERDI_S_E_Lead__r.Email);

        if(govForm.Project__r.Transaction_Lead__r.Email != null)
            bccEmails.add(govForm.Project__r.Transaction_Lead__r.Email);
      
        if(govForm.Project__r.Addiitonal_ERDI_member_1__r.Email != null)
            bccEmails.add(govForm.Project__r.Addiitonal_ERDI_member_1__r.Email);
          
        if(govForm.Project__r.Additional_ERDI_Member_2__r.Email != null)
            bccEmails.add(govForm.Project__r.Additional_ERDI_Member_2__r.Email);
        
        if(govForm.Project__r.Additional_ERDI_Member_3__r.Email != null)
            bccEmails.add(govForm.Project__r.Additional_ERDI_Member_3__r.Email);
      
                     
        if(appSetting != null)
        {
            emailToApexEmailAddress = appSetting.Email_to_Apex_Email_Address__c;
           
            try
            {
                templateID = [SELECT id FROM EmailTemplate WHERE DeveloperName = :appSetting.Email_Template_Developer_Name__c].id;
                BcctemplateID = [SELECT id FROM EmailTemplate WHERE DeveloperName = :appSetting.Bcc_Email_Template_Developer_Name__c].id;
            }
            catch(Exception e)
            {
                msg =System.Label.Approval_Process_Email_Template_Not_Found_Msg;
                return msg;
            }
        }
        else
        {
            msg = System.Label.Approval_Process_Custom_Setting_Not_Defined_Msg;
            return msg;
        }

        formReq = [SELECT id,Approver__c, Reviewer__c, Status__c FROM Project_Governance_Form_Approval_Request__c WHERE Project_Governance_Form__c = :govID AND Status__c = 'Pending for Submission'];

        if(!formReq.isEmpty() && attIDs != '' && attIDs != null)
        {
            List<String> attIDList = attIDs.split(';');
            for(Attachment att : [SELECT Id,Body,Name,BodyLength FROM Attachment WHERE ID IN :attIDList])
            {
                Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
                attSize = attSize + Double.ValueOF(att.BodyLength/1024);
                efa.setFileName(att.Name);
                efa.setBody(att.Body);
                attList.add(efa);
            }
        }
      
        system.debug('***********form data************'+formReq);
        for(Project_Governance_Form_Approval_Request__c req : formReq)
        {
            Project_Governance_Form_Approval_Request__c reqUpdate = new Project_Governance_Form_Approval_Request__c(id = req.id);
            reqUpdate.Status__c = 'Pending Approval';
            requestsToAdd.add(reqUpdate);

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setWhatID(req.id);
            //if(!bccEmails.isEmpty())
                //mail.setBCCAddresses(new List<String>(bccEmails));
            mail.setTemplateID(templateID);
            mail.setSaveAsActivity(true);
            mail.setTargetObjectId(req.Approver__c);
            mail.setReplyTo(emailToApexEmailAddress);

          
          

            Messaging.SingleEmailMessage mailbcc = new Messaging.SingleEmailMessage();
            if(!bccEmails.isEmpty()){
                mailbcc.setWhatID(req.id);
                mailbcc.setTemplateID(BcctemplateID);
                mailbcc.setBccAddresses(new List<String>(bccEmails));
                mailbcc.setTargetObjectId(req.Approver__c);
                //mail.setCcAddresses(ccAddresses);
            }

            system.debug('*************created email***************************'+bccEmails);
            if(!attList.isEmpty())
            {
                if(attSize > 9216)
                {
                    String[] toAddresses = new String[]{govForm.Project__r.Owner.Email};
                    attMail.setToAddresses(toAddresses);
                    attMail.setSubject('Attachments not sent for Project ' + govForm.Project__r.Name);
                    attMail.setHTMLBody('Attachment were not sent for the project ' + govForm.Project__r.Name + ' - you have exceeded size limit of 10MB');
                    sendFailMail = true;
                }
                else
                {
                    mail.setFileAttachments(attList);
                }
            }
            
         if(mailbcc!=null){
             // bccMails.add(mailbcc);
             allMails.add(mailbcc);
             }
             allMails.add(mail);
        }

    if(!govForm.isLocked__c)
        {
            govForm.isLocked__c = true;
            if(govForm.Recordtype.DeveloperName=='AIP_Form')
            govForm.Date_of_AIP_request__c=system.today();
            if(govForm.Recordtype.DeveloperName=='Commitment_Form')
            govForm.Date_of_Commitment_Request__c=system.today();
            if(govForm.Recordtype.DeveloperName=='FMA_Form' ||govForm.Recordtype.DeveloperName=='FMA_Commitment')
            govForm.Date_of_FMA_Request__c=system.today();
            govForm.Override_Lock_Toggle__c =!(govForm.Override_Lock_Toggle__c);
            try
            {
                update govForm;
            }
            catch(Exception e)
            {
                system.debug('*********Exception encountered********'+e.getMessage());
            }
        }

        if(!requestsToAdd.isEmpty())
        {
            try
            {
                update requestsToAdd;
                Messaging.sendEmail(allMails);
                //Messaging.sendEmail(bccMails);

            }
            catch(Exception e)
            {
                system.debug('*********Exception encountered********'+e.getMessage());
                msg = e.getMessage();
            }
        }

        if(sendFailMail)
        {
            try
            {
                Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ attMail });
            }
            catch(Exception e)
            {
                system.debug('*********Exception encountered********'+e.getMessage());
                msg = e.getMessage();
            }
        }
        system.debug('msg:'+msg);
        return msg;
    }
}
  • June 02, 2014
  • Like
  • 0
I have been trying to create a contact record once a user record of a specific profile has been created. I am able to save the trigger but cannot create a user record. I have posted a code below. 
trigger createContact on User (before insert) {     
List<Contact> ur = new List<Contact>();
    for (User usr: Trigger.New)
    //IF(Usr.UserRoleId == '00EK0000000KRUR'){
          ur.add (new Contact(
                     FirstName = Usr.FirstName,
                     LastName = Usr.LastName));
                  //  }   
         
   
   insert ur;
 }
  • November 19, 2014
  • Like
  • 1

I am getting the following error while trying to put one of my custom object related list on Account Detail page.

 

Content cannot be displayed: 'Application__c' is not a valid child relationship name for entity Account

 

Here is my vf page

<apex:page standardController="Account">
<apex:relatedList list="Application__c"/>
</apex:page>

 I am able to save the vf page but when I put the page on Account details page, its not showing anything but an error.

  • May 21, 2013
  • Like
  • 1
I have 3 record types and 2 visualforce pages. I want to override "New" button and display visualforce pages based on the record type selected. But there is a record type for which I want to display standard record creation page and not a visualforce page. How do I do that?
  • October 11, 2016
  • Like
  • 0
Hello everyone,

I am tryign to use this validation rule and getting some errors.  Can someone please help me.

ISPICKVAL(Specific_Product_Type__c, "Trust Services")&& RecordType.Name="Investments/Insurance - BCIS"  OR(
ISPICKVAL(Probability__c,"50%",ISPICKVAL(Probability__c,"75%"),ISPICKVAL(Probability__c,"100%")) 
&& ISBLANK(Specialty_Partner__c)
I'm trying to display opportunity product names to opportunity custom field. The trigger is working fine but it displays only last record name. eg. If I have 4 products related to opportunity, it display 4th product name and not display the first three. I would like to display each product name with ',' in between. here is my code. Any idea what need to ​be added in order to display all related products name.
Trigger OppProdLine on Opportunity (before update) {

list<opportunity> sl = trigger.new;

list<opportunityLineItem> slnu = new list<opportunityLineItem>([select id ,product2.name, opportunityId from opportunitylineitem where opportunityId =: trigger.new[0].id]);

string productName='';

for(opportunityLineItem opp : slnu){

 productName = opp.product2.name;

}

for(Opportunity opp : trigger.new){

 opp.Opportunity_Prod__c = productName;


}


}
  • May 03, 2016
  • Like
  • 0
Hi,
How do I fire trigger only when a record is created by Connection User in salesforce to salesforce integration. i.e. We have SF2SF integration and a trigger updates certain lookup fields but I want to fire that trigger only when a record is created by connection user. I tried CreatedById = '[Id of the connection user] ' but that did not work. Please assist.

Thanks
UT
  • April 02, 2015
  • Like
  • 0
Hi, I have a few record types in our system and each record type has different page layout. Each page has almost sames fields with small variations. I have created a visualforce page pdf for the detail page and a button on detail page, which by clicking generates pdf of the detail page. But since there is a small variation in each page layout, I don't want to create many visualforce pages. Is there a way to display fields dynamically on visualforce pdf based on the record type/page layout?
  • December 29, 2015
  • Like
  • 0
I am trying to create a contact record upon user record creation. It should only create a contact record if certain user role are selected. I have the following trigger which works fine if I remove IF statement for ROLE...could someone please help? Again, I have been trying to create a contact record upon creating user record only when certain ROLE are set for the user...Thanks..
trigger CreateContact on User (after insert) {    
    List<Contact> ur = new List<Contact>();
    for (User usr: Trigger.New){
	     if(usr.UserRole.Name=='role name'|| usr.UserRole.Name=='role name')      
              ur.add (new Contact(
                         FirstName = usr.FirstName,
                         LastName = usr.LastName));
                         
    }
	if(!ur.isEmpty())
        insert ur; 
}

 
  • November 25, 2014
  • Like
  • 0
Hi,

 My requirement is i have two user have same profile and same role, i need give permit for read and write like that to particular tab like account for one user  only,
other user not able to access anything.. how can i do this.. please can any one help me...

Thanks,
kathir
Hi.II have a search VF page with various field datatypes.
Like Date,currency.

I would like to display error on Vf page when date format is not being followed.Default format is yyyy-dd-mm.So if user enters other than this format,i want to show an alert or error on Vf page saying to enter correct format.


Please help.
I am getting the following error.
Id value is not valid for the Project_Governance_Form__c standard controller

Here is my code..Could someone please help why I am getting this error?

<apex:page standardController="Project_Governance_Form__c" action="{!URLFOR(CASE(Project_Governance_Form__c.RecordType.Name, 'AIP Form', '/apex/GovForm_Edit_Override_AiP?id={!Project_Governance_Form__c.id}' ,'Commitment', '/apex/GovForm_Edit_Override_Commitment?id={!Project_Governance_Form__c.Id}', 'Commitment / FMA', '/apex/GovForm_Edit_Override_FMA_Commit', '/apex/GovForm_Edit_Override_FMA'))}" >
    
<apex:variable value="{!Project_Governance_Form__c.RecordType.Name}" var="recTypeName"/>
</apex:page>


  • July 16, 2014
  • Like
  • 0
Hi,
I have been trying to pass a record ID to the URL. I have four record types and based on the record type, the edit button is overridden but not able to pass the record id. it gives me error.. see my vfp below.. So if the Record Type if TER Form then if the user clicks EDIT, it should pick up TER Visualforce page and populate fields from the record..Please help..

<apex:page standardController="Project_Governance_Form__c" action="{!URLFOR(CASE(Project__c.RecordType.Name, 'TER Form', '/apex/Form_Edit_Override_TER?id={!Project__c.Id}'))}" >
    <apex:variable value="{!Project__c.RecordType.Name}" var="recTypeName"/>
</apex:page>


  • July 16, 2014
  • Like
  • 0
Is there an easy wasy to override edit button using visualforce page? Currently I have mentioned all the fields I want to display on my visualforce page. I am looking for an easy way so that it can be maintained using the standard page layouts. e.g. override tab view - https://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_tabs.htm
  • July 12, 2014
  • Like
  • 0
Hi,
I have two custom objects with Master-Detail relationship. I would like to send email to the records displayed in the child object using the visualforce email template. Could someone please assist? I came across to the following link but seems like its not helping me.

https://www.salesforce.com/us/developer/docs/pages/Content/pages_email_custom_controller.htm

Thanks,

Urvik
  • July 10, 2014
  • Like
  • 0
Hi everyone,
I have the following controller for sending emails for our custom approval process. There are two emails going out - for Approver and Reviewer. The first issue is, Approvers are getting Approver email and Reviewer email too. The second issue is, Reviewers are getting emails based on number of Approvers. e.g. If there are three approvers then reviewer gets three emails, which is incorrect. Each reviewer should get only one email. Could someone please tell me what is incorrect in my controller?

---------

global class Submit_Form_For_Approval
{
    webService static String submitForApproval(String govID, String attIDs)
    {
        Messaging.SingleEmailMessage attMail = new Messaging.SingleEmailMessage();
        List<Messaging.SingleEmailMessage> allMails = new List<Messaging.SingleEmailMessage>();
        List<Messaging.SingleEmailMessage> bccMails = new List<Messaging.SingleEmailMessage>();
        List<Messaging.EmailFileAttachment> attList = new
        List<Messaging.EmailFileAttachment>();
        List<Project_Governance_Form_Approval_Request__c> requestsToAdd = new List<Project_Governance_Form_Approval_Request__c>();
        List<Project_Governance_Form_Approval_Request__c> formReq = new List<Project_Governance_Form_Approval_Request__c>();
        Set<String> bccEmails = new Set<String>();
        Boolean sendFailMail = false;
        Decimal attSize = 0.0;
        String emailToApexEmailAddress = '';
        String templateID = '';
        String BcctemplateID = '';
        String roleName = '';
        String msg = System.Label.Approval_Process_Request_Submitted_Success_Msg;
        Approval_Process_Setting__c appSetting = Approval_Process_Setting__c.getInstance();


      
        if(appSetting != null)
            roleName = appSetting.Leadership_Role_Name__c;
        
        Project_Governance_Form__c govForm = [SELECT id,Name, Date_of__c,Date_of_Commitment_Request__c,
        Date_of__c,Project__c,isLocked__c,Project__r.Name,Project__r.Owner.Email,
        Project__r.Lead__r.Email,Project__r.Transaction_Lead__r.Email, Override_Lock_Toggle__c,
        Project__r.External_Company_Contact__r.Email, Project__r.Addiitonal__r.Email,
        Project__r.Additional__r.Email, Project__r.Additional__r.Email,
        Recordtype.DeveloperName FROM Project_Governance_Form__c WHERE id = :govID LIMIT 1];

        try
        {
            UserRecordAccess usr = [SELECT HasEditAccess,RecordId FROM UserRecordAccess WHERE UserId = :UserInfo.getUserID() AND RecordId =:govForm.Project__c LIMIT 1];
          
            if(!usr.HasEditAccess)
            {
                return 'NOACCESS';
            }
        }
        catch(Exception e)
        {
            system.debug('**************Exception encountered**************'+e.getMessage());
        }

        if(govForm.Project__r.ERDI_S_E_Lead__r.Email != null)
            bccEmails.add(govForm.Project__r.ERDI_S_E_Lead__r.Email);

        if(govForm.Project__r.Transaction_Lead__r.Email != null)
            bccEmails.add(govForm.Project__r.Transaction_Lead__r.Email);
      
        if(govForm.Project__r.Addiitonal_ERDI_member_1__r.Email != null)
            bccEmails.add(govForm.Project__r.Addiitonal_ERDI_member_1__r.Email);
          
        if(govForm.Project__r.Additional_ERDI_Member_2__r.Email != null)
            bccEmails.add(govForm.Project__r.Additional_ERDI_Member_2__r.Email);
        
        if(govForm.Project__r.Additional_ERDI_Member_3__r.Email != null)
            bccEmails.add(govForm.Project__r.Additional_ERDI_Member_3__r.Email);
      
                     
        if(appSetting != null)
        {
            emailToApexEmailAddress = appSetting.Email_to_Apex_Email_Address__c;
           
            try
            {
                templateID = [SELECT id FROM EmailTemplate WHERE DeveloperName = :appSetting.Email_Template_Developer_Name__c].id;
                BcctemplateID = [SELECT id FROM EmailTemplate WHERE DeveloperName = :appSetting.Bcc_Email_Template_Developer_Name__c].id;
            }
            catch(Exception e)
            {
                msg =System.Label.Approval_Process_Email_Template_Not_Found_Msg;
                return msg;
            }
        }
        else
        {
            msg = System.Label.Approval_Process_Custom_Setting_Not_Defined_Msg;
            return msg;
        }

        formReq = [SELECT id,Approver__c, Reviewer__c, Status__c FROM Project_Governance_Form_Approval_Request__c WHERE Project_Governance_Form__c = :govID AND Status__c = 'Pending for Submission'];

        if(!formReq.isEmpty() && attIDs != '' && attIDs != null)
        {
            List<String> attIDList = attIDs.split(';');
            for(Attachment att : [SELECT Id,Body,Name,BodyLength FROM Attachment WHERE ID IN :attIDList])
            {
                Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
                attSize = attSize + Double.ValueOF(att.BodyLength/1024);
                efa.setFileName(att.Name);
                efa.setBody(att.Body);
                attList.add(efa);
            }
        }
      
        system.debug('***********form data************'+formReq);
        for(Project_Governance_Form_Approval_Request__c req : formReq)
        {
            Project_Governance_Form_Approval_Request__c reqUpdate = new Project_Governance_Form_Approval_Request__c(id = req.id);
            reqUpdate.Status__c = 'Pending Approval';
            requestsToAdd.add(reqUpdate);

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setWhatID(req.id);
            //if(!bccEmails.isEmpty())
                //mail.setBCCAddresses(new List<String>(bccEmails));
            mail.setTemplateID(templateID);
            mail.setSaveAsActivity(true);
            mail.setTargetObjectId(req.Approver__c);
            mail.setReplyTo(emailToApexEmailAddress);

          
          

            Messaging.SingleEmailMessage mailbcc = new Messaging.SingleEmailMessage();
            if(!bccEmails.isEmpty()){
                mailbcc.setWhatID(req.id);
                mailbcc.setTemplateID(BcctemplateID);
                mailbcc.setBccAddresses(new List<String>(bccEmails));
                mailbcc.setTargetObjectId(req.Approver__c);
                //mail.setCcAddresses(ccAddresses);
            }

            system.debug('*************created email***************************'+bccEmails);
            if(!attList.isEmpty())
            {
                if(attSize > 9216)
                {
                    String[] toAddresses = new String[]{govForm.Project__r.Owner.Email};
                    attMail.setToAddresses(toAddresses);
                    attMail.setSubject('Attachments not sent for Project ' + govForm.Project__r.Name);
                    attMail.setHTMLBody('Attachment were not sent for the project ' + govForm.Project__r.Name + ' - you have exceeded size limit of 10MB');
                    sendFailMail = true;
                }
                else
                {
                    mail.setFileAttachments(attList);
                }
            }
            
         if(mailbcc!=null){
             // bccMails.add(mailbcc);
             allMails.add(mailbcc);
             }
             allMails.add(mail);
        }

    if(!govForm.isLocked__c)
        {
            govForm.isLocked__c = true;
            if(govForm.Recordtype.DeveloperName=='AIP_Form')
            govForm.Date_of_AIP_request__c=system.today();
            if(govForm.Recordtype.DeveloperName=='Commitment_Form')
            govForm.Date_of_Commitment_Request__c=system.today();
            if(govForm.Recordtype.DeveloperName=='FMA_Form' ||govForm.Recordtype.DeveloperName=='FMA_Commitment')
            govForm.Date_of_FMA_Request__c=system.today();
            govForm.Override_Lock_Toggle__c =!(govForm.Override_Lock_Toggle__c);
            try
            {
                update govForm;
            }
            catch(Exception e)
            {
                system.debug('*********Exception encountered********'+e.getMessage());
            }
        }

        if(!requestsToAdd.isEmpty())
        {
            try
            {
                update requestsToAdd;
                Messaging.sendEmail(allMails);
                //Messaging.sendEmail(bccMails);

            }
            catch(Exception e)
            {
                system.debug('*********Exception encountered********'+e.getMessage());
                msg = e.getMessage();
            }
        }

        if(sendFailMail)
        {
            try
            {
                Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ attMail });
            }
            catch(Exception e)
            {
                system.debug('*********Exception encountered********'+e.getMessage());
                msg = e.getMessage();
            }
        }
        system.debug('msg:'+msg);
        return msg;
    }
}
  • June 02, 2014
  • Like
  • 0

I am able to save the trigger but getting the following error while creating / editing the record...

 

System.NullPointerException: Attempt to de-reference a null object: Trigger.ComplTrigger: line 34, column 1

 

see my trigger below..

 

trigger ComplTrigger on Complaint_Inquiries__c (before insert, before update) {

 
   Set<id> AccIds = new Set<id>();
   
    for (Complaint_Inquiries__c c : Trigger.new)
        AccIds.add(c.Account__c);
       
  
    Map<id, Account> AccIDmap = new Map<id, Account>([Select Name, BillingStreet,BillingCity, BillingState, BillingPostalCode from Account Where Id in :AccIds]);     
   
    for (Complaint_Inquiries__c Compl : Trigger.new){
        if(Compl.Copy_From_Account__c == true){
        Compl.Business_Name__c      = AccIDmap.get(Compl.Account__c).Name;
        Compl.Business_Address__c   = AccIDmap.get(Compl.Account__c).BillingStreet;
        Compl.Business_City__c         = AccIDmap.get(Compl.Account__c).BillingCity;
        Compl.Business_State__c       = AccIDmap.get(Compl.Account__c).BillingState;
        Compl.Business_Zip__c           = AccIDmap.get(Compl.Account__c).BillingPostalCode;
        Compl.Copy_From_Account__c = false;
        }
        }
        
        
        Set<id> ContIds = new Set<id>();
   
    for (Complaint_Inquiries__c c : Trigger.new)
        ContIds.add(c.Contact__c);
       
  
    Map<id, Contact> ContIDmap = new Map<id, Contact>([Select FirstName from Contact Where Id in :ContIds]);     
   
    for (Complaint_Inquiries__c Compl : Trigger.new){
        if(Compl.Copy_From_Contact__c == true){
        Compl.Business_Contact_First_Name__c = ContIDmap.get(Compl.Contact__c).FirstName;
        Compl.Copy_From_Contact__c = false;
        }
        }
        
        
        

}

 Please help

  • August 21, 2013
  • Like
  • 0


public with sharing class ComplaintInquiriesHandler { private boolean isExecuting = false; private integer batchSize = 0; public ComplaintInquiriesHandler(boolean triggerIsExecuting, integer size){ isExecuting = triggerIsExecuting; batchSize = size; } public void OnBeforeUpdate(Complaint_Inquiries__c[] oldComp, Complaint_Inquiries__c[] updatedComp){ For(Complaint_Inquiries__c Compl:updatedComp) { if (Compl.Copy_From_Account__c == true){ list<Account> Acc = [Select id,BillingStreet from Account where Name=:Compl.Business_Name__c limit 1]; if(Acc!=null){ Compl.Business_Address__c = Account.BillingStreet; } Compl.Copy_From_Account__c = false; } } } }

 Could someone please assist? I am not able to figure out the issue here.

  • August 20, 2013
  • Like
  • 0