• Rajesh-InLoveWithSFdc
  • NEWBIE
  • 30 Points
  • Member since 2017
  • Salesforce Developer


  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
I am looking to create a VF page exactly same of the Account List page just without the "New Button". How would I go about creating this? Sample code would be great!

Here is my first try at it!

<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock title="Account Details">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Account.AccountNumber}"/>
                <apex:inputField value="{!Account.Type}"/>
                <apex:inputField value="{!Account.NumberOfEmployees}"/>
                <apex:inputField value="{!Account.Industry}"/>
                <apex:inputField value="{!Account.Phone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    
</apex:page> 
Can anybody please share the test class for  below transaction Security Apex 


global class DisableSSNChatterMSGPolicyCondition implements TxnSecurity.PolicyCondition {
 public boolean evaluate(TxnSecurity.Event e) {
   
  String str= e.data.get('Body');
 Pattern p = Pattern.compile('(\\d{3}\\-\\d{2}-\\d{4})');
  Matcher m = p.matcher(str);

 if (m.find())
 {
  return true;
 }
 else 
 {
 return false;
 }
}
 }
Hi All,

Requirement : Connect two SFDC Dev Org using REST if Account Name in Teaget Exists through Error to User that Account Name already present in Target Org .

Steps a)  I have created Visualforce Pages and used Standard and Extension Controller as below 
                VF
                <apex:page standardcontroller="Account" extensions="MyController" tabStyle="Account">
    
 <apex:form >
      <!-- <apex:actionFunction action="{!InsertRecord}" name="InsertRecord_JS" oncomplete="CallWebService_JS();"/>
        <apex:actionFunction action="{!CallWebService}" name="CallWebService_JS" /> -->
      <apex:pageBlock >
        <apex:pageBlockSection columns="2" title="Account Information" collapsible="false" >
            <apex:inputField value="{!Account.Name}"/>
            <apex:inputField value="{!Account.Phone}"/>
            <apex:inputField value="{!Account.Site}"/>
            <apex:inputField value="{!Account.Type}"/>
            <apex:inputField value="{!Account.Industry}"/>
            <apex:inputField value="{!Account.AccountNumber}"/>
            <apex:inputField value="{!Account.AnnualRevenue}"/>
          <!--  <apex:inputcheckbox onclick="javaScrpt()" label="Check" value="{!test}"> -->
          <apex:actionRegion >
          <div align="center">
          <apex:outputLabel for="c1" value="Show Additional Information" style="font-weight:900"/>
          <apex:inputcheckbox label="Check" id="c1" value="{!checkinvalue}"> 
          <apex:actionSupport event="onclick" action="{!ActnMethod}" reRender="changeit" />
          </apex:inputcheckbox>
           </div>
            </apex:actionRegion>
      </apex:pageblockSection>
             
             <apex:outputPanel id="changeit">
             <apex:pageBlockSection columns="2" title="Additional Information" rendered="{!show}"  >
             <apex:inputField value="{!Account.CustomerPriority__c}"/>
             <apex:inputField value="{!Account.SLAExpirationDate__c}"/>
             <apex:inputField value="{!Account.SLA__c}"/>
             <apex:inputField value="{!Account.SLASerialNumber__c}"/>
             <apex:inputField value="{!Account.Active__c}"/>
             </apex:pageblockSection>
             </apex:outputPanel>
              
              <apex:pageblockButtons >
              <!--<div><input name="DoAction" class="btn" type="button" value="Do Action" onclick="InsertRecord_JS();return false;"/></div>-->
              <apex:commandButton action="{!Save1}" value="Save1"  />
              </apex:pageblockButtons>
              
       </apex:pageBlock> 
      
      
      
    </apex:form> 
    
  <!-- <script>
      function javaScrpt(){
       actionFunName(); 
      }
    </script>--->
     
</apex:page>

Custom COntroller 

Public class MyController {
Public Boolean show{get;set;}
Public Boolean checkinvalue{get;set;}
public Account acc {get;set;}
public MyController(ApexPages.StandardController controller) {
acc= (Account)controller.getRecord();
 }
public string ActnMethod(){
 if (checkinvalue==true)
    {
      show = true;
      }
      else
    {
      show = false;
      }
     return null;
    }
 Public pagereference Save1()
 {
     Integer r = SendAccountUsingRestApi.createAccount(acc.Name);
     System.debug('Value of r is'+r);
     if(r==200)
     {
         acc.Name.addError('Already Exist in the System');
     }
     else
     {
     upsert acc;
    return(new pagereference('/'+acc.id));
         
         
     }
     return null;
 }
}

