• Devid
  • NEWBIE
  • 35 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
Hi Team ,
I have wrote a trigger. When ever the record is updated I need update the pick list field which is Car_Type__c. But I'm gettng below error. Please let me know the why the error message is getting and solution for it.

Error Message :   execution of AfterUpdate caused by: System.FinalException: Record is read-only

Triggger :

trigger DiscountonCarprice on V_Customers__c (after insert,after update) {
    if(Trigger.isInsert && Trigger.isAfter ){
       DiscountonCarpriceController.Discount(trigger.new); 
    }
    else if(Trigger.isupdate && Trigger.isAfter ){
        system.debug('Im in else block');
      DiscountonCarpriceController.DiscountAfterUpdate(trigger.new,trigger.oldmap);   
    }
}

=================================
Apex Class :

public class DiscountonCarpriceController {
    Public static void discount(list<V_Customers__c> vclist){
        set<id> vcId = new set<id>();
         list<V_Customers__c> updateVc = new list<V_Customers__c>();
        for(V_Customers__c vcCust:vclist){
            vcId.add(vcCust.id);
            
        }
        list<V_Customers__c> updateVcList = [select id,name,Country__c,Discount__c from V_Customers__c where id =: vcId];
        for(V_Customers__c vc: updateVcList){
            if(vc.Country__c=='INDIA'){
                vc.Discount__c = 20;
                //updateVc.add(vc);
            }
                else if(vc.Country__c=='UK'){
                vc.Discount__c = 15;
                  //  updateVc.add(vc);
            }
                else if(vc.Country__c=='USA'){
                vc.Discount__c = 10;
                   // updateVc.add(vc);
            }
            
        }
        update updateVcList;
    }
    Public static void DiscountAfterUpdate(list<V_Customers__c> vclist,map<id,V_Customers__c> vcoldMap){ 
         set<id> vcId = new set<id>();
        for(V_Customers__c vcCust:vclist){
            vcId.add(vcCust.id);
            
        }
        system.debug('vclist****'+vclist);
         system.debug('vcoldMap****'+vcoldMap);
        list<V_Customers__c> vclist1 = new list<V_Customers__c>();
          list<V_Customers__c> vclist2 = [select id,name,Country__c,Discount__c,Car_Type__c from V_Customers__c where Id IN :vcId];
        for(V_Customers__c vc:vclist){
            if(vcoldMap.get(vc.id).id == vc.id ){
                 vc.Car_Type__c = 'Hatchback';
               vclist1.add(vc);
                
                system.debug('Discount Amount***'+ vc.Discount__c);
            } 
            
        }
       
            system.debug('vclist1***'+ vclist1);
            update vclist1;
             system.debug('vclist1***'+ vclist1);
        
        
    }
}

=============================
Error Screenshot:
FYI:
User-added image
Hi All,
I have created a Lightning component(Aura) and using this salesforce mobile app and I have created a button when the user clicks on that button it redirects the user to square APP.
Here is the Square API doc link:
https://developer.squareup.com/docs/pos-api/web-technical-reference
according to the square doc their different link to redirect on the square app for iOS and Android.
My code works well in iOS but in android, it shows a problem
Here is my code:
component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
	<lightning:button label="Pay" title="Pay" onclick="{! c.handleClick }"/>
</aura:component>

controller:
({
	handleClick : function(component, event, helper) {
        let redirectionLink = '';
		if( $A.get("$Browser.isAndroid") ){
            redirectionLink = 'intent:#Intent;action=com.squareup.pos.action.CHARGE;package=com.squareup;S.browser_fallback_url=https://www.google.com/;S.com.squareup.pos.WEB_CALLBACK_URI=https://devid305001-developer-edition.ap16.force.com/squareTest;S.com.squareup.pos.CLIENT_ID=sq0idp-v1YAxLJ-mgUnO-rvQmmNIw;S.com.squareup.pos.API_VERSION=v2.0;i.com.squareup.pos.TOTAL_AMOUNT=100;S.com.squareup.pos.CURRENCY_CODE=USD;S.com.squareup.pos.TENDER_TYPES=com.squareup.pos.TENDER_CARD,com.squareup.pos.TENDER_CASH;end';
        }else if( $A.get("$Browser.isIOS") ){
            redirectionLink = 'square-commerce-v1://payment/create?data=%7B%22amount_money%22%3A%7B%22amount%22%3A%22500%22%2C%22currency_code%22%3A%22USD%22%7D%2C%22callback_url%22%3A%22https%3A%2F%2Fdevid305001-developer-edition.ap16.force.com%2FsquareTest%22%2C%22client_id%22%3A%22sq0idp-v1YAxLJ-mgUnO-rvQmmNIw%22%2C%22version%22%3A%221.3%22%2C%22notes%22%3A%22notes%20for%20the%20transaction%22%2C%22options%22%3A%7B%22supported_tender_types%22%3A%5B%22CREDIT_CARD%22%2C%22CASH%22%2C%22OTHER%22%2C%22SQUARE_GIFT_CARD%22%2C%22CARD_ON_FILE%22%5D%7D%7D';
        }
        let urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
            "url": redirectionLink
        });
        urlEvent.fire();
	}
})
The error in android is here:
User-added image

