+ Start a Discussion
Pete Watson 5Pete Watson 5 
Hi All, 

Any help on the below would be much appreciated.

have the below trigger and its working perfectly in the sandbox but after deploying to prod I am getting a CPU time limit exeeded failure... 

trigger ProfileTrigger on User (before insert, before update) {
    List<Id> userIds = new List<Id>();
    List<Case> cases = new List<Case>();
    List<Case> casesToUpdate = new List<Case>();
    for(User u: Trigger.new) {
        if(u.out_of_office__c==True) {
            userIds.add(u.Id);
        }
        for (case c : (cases = [SELECT id, Status FROM Case where ownerId IN:userIds]))
            IF(c.Status == 'Assigned' || c.Status == 'Working' ||c.Status == 'Escalated'){
            c.Reassign_to_Queue__c=true;
            casesToUpdate.add(c);
        }
        update casesToUpdate;
    }

Many thanks in advance! 
Pete
Best Answer chosen by Pete Watson 5
AnudeepAnudeep (Salesforce Developers) 
Hi Pete, 

I recommend adding Limits.getCpuTime() to check where there is the maximum consumption is
 
Integer cpuStart = Limits.getCpuTime();
System.debug('Before For loop = ' +cpuStart);

    for(User u: Trigger.new) {
        if(u.out_of_office__c==True) {
            userIds.add(u.Id);
 System.debug('CPU time consumed in loop ' + (Limits.getCpuTime() - cpuStart));
        }

// repeat this for the other for loop

// Check CPU time before DML

 cpuStart = Limits.getCpuTime();

 System.debug('Before DML = ' +cpuStart);

 update casesToUpdate;

I suggest comparing the debug logs between your sandbox and production when running this code

Also, review this help article

Anudeep
Michael MMichael M 
Hello, I was wondering if someone can help me write the apex to parse a string like this (changed the details of it, but the concept is still what I need):

https://abc-park-store.facilities.facilities.org/contact-form-block/

From that string, I only want everything between "https://" and ".facilities...". Also, I want to replace the "-" with spaces, and capitalize each word. So from the above string, I would want it to say "Abc Park Store". How can I parse the string as such? Thank you.
Best Answer chosen by Michael M
AnudeepAnudeep (Salesforce Developers) 
Hi Michael, 

Verified in my org. The following code gives the output you are looking for
 
String str = 'https://abc-park-store.facilities.facilities.org/contact-form-block/';
String str2 = str.substringAfter('//').substringBefore('.facilities'); 
System.debug('split string is' + str.substringAfter('//').substringBefore('.facilities')); 
System.debug('string' + str2.substring(0,1).toUpperCase()+str2.substring(1,3)+'-'+str2.substring(4,5).toUpperCase()+str2.substring(5,8)+'-'+str2.substring(9,10).toUpperCase()+str2.substring(10,14));

I referred to the methods available in the string class

Let me know if it helps

Anudeep
Craig WoodmanCraig Woodman 
I had a question, but answered it on my own. So since my search didn't reveal anything, I figured I would post it here in case anyone else is looking.

Does a Before Update flow (or one that is triggered by record create or change, that saves before the record is updated) work with lead creation by web-to-lead?

I had not seen this in any documentation. And searches didn't show anything. So I figured I would do some tests on my own.

I set up a test flow to write text to the Lead Description field on creation, that says "The before update flow worked!!!" I then went to the website, downloaded a catalog, and checked the description field. The text was written, with no delay to the web to lead record.

My use case for this is changing the record type automatically on a web to lead record, which passes in certain values. It works perfectly!

I hope that this helps anyone who is looking for this information!
Best Answer chosen by Craig Woodman
Craig WoodmanCraig Woodman
Thanks Anutej,  While this can be completed with a trigger, I wanted to show the functions of the new before save flow actions, and answer a question that I could not find about these flows.  Hopefully people can see this and see both solutions.
Michael MMichael M 
Hello, we need to give access to a user to login as other users. However, we do not want them to be able to edit meta-data, and preferably we don't want them to be able to login as system administrators. 

 I am trying to use the "delegated administrator" feature, however, I don't see how to give them the ability to login as other users without giving them the "modify all data" permission, but the problem is that gives them access to metadata. Is there any way around this? 
Best Answer chosen by Michael M
ShirishaShirisha (Salesforce Developers) 
Hi Michael,

Greetings!

If you need some other user to login as other user then that user should have the Modify All Data permission which will allow the user to access the Metadata as well.

So,it is not possible to provide the login as user access without having the Modify All Data permission.

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Haneesh reddy 13Haneesh reddy 13 
Hi 

With the Salesforce API, is there any way to get the current time on the Salesforce server?

Can any one please help me out.
Best Answer chosen by Haneesh reddy 13
AbhishekAbhishek (Salesforce Developers) 
Yes, you can use the getServerTimestamp() method:

GetServerTimestampResult timestamp = binding.getServerTimestamp();

See Salesforce API Docs: getServerTimestamp() (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm)

Thanks.
henry benhenry ben 
Hi,

Iam getting below error while adding products to opportunity.

Error ID:  584898851 - 13966 (- 1775489667)

Do anyone face this error please let me know how to get rid of this error.
Best Answer chosen by henry ben
AbhishekAbhishek (Salesforce Developers) 
Hi,

Based on the error message I suspect that your issue is related to the below-known issue,

https://trailblazer.salesforce.com/issues_view?id=a1p3A000001YonZQAS

If yes please try the workaround.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
John KeplerJohn Kepler 

Hi,

I am creating a validation rule to restrict user from entering amount less than 10000$ when industry type is Corporate. I am facing an error.

Any help will be appreciated.

Thanks

John 

Best Answer chosen by John Kepler
D srinivas 8734D srinivas 8734
Hi John,
AND(ISPICKVAL( Industry , 'Corporate'),amount > 10000)
 
   
copy above formula and paste in Validation rule ..
For more information please visit below link
https://www.etggs.com/services/salesforce/ (https://www.etggs.com/services/salesforce/" style="color:#0563c1; text-decoration:underline)
chandan daschandan das 
Web experince is not working in salesforce1 Mobile
can any one please help me out.
Best Answer chosen by chandan das
AbhishekAbhishek (Salesforce Developers) 
Hi Das,

We retired the Salesforce mobile web experience with the Summer ’20 release.

Previously you were able to access the “Salesforce mobile app” experience on your device in two ways, by installing the downloadable Salesforce mobile app from Google Play or the App Store or via a supported mobile browser. Salesforce removed access to Salesforce on your browser, i.e., the mobile web experience. Starting with the Summer ’20 release, you need to have the Salesforce mobile app installed on your device or use Lightning Experience on iPad Safari.  

Why is Salesforce making this change?

Salesforce wants to focus development on enhancing the Salesforce mobile app to ensure you have a consistent and quality experience, which led us to the decision to retire the mobile browser version.

For further reference, you can check the below-documented article,

https://help.salesforce.com/articleView?id=000349471&language=en_US&type=1&mode=1

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
 
chandan daschandan das 
Hi,

Web experince is not working in salesforce mobile.
Has any one face this issue??

 
Best Answer chosen by chandan das
AbhishekAbhishek (Salesforce Developers) 
Hi Das,

We retired the Salesforce mobile web experience with the Summer ’20 release.

Previously you were able to access the “Salesforce mobile app” experience on your device in two ways, by installing the downloadable Salesforce mobile app from Google Play or the App Store or via a supported mobile browser. Salesforce removed access to Salesforce on your browser, i.e., the mobile web experience. Starting with the Summer ’20 release, you need to have the Salesforce mobile app installed on your device or use Lightning Experience on iPad Safari.  

Why is Salesforce making this change?

Salesforce wants to focus development on enhancing the Salesforce mobile app to ensure you have a consistent and quality experience, which led us to the decision to retire the mobile browser version.

For further reference, you can check the below-documented article,

https://help.salesforce.com/articleView?id=000349471&language=en_US&type=1&mode=1

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
 
Ganesh RajputGanesh Rajput 
I have a requirement to send visualforce(Include Images from the content document ) page attachment as pdf and as a word document. I am done with PDF but stuck at the second requirement want to send it as a word document file.

Controller 
public class CargoQuoteDocController {
public Quote__c quoteObj{get;set;}
    public User user{get;set;}
    public String todysDate{get;set;}
    public String DepartDate{get;set;}
    public List<String> ImageURLs{get;set;}
    public static String Thank_You_Message{get;set;}
    public static String PRICE_INCLUDES{get;set;}
    public static String PRICE_DOES_NOT_INCLUDE{get;set;}
    public String quo;  
    public String D_Date{get;set;}
    public String A_Date{get;set;}
    public ACType__c acType{get;set;}
    public Quote__c quote{get;set;}
    public Opportunity oppo{get;set;}
    public List<String> imgIds = new List<String>();
        
    public void setValues(){
        ImageURLs = new List<String>();
        //List<String> imgIds = new List<String>();
        quo = apexPages.currentPage().getParameters().get('recId');
        PRICE_DOES_NOT_INCLUDE = apexPages.currentPage().getParameters().get('segThree');//quoteTerms.PRICE_DOES_NOT_INCLUDE__c;
        Thank_You_Message = apexPages.currentPage().getParameters().get('segOne');//quoteTerms.Thank_You_Message__c;
        PRICE_INCLUDES = apexPages.currentPage().getParameters().get('segTwo');//quoteTerms.PRICE_INCLUDES__c;
        Integer length = Integer.valueOf(apexPages.currentPage().getParameters().get('length'));
        
        if(length>0){
            for(Integer i=0; i<length;i++){
                imgIds.add(apexPages.currentPage().getParameters().get('img'+i));
            }
        }
        
        for(String img:imgIds){
            ImageURLs.add(URL.getSalesforceBaseUrl().toExternalForm()+'/sfc/servlet.shepherd/version/download/'+img);  	
        }
        
        for(String img:ImageURLs){
            System.debug('ImageURLs == '+img);  
        }
        System.debug(quoteObj);
        
        user = [SELECT Id, Name,Email, MobilePhone FROM User WHERE Id=:UserInfo.getUserId()];
        
        try{
            System.debug('quote == '+quo);
            this.quote = [SELECT ID, Name, Opportunity__c, Aircraft__c, AircraftType__c,Contact_Name__c, Contact_Email__c,
                          (SELECT Id, From__r.Name, To__r.Name,Airway_Time__c,Duration__c,DepartDate__c,DepartTime__c,
                           Temp_Duration__c, ArriveTime__c, ArriveDate__c,PAX__c,CGO__c FROM Quote_Sectors__r) FROM Quote__c WHERE id=:quo];
            this.oppo = [SELECT Id, Name, ContactId, OppID__c, Depart_Date__c, Cargo_lbs__c  
                         FROM Opportunity WHERE Id =: quote.Opportunity__c];  
            this.acType = [SELECT Id,Name, Load__c, Manufacturer__c,Volume__c,MaxKGS__c FROM ACType__c 
                           WHERE Id=:quote.AircraftType__c];
        }catch(Exception e){
            System.debug('Exception == '+e);
        }
        DateTime dT = System.now();
            todysDate = dT.month()+'/'+dT.day()+'/'+dT.year();
        if(oppo.Depart_Date__c != null){
            DateTime dT2 = oppo.Depart_Date__c;
            DepartDate = dT2.month()+'/'+dT2.day()+'/'+dT2.year(); 
            
        }
    }
}
Visualforce Page
<apex:page controller="CargoQuotePdfController" action="{!setValues}" sidebar="false"
           showHeader="false" contentType="application/vnd.msWord" cache="true">
    <center>
        <html>
            <body>
                <div class="slds-m-around--large">
                    <table width="700">
                        <td>
                            <center>
                                <!--Letter Heade-->  
                                <div class="header">
                                    <center>
                                        <!--<img src="{!$Resource.LetterHead}" width="700" hight="80"/>-->
                                    </center>
                                </div>
                                <!--To From Detils -->
                                <table width="700px">
                                    <tr>
                                        <td style="padding-bottom: 10px; width: 75%;text-align:left;">
                                            <h3>CHARTER FLIGHT</h3><br/>
                                            <b>TRIP # {!oppo.OppID__c}</b><br/>
                                            <p>QUOTATION # {!quote.Name}</p> 
                                        </td>
                                        <td style="padding-bottom: 10px; width: 30%;text-align:left;">
                                            DATE: {!todysDate}<br/><br/>
                                            TO: {!quote.Contact_Name__c}<br/>
                                            FROM: {!user.Name}
                                        </td>
                                    </tr>
                                </table>
                            </center>
                            <!--Thank you Message-->
                            <p>
                                <b>Dear {!quote.Contact_Name__c},</b><br/>
                            </p>
                            <div>
                                <div rows="5" cols="80" name="comment" form="usrform">
                                    {!Thank_You_Message}
                                </div>
                            </div>
                            <!--Iternanery-->
                            <p >
                                <br/><b>Proposed Itinerary</b><br/>
                            </p>
                            <table border="1px;"  width="700" >
                                <tr>
                                    <th style="padding-bottom: 10px; width: 15%; background-color:#4db8ff; color:white;"><center>Depart Date/Time</center></th>
                                    <th style="padding-bottom: 10px; width: 20%; background-color:#4db8ff; color:white;"><center>FROM</center></th>
                                    <th style="padding-bottom: 10px; width: 20%; background-color:#4db8ff; color:white;"><center>TO</center></th>
                                    <th style="padding-bottom: 10px; width: 15%; background-color:#4db8ff; color:white;"><center>Arrive<br/>Date/time</center></th>
                                    <th style="padding-bottom: 10px; width: 15%; background-color:#4db8ff; color:white;"><center>Duration</center></th>
                                    <th style="padding-bottom: 10px; width: 15%; background-color:#4db8ff; color:white;"><center>CGO</center></th>
                                </tr>
                                <apex:repeat value="{!quote.Quote_Sectors__r}" var="queSec" id="theRepeat">
                                    <tr>
                                        <td style="padding-bottom: 10px; width: 15%; background-color:#cbd6d3;"><center>{!queSec.DepartDate__c}<br/>{!queSec.DepartTime__c}</center></td>
                                        <td style="padding-bottom: 10px; width: 20%; background-color:#cbd6d3;"><center>{!queSec.From__r.Name}</center></td>
                                        <td style="padding-bottom: 10px; width: 20%; background-color:#cbd6d3;"><center>{!queSec.To__r.Name}</center></td>
                                        <td style="padding-bottom: 10px; width: 15%; background-color:#cbd6d3;"><center>{!queSec.ArriveDate__c}<br/>{!queSec.ArriveTime__c}</center></td>
                                        <td style="padding-bottom: 10px; width: 15%; background-color:#cbd6d3;"><center>{!queSec.Temp_Duration__c}</center></td>
                                        <td style="padding-bottom: 10px; width: 15%; background-color:#cbd6d3;"><center>{!queSec.CGO__c}</center></td>
                                    </tr>
                                </apex:repeat>
                            </table>
                            <br/><br/>
                            <!--Images-->
                            <b>
                                Aircraft Image <br/><br/>
                            </b>
                            <div style="margin-left:50px;width:700;min-height:300px">
                                <apex:repeat value="{!ImageURLs}" var="image" id="Images">
                                    <!--<img src="{!image}" style="width:200px; hight:200px"/>-->
                                    <apex:image url="{!image}" style="width:200px; hight:200px"/>
                                </apex:repeat>
                            </div>
                            <br/><br/>
                            <!--Price payload-->
                            <table border="1px" width="700">
                                <tr>
                                    <td rowspan="2" style="padding-bottom: 10px; width: 50%;margin-left:20px;">
                                        Aircraft: {!acType.Load__c} <br/>&nbsp;&nbsp;
                                        {!acType.Manufacturer__c} <br/>&nbsp;&nbsp;
                                        {!acType.Name}</td>
                                    <td style="margin-left:20px;">PAYLOAD: {!acType.MaxKGS__c}</td>
                                </tr>
                                <tr>
                                    <td style="margin-left:20px;">VOLUME: {!acType.Volume__c}</td>
                                </tr>
                                <tr>
                                    <td colspan="2" style="margin-left:20px;">PRICE:</td>
                                </tr>
                            </table>
                            <br/>
                            <div>
                                <div rows="5" cols="80" name="comment" form="usrform">
                                    {!PRICE_INCLUDES}
                                </div>
                            </div>
                            <br/>
                            <div>
                                <div rows="5" cols="80" name="comment" form="usrform">
                                    {!PRICE_DOES_NOT_INCLUDE}
                                </div>
                            </div><br/>
                            Please let me know if you require any additional information.<br/>
                            Best Regards,
                            
                            <br/><br/><br/>
                            
                            <p>
                                {!user.Name}<br/>
                                {!user.MobilePhone}<br/>
                                {!user.Email}
                            </p>
                        </td>
                    </table> 
                </div>
                <br/>
            </body>
        </html>  
    </center>  
</apex:page>

and this code to send email
 
Messaging.EmailFileAttachment attach2 = new Messaging.EmailFileAttachment();
           	pagereference pageRef2 = Page.CargoQuoteDoc;
            pageRef2.setRedirect(true);
            pageRef2.getParameters().put('recId',recId);
            pageRef2.getParameters().put('segOne',Thank_You_Message);
            pageRef2.getParameters().put('segTwo',PRICE_INCLUDES);
            pageRef2.getParameters().put('segThree',PRICE_DOES_NOT_INCLUDE);
            pageRef2.getParameters().put('length',String.valueOf(length));
            Integer j=0;
            for(String img :imgIds){
                pageRef.getParameters().put('img'+j,img);
                j=j+1;
            }
            
            for(String img :imgIds){
                System.debug('img == '+img);
                
            }
            
            Blob body;//= pageRef.getContent();
            
            if(Test.isRunningTest()) { 
                body = blob.valueOf('Unit.Test');
            } else {
                body = pageRef.getContent();
            }
            attach2.setFileName('Cargo Quote.doc');
            attach2.setBody(body);

when I render visual force page it download on the local system it looks fine with textual content(Images not displaying ) but when I send it as an attachment and open it, it Open in unreadable formatted





%PDF-1.4
%âãÏÓ
2 0 obj <</ColorSpace[/CalRGB<</Gamma[2.2 2.2 2.2]/WhitePoint[0.95043 1 1.09]/Matrix[0.41239 0.21264 0.01933 0.35758 0.71517 0.11919 0.18045 0.07218 0.9504]>>]/Intent/Perceptual/Subtype/Image/Height 137/Filter/FlateDecode/Type/XObject/DecodeParms<</Columns 1131/Colors 3/Predictor 15/BitsPerComponent 8>>/Width 1131/Length 19127/BitsPerComponent 8>>stream
x^í½€Å™÷=&Ïl�V9
$HŒ�³á






Please provide some guidence for this issue 
Best Answer chosen by Ganesh Rajput
Ganesh RajputGanesh Rajput
I did a very silly mistake in code of mail sending 
use 
line(25) 

body = pageRef.getContent();

Instead of

body = pageRef2.getContent();

it's working fine but images still have problem
:)