b)  I have created the REST connection class to retrieve the result 
   public class SendAccountUsingRestApi {
String clientId='Ihavegivenmyclientsecret';
    String clientsecret='IhavegivenmyCLientID';
    string username='targetorguserdIdandPassword';
    String password='password+securitytokn';
    String accesstoken_url='https://login.salesforce.com/services/oauth2/token';
    String authurl='https://login.salesforce.com/services/oauth2/authorize';
    
  public class deserializeResponse{
      public String id;
      public String access_token;   
   }
    public String ReturnAccessToken(SendAccountUsingRestApi Acc){
        String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password; 
        Http h= new Http();
        HttpRequest req= new HttpRequest();
        req.setBody(reqbody);
        req.setMethod('POST');
       req.setEndpoint('https://ap4.salesforce.com/services/oauth2/token'); 
        HttpResponse res=h.send(req);
        System.debug(res.getBody()+'###1203res');
        deserializeResponse resp1=(deserializeResponse)JSON.deserialize(res.getBody(),deserializeResponse.class);
        System.debug(resp1+'###1203deserializeresponse');
        return resp1.access_token;
    }
 public static Integer  createAccount(String AccountName){
        SendAccountUsingRestApi acc1= new SendAccountUsingRestApi();
        String accessToken=acc1.ReturnAccessToken(acc1);
        Integer s;
        System.debug(accessToken+'###0012');
        if(accessToken!=null){
            String jsonstr='{"Name":"'+ AccountName +'"}';
            Http h2= new Http();
            HttpRequest req2= new HttpRequest();
            System.debug('Value of Auth Token is '+accessToken);
            req2.setHeader('Authorization','Bearer ' + accessToken);
            req2.setHeader('Content-Type','application/json');
            req2.setHeader('accept','application/json');
            req2.setBody(jsonstr);
            req2.setMethod('GET');
            req2.setEndpoint('https://ap4.salesforce.com/services/data/v39.0/sobjects/Account/');
            HttpResponse res2=h2.send(req2);
            s = res2.getStatusCode();}
          return s;
 }}

Issues: When i am creating Account which is not present in Target Org then also it is throwing Error in My Source Org ,But its creating the Account in Target Org as well, I am not able to understand why if someone can explain would be great help
Hi All.
 I have a workflow which updates Field A to True and I have process Builder to execute when FieldA is true on Same Object .
 I have checked re-evaluate workflow checkbox but still process builder is not executig please let me know if i am doing anything wrong ?

Regards,
Rajesh
HI Guys ,
 I need to understand few things regarding Execution Rule 
  
As per I understand below is Order
System Validation 
Before Trigger
Custom Validation 

When we are saying system validation is this only Layout Specific(Like made field required on layout) System validation  or including Validation lets we have mad field required during its creation ?

I was trying few thing like i created a field and made it required through before Trigger and Then Made it Blank again in after trigger so record is saving properly but when i made field required during field creation and i am trying to make it blank in after trigger then it is throwing error required field missing although system validation happens  before  after trigger .

Can anybody please explain ?

Regards,
Rajesh

HI All, I do not have much experience in Salesforce but i am learning and i came acroos this statement "You can use an object to change its own field values using trigger.new, but only in before triggers. In all after triggers, trigger.new is not saved, so a runtime exception is thrown"

I have two issue now 
a)  As it is mentioned we can not update Object in After Trigger but we can update it like below 
trigger AccountNumberUpdate on Account (before insert,after insert) {
list<Account> up = new list<Account>();


for (Account c : Trigger.new)
{
if (Trigger.isBefore)
{
if (String.isBlank(c.AccountNumber))
{
 c.AccountNumber.addError('Account Number Can not be bLanks');
  
}}

if (Trigger.isAfter)

{
 Account a = [Select Id,AccountNumber from Account where id = :c.id];
 a.AccountNumber = NULL;
 up.add(a);

}
update up;
}

b) (Refre Above Code)Second issue with order of execution lets say i have custom validation on field here AccountNumber and in all after trigger again i am making AccountNumber blank in that  case error will not throw because custom validation does not takes place after trigger . Is it limitation of salesforce ?