I am not able to understand what I am doing wrong. for iOS this code is working perfectly means successfully redirecting to the square app and doing payment but when I do same things in android it is showing above error.

I also created VF page and added two different link in anchor tag when I tried to open from here its working fine here my site link:

https://devid305001-developer-edition.ap16.force.com/squareTest

and is the VF page code (SquareTest):
<apex:page > 
    <a href="intent:#Intent;action=com.squareup.pos.action.CHARGE;package=com.squareup;S.browser_fallback_url=https://www.google.com/;S.com.squareup.pos.WEB_CALLBACK_URI=https://devid305001-developer-edition.ap16.force.com/squareTest;S.com.squareup.pos.CLIENT_ID=sq0idp-v1YAxLJ-mgUnO-rvQmmNIw;S.com.squareup.pos.API_VERSION=v2.0;i.com.squareup.pos.TOTAL_AMOUNT=100;S.com.squareup.pos.CURRENCY_CODE=USD;S.com.squareup.pos.TENDER_TYPES=com.squareup.pos.TENDER_CARD,com.squareup.pos.TENDER_CASH;end">
        Click here to open square app in android for payment
    </a>
    <br/><br/><br/>
    <a href="" id="iosLink">
        Click here to open square app in iOS for payment
    </a>
    
    <script>
    var dataParameter = {
        amount_money: {
            amount:        "500",
            currency_code: "USD"
        },
        
        // Replace this value with your application's callback URL
        callback_url: "https://devid305001-developer-edition.ap16.force.com/squareTest",
        
        // Replace this value with your application's ID
        client_id: "sq0idp-v1YAxLJ-mgUnO-rvQmmNIw",
        
        version: "1.3",
        notes: "notes for the transaction",
        options: {
            supported_tender_types: ["CREDIT_CARD","CASH","OTHER","SQUARE_GIFT_CARD","CARD_ON_FILE"]
        }
    };
    
    document.getElementById('iosLink').href =
        "square-commerce-v1://payment/create?data=" +
        encodeURIComponent(JSON.stringify(dataParameter));
    </script>

</apex:page>

 
  • October 30, 2020
  • Like
  • 0
This below code is working perfect with 10 mb but when I try to upload more than 10mb file then it throws an error.
 
private string TOKEN = 'access_token_of_dropbox_app';//
string folderPathWithFileName;
for(ContentVersion contentVersionRec : [SELECT PathOnClient, VersionData FROM contentversion
										   WHERE contentdocumentId IN : contentDocumentIdSet){
	folderPathWithFileName = '/Root/'+PathOnClient;//PathOnClient contains file name with extension like imagefile.png
	system.debug('###folderPathWithFileName=>'+folderPathWithFileName);
	Http http = new Http();
	HttpRequest httpReq = new HttpRequest();
	httpReq.setEndpoint('https://content.dropboxapi.com/2/files/upload');
	httpReq.setMethod('POST');
	httpReq.setHeader('Authorization','Bearer ' + TOKEN);
	httpReq.setHeader('Content-Type','application/octet-stream');
	httpReq.setHeader('Dropbox-API-Arg','{"path":"'+folderPath+'","mode":{".tag":"add"}}');
	httpReq.setBodyAsBlob(contentVersionRec.VersionData);
	HttpResponse httpResponse = http.send(httpReq);
	System.debug('res###' + httpResponse);
	System.debug('res.getBody()###'+httpResponse.getBody());
	if (httpResponse.getStatusCode() == 200) {
		System.debug('##Congratulations File Uploaded successfully :) =>'+httpResponse.getBody());
	}else{
		//Handle code here when file not uploaded. 
	}
}

The error is : System.CalloutException: Exceeded max size limit of 12000000 with request size 12001280

I know(limit while sending http request) reason of this error but there should be a way to send more than 10mb file. Actually I need to upload up to 100 mb file from http request(Salesoforce) to dropbox.

If anyone have any idea please let me know.
  • July 27, 2020
  • Like
  • 0
I have written a trigger on lead to enhance the lead conversion process. When converting a lead, the user has the ability to create a new account or choose existing. If a user tries to create a new account we need to run validation to see if there is already an account with the same custom field value (Company_Id__c). If there is another account with the same Company_Id__c, then we need to show an error message to the user.
But I got stuck here in code to get to know how to check that user want to create new account or selected existing account?

Here is my code.
 
trigger LeadTrigger on Lead (After Update) {
	Map<Id, Lead> = Trigger.oldMap;
	for(Lead lead : Trigger.new){
		if(lead.isConverted && oldMap.get(lead.id).isConverted) continue; //only process newly converted leads
		//check converted leads only.
		if (oldMap.get(lead.Id).isConverted == false && lead.isConverted) {
			//How to check in code that user already existing account or new one he want to create.
		}
	}
}
Please help
  • July 13, 2020
  • Like
  • 0
string input = 'Lead Informations
Program1: Installation
Lead #: 7894512
Name: Salesforce Dev
Email: test@gmail.com
Phone: (000) 123-7897';

//Marker for final ring duraion
Integer intIndex = input.lastindexOf('Lead Information');

system.debug('### intIndex'+intIndex);
//Remove all characters before intIndex
String newString = input.right(input.length()-intIndex);

system.debug('### newString'+newString);
system.debug('### newString ENd');


// split whole input into lines
string[] lines = newString.split('[\n]+');

string regex = '([^:]+):([^:]+)';

Pattern MyPattern = Pattern.compile(regex);

// Apply regex to every line
for(string inputLine : lines){
	matcher myMatcher = myPattern.matcher(inputLine.trim());
	if(myMatcher.matches() && myMatcher.hitEnd() && myMatcher.groupCount() == 2){
		system.debug('**** Match :'+myMatcher.group(1).trim() + '=>'+myMatcher.group(2).trim());
	}
	else{
		system.debug('No match: line :'+ inputLine);
	}
}


String can be like this:
Example 1:
Lead Informations
Program1: Installation
Lead #: 7894512
Name: Salesforce Dev
Email: test@gmail.com
Phone: (000) 123-7897

Example 2:
Lead Informations
Program1:
Installation
Lead #:
7894512
Name:
Salesforce Dev
Email:
test@gmail.com
Phone: (000) 123-7897

Example 3:
Lead Informations
Program1:

Installation

Lead #:

7894512

Name:

Salesforce Dev

Email:

test@gmail.com

Phone: (000) 123-7897

 

I want to store all Lead #, Name, Email and Phone values to object fields But got stuck how to parse these strings mention above. above code is working for single line break but it does work for multiple line breaks.

  • June 05, 2020
  • Like
  • 0
Hi Team ,
I have wrote a trigger. When ever the record is updated I need update the pick list field which is Car_Type__c. But I'm gettng below error. Please let me know the why the error message is getting and solution for it.

Error Message :   execution of AfterUpdate caused by: System.FinalException: Record is read-only

Triggger :

trigger DiscountonCarprice on V_Customers__c (after insert,after update) {
    if(Trigger.isInsert && Trigger.isAfter ){
       DiscountonCarpriceController.Discount(trigger.new); 
    }
    else if(Trigger.isupdate && Trigger.isAfter ){
        system.debug('Im in else block');
      DiscountonCarpriceController.DiscountAfterUpdate(trigger.new,trigger.oldmap);   
    }
}

=================================
Apex Class :

public class DiscountonCarpriceController {
    Public static void discount(list<V_Customers__c> vclist){
        set<id> vcId = new set<id>();
         list<V_Customers__c> updateVc = new list<V_Customers__c>();
        for(V_Customers__c vcCust:vclist){
            vcId.add(vcCust.id);
            
        }
        list<V_Customers__c> updateVcList = [select id,name,Country__c,Discount__c from V_Customers__c where id =: vcId];
        for(V_Customers__c vc: updateVcList){
            if(vc.Country__c=='INDIA'){
                vc.Discount__c = 20;
                //updateVc.add(vc);
            }
                else if(vc.Country__c=='UK'){
                vc.Discount__c = 15;
                  //  updateVc.add(vc);
            }
                else if(vc.Country__c=='USA'){
                vc.Discount__c = 10;
                   // updateVc.add(vc);
            }
            
        }
        update updateVcList;
    }
    Public static void DiscountAfterUpdate(list<V_Customers__c> vclist,map<id,V_Customers__c> vcoldMap){ 
         set<id> vcId = new set<id>();
        for(V_Customers__c vcCust:vclist){
            vcId.add(vcCust.id);
            
        }
        system.debug('vclist****'+vclist);
         system.debug('vcoldMap****'+vcoldMap);
        list<V_Customers__c> vclist1 = new list<V_Customers__c>();
          list<V_Customers__c> vclist2 = [select id,name,Country__c,Discount__c,Car_Type__c from V_Customers__c where Id IN :vcId];
        for(V_Customers__c vc:vclist){
            if(vcoldMap.get(vc.id).id == vc.id ){
                 vc.Car_Type__c = 'Hatchback';
               vclist1.add(vc);
                
                system.debug('Discount Amount***'+ vc.Discount__c);
            } 
            
        }
       
            system.debug('vclist1***'+ vclist1);
            update vclist1;
             system.debug('vclist1***'+ vclist1);
        
        
    }
}

=============================
Error Screenshot:
FYI:
User-added image
On Case object under attachment related lists section , we have to override the upload files button and when we click it we should have two options one is public and another one is private , if user clicks public then he should be able to add the attachment should be visible both in Salesforce as well as in community portal.
If it is private then it has to be visible only in salesforce ( right now the default is private which is out of the box ).
Hi All,
I have created a Lightning component(Aura) and using this salesforce mobile app and I have created a button when the user clicks on that button it redirects the user to square APP.
Here is the Square API doc link:
https://developer.squareup.com/docs/pos-api/web-technical-reference
according to the square doc their different link to redirect on the square app for iOS and Android.
My code works well in iOS but in android, it shows a problem
Here is my code:
component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
	<lightning:button label="Pay" title="Pay" onclick="{! c.handleClick }"/>
</aura:component>

controller:
({
	handleClick : function(component, event, helper) {
        let redirectionLink = '';
		if( $A.get("$Browser.isAndroid") ){
            redirectionLink = 'intent:#Intent;action=com.squareup.pos.action.CHARGE;package=com.squareup;S.browser_fallback_url=https://www.google.com/;S.com.squareup.pos.WEB_CALLBACK_URI=https://devid305001-developer-edition.ap16.force.com/squareTest;S.com.squareup.pos.CLIENT_ID=sq0idp-v1YAxLJ-mgUnO-rvQmmNIw;S.com.squareup.pos.API_VERSION=v2.0;i.com.squareup.pos.TOTAL_AMOUNT=100;S.com.squareup.pos.CURRENCY_CODE=USD;S.com.squareup.pos.TENDER_TYPES=com.squareup.pos.TENDER_CARD,com.squareup.pos.TENDER_CASH;end';
        }else if( $A.get("$Browser.isIOS") ){
            redirectionLink = 'square-commerce-v1://payment/create?data=%7B%22amount_money%22%3A%7B%22amount%22%3A%22500%22%2C%22currency_code%22%3A%22USD%22%7D%2C%22callback_url%22%3A%22https%3A%2F%2Fdevid305001-developer-edition.ap16.force.com%2FsquareTest%22%2C%22client_id%22%3A%22sq0idp-v1YAxLJ-mgUnO-rvQmmNIw%22%2C%22version%22%3A%221.3%22%2C%22notes%22%3A%22notes%20for%20the%20transaction%22%2C%22options%22%3A%7B%22supported_tender_types%22%3A%5B%22CREDIT_CARD%22%2C%22CASH%22%2C%22OTHER%22%2C%22SQUARE_GIFT_CARD%22%2C%22CARD_ON_FILE%22%5D%7D%7D';
        }
        let urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
            "url": redirectionLink
        });
        urlEvent.fire();
	}
})
The error in android is here:
User-added image