Regards,
Rajesh 

HI All, I do not have much experience in Salesforce but i am learning and i came acroos this statement "You can use an object to change its own field values using trigger.new, but only in before triggers. In all after triggers, trigger.new is not saved, so a runtime exception is thrown"

I have two issue now 
a)  As it is mentioned we can not update Object in After Trigger but we can update it like below 
trigger AccountNumberUpdate on Account (before insert,after insert) {
list<Account> up = new list<Account>();


for (Account c : Trigger.new)
{
if (Trigger.isBefore)
{
if (String.isBlank(c.AccountNumber))
{
 c.AccountNumber.addError('Account Number Can not be bLanks');
  
}}

if (Trigger.isAfter)

{
 Account a = [Select Id,AccountNumber from Account where id = :c.id];
 a.AccountNumber = NULL;
 up.add(a);

}
update up;
}

b) (Refre Above Code)Second issue with order of execution lets say i have custom validation on field here AccountNumber and in all after trigger again i am making AccountNumber blank in that  case error will not throw because custom validation does not takes place after trigger . Is it limitation of salesforce ?

Regards,
Rajesh 
I am looking to create a VF page exactly same of the Account List page just without the "New Button". How would I go about creating this? Sample code would be great!

Here is my first try at it!

<apex:page standardController="Account">
    <apex:form >
        <apex:pageBlock title="Account Details">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Account.AccountNumber}"/>
                <apex:inputField value="{!Account.Type}"/>
                <apex:inputField value="{!Account.NumberOfEmployees}"/>
                <apex:inputField value="{!Account.Industry}"/>
                <apex:inputField value="{!Account.Phone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    
</apex:page> 
Hi All.
 I have a workflow which updates Field A to True and I have process Builder to execute when FieldA is true on Same Object .
 I have checked re-evaluate workflow checkbox but still process builder is not executig please let me know if i am doing anything wrong ?

Regards,
Rajesh
HI Guys ,
 I need to understand few things regarding Execution Rule 
  
As per I understand below is Order
System Validation 
Before Trigger
Custom Validation 

When we are saying system validation is this only Layout Specific(Like made field required on layout) System validation  or including Validation lets we have mad field required during its creation ?

I was trying few thing like i created a field and made it required through before Trigger and Then Made it Blank again in after trigger so record is saving properly but when i made field required during field creation and i am trying to make it blank in after trigger then it is throwing error required field missing although system validation happens  before  after trigger .

Can anybody please explain ?

Regards,
Rajesh

HI All, I do not have much experience in Salesforce but i am learning and i came acroos this statement "You can use an object to change its own field values using trigger.new, but only in before triggers. In all after triggers, trigger.new is not saved, so a runtime exception is thrown"

I have two issue now 
a)  As it is mentioned we can not update Object in After Trigger but we can update it like below 
trigger AccountNumberUpdate on Account (before insert,after insert) {
list<Account> up = new list<Account>();


for (Account c : Trigger.new)
{
if (Trigger.isBefore)
{
if (String.isBlank(c.AccountNumber))
{
 c.AccountNumber.addError('Account Number Can not be bLanks');
  
}}

if (Trigger.isAfter)

{
 Account a = [Select Id,AccountNumber from Account where id = :c.id];
 a.AccountNumber = NULL;
 up.add(a);

}
update up;
}

b) (Refre Above Code)Second issue with order of execution lets say i have custom validation on field here AccountNumber and in all after trigger again i am making AccountNumber blank in that  case error will not throw because custom validation does not takes place after trigger . Is it limitation of salesforce ?

Regards,
Rajesh 

I'm writing a trigger for new opportunity products to populate a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product).

This is my trigger:

trigger SetProductCategory on OpportunityLineItem (after insert) {

            for (OpportunityLineItem opplineitem: Trigger.new){

                         opplineitem.Product_Category__c= opplineitem.PricebookEntry.Product2.Product_Category_new__c;

              }     
}

I get this error message:

execution of AfterInsert caused by: System.FinalException: Record is read-only

I have tried with before insert;in this case there aren't errors but the value Product category it's not saved on Opportunity Line item.

 

I have found that:

In a after insert trigger is not allowed change field using trigger.new

 

Please can you suggest a solution for this? i would like to copy the value Product category (Product) on Product Category (Opportunity Product) after the insert of the new opportunity products.

Thanks in advantage for any advice.

Br