I am not able to understand what I am doing wrong. for iOS this code is working perfectly means successfully redirecting to the square app and doing payment but when I do same things in android it is showing above error.

I also created VF page and added two different link in anchor tag when I tried to open from here its working fine here my site link:

https://devid305001-developer-edition.ap16.force.com/squareTest

and is the VF page code (SquareTest):
<apex:page > 
    <a href="intent:#Intent;action=com.squareup.pos.action.CHARGE;package=com.squareup;S.browser_fallback_url=https://www.google.com/;S.com.squareup.pos.WEB_CALLBACK_URI=https://devid305001-developer-edition.ap16.force.com/squareTest;S.com.squareup.pos.CLIENT_ID=sq0idp-v1YAxLJ-mgUnO-rvQmmNIw;S.com.squareup.pos.API_VERSION=v2.0;i.com.squareup.pos.TOTAL_AMOUNT=100;S.com.squareup.pos.CURRENCY_CODE=USD;S.com.squareup.pos.TENDER_TYPES=com.squareup.pos.TENDER_CARD,com.squareup.pos.TENDER_CASH;end">
        Click here to open square app in android for payment
    </a>
    <br/><br/><br/>
    <a href="" id="iosLink">
        Click here to open square app in iOS for payment
    </a>
    
    <script>
    var dataParameter = {
        amount_money: {
            amount:        "500",
            currency_code: "USD"
        },
        
        // Replace this value with your application's callback URL
        callback_url: "https://devid305001-developer-edition.ap16.force.com/squareTest",
        
        // Replace this value with your application's ID
        client_id: "sq0idp-v1YAxLJ-mgUnO-rvQmmNIw",
        
        version: "1.3",
        notes: "notes for the transaction",
        options: {
            supported_tender_types: ["CREDIT_CARD","CASH","OTHER","SQUARE_GIFT_CARD","CARD_ON_FILE"]
        }
    };
    
    document.getElementById('iosLink').href =
        "square-commerce-v1://payment/create?data=" +
        encodeURIComponent(JSON.stringify(dataParameter));
    </script>

</apex:page>

 
  • October 30, 2020
  • Like
  • 0
string input = 'Lead Informations
Program1: Installation
Lead #: 7894512
Name: Salesforce Dev
Email: test@gmail.com
Phone: (000) 123-7897';

//Marker for final ring duraion
Integer intIndex = input.lastindexOf('Lead Information');

system.debug('### intIndex'+intIndex);
//Remove all characters before intIndex
String newString = input.right(input.length()-intIndex);

system.debug('### newString'+newString);
system.debug('### newString ENd');


// split whole input into lines
string[] lines = newString.split('[\n]+');

string regex = '([^:]+):([^:]+)';

Pattern MyPattern = Pattern.compile(regex);

// Apply regex to every line
for(string inputLine : lines){
	matcher myMatcher = myPattern.matcher(inputLine.trim());
	if(myMatcher.matches() && myMatcher.hitEnd() && myMatcher.groupCount() == 2){
		system.debug('**** Match :'+myMatcher.group(1).trim() + '=>'+myMatcher.group(2).trim());
	}
	else{
		system.debug('No match: line :'+ inputLine);
	}
}


String can be like this:
Example 1:
Lead Informations
Program1: Installation
Lead #: 7894512
Name: Salesforce Dev
Email: test@gmail.com
Phone: (000) 123-7897

Example 2:
Lead Informations
Program1:
Installation
Lead #:
7894512
Name:
Salesforce Dev
Email:
test@gmail.com
Phone: (000) 123-7897

Example 3:
Lead Informations
Program1:

Installation

Lead #:

7894512

Name:

Salesforce Dev

Email:

test@gmail.com

Phone: (000) 123-7897

 

I want to store all Lead #, Name, Email and Phone values to object fields But got stuck how to parse these strings mention above. above code is working for single line break but it does work for multiple line breaks.

  • June 05, 2020
  • Like
  • 0