• Mohd Nabeel
  • NEWBIE
  • 85 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 33
    Replies
<apex:page docType="html-5.0" showHeader="false" sidebar="false" controller="StripeCheckout" standardStylesheets="false">
    <!---->
  <head>
    <apex:slds />
    <script src="https://js.stripe.com/v3/"></script>
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
    <script type="text/javascript">
    function stripePopup(){
        console.log("inside the function")
        var stripe = Stripe("pk_test_something");
        stripe.redirectToCheckout({
        lineItems: [
        {price: '400', quantity: 1},
        ],
        mode: 'payment',
        successUrl: 'https://google.com',
        cancelUrl: 'https://tesla.com',
    })
    .then(function(result) {
        console.log(result);
    });
    }

    </script>
  </head>
    <br/>
    <h1 style="text-align:center"><b>Stripe Checkout Demo</b></h1>
      <center>
          <apex:image value="{!URLFOR($Resource.product)}"/>
      </center>
      <div class="slds-table--header-fixed_container" style="height:450px;">
          <div class="slds-scrollable_y" style="height:100%;">
          <apex:form id="ContributionRequestForm">
              <center>
                  <br/>
                  <apex:commandButton styleClass="slds-button slds-button--brand" onclick="stripePopup()" value="Pay now"/>
              </center>    
          </apex:form>
          </div>
      </div>
</apex:page>

I have made a VF page with only a Pay now button. I took help from Stripe official docs https://stripe.com/docs/js/checkout/redirect_to_checkout, but whenever I am clicking on pay now it is redirecting me back to my VF page but it is not redirecting to the Stripe Checkout page. What is wrong here? Thanks
Here is the validation rule, which is working fine, but there is one more thing i want to do that if a reporting agent is assigning any case to itself then it should be able to assign it irrespective of the status.
AND(ISCHANGED(OwnerId), NOT(OR(ISPICKVAL(Status,"Escalated"),ISPICKVAL(Status , "Re-Routed"))),NOT($Profile.Name<>"Reporting Agent"))
from this rule it is also validating that if the user agent is assigning a case to itself then it is firing this, How can i fix this?
//Handler Class
public class InvoiceClass {
    public static void invoiceProduct(List<Invoice_Product__c> invProduct){
        for(Invoice_Product__c inv : invProduct){
            inv.Total_Price__c = inv.Price__c * inv.Quantity__c;
        }
    }
    public static void invoiceAmountUpdate(List<Invoice_Product__c> invProduct ){
        Set<id> invoiceIds = new Set<id>();
        for(Invoice_Product__c invPro : invProduct){
            if(invPro.InvoiceLookUp__c != Null){
                invoiceIds.add(invPro.InvoiceLookUp__c);   
            }
        }
        List<Invoice__c> invoices = [Select id, Total_Amount__c, (Select id, Total_Price__c
                                                                  From Invoice_Products__r)
                                     From Invoice__c where id in : invoiceIds];
        for(Invoice__c inv: invoices){
            inv.Total_Amount__c = 0;
            for(Invoice_Product__c invProd : inv.Invoice_Products__r){
                inv.Total_Amount__c += invProd.Total_Price__c;
            }
        }
        if(invoices != Null){
            update invoices;
        }
    }
}
//trigger
trigger InvoiceProductTrigger on Invoice_Product__c (before insert, before update, after insert, after update, after delete) {
    if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
        InvoiceClass.invoiceProduct(Trigger.new);
    }
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)){
        InvoiceClass.invoiceAmountUpdate(Trigger.new);
    } 
    if(Trigger.isAfter && Trigger.isDelete){
        InvoiceClass.invoiceAmountUpdate(Trigger.old);
    }
    if(Trigger.isAfter && Trigger.isUpdate){
        InvoiceClass.invoiceAmountUpdate(Trigger.old);
    }
}

 
Create two field on Account: 1 - Amount X (Number), 2 - Amount Y (Number).
Create a two fields on Contact: 1 - Amount Type (Picklist: Amount X, Amount Y), 2 - Amount (Number)
You have to rollup amount in the correct field on account record and it depends on the Amount Type field on Contact.

I also need to bulkify this code.
I know the definition of these Id's;. But i dont know what is the use of these ids and why we use it..Even with the accountId we can relate objects the why use these.Whoid is equivalent to Contact's ID or Lead Id then why we dont use those id's instead of who id or what id
Create object : Candidate__c
Fields : (All Text fields)
First Name
Last Name
Email
Brokerage
Manage Brokerage
Candidate Status (Webinar - Attended , Webinar -Not Attended)
User Created ( checkbox)


On insert:
1. Create Account if Brokerage !=null
2. Create another account if Manage Brokerage != null and set parentId = Brokerage account id (created in 1 point)
3. Create new contact record and set accountId = Manage Brokerage account id (created in 2 point)
   create new field candidate__c(lookup) on contact and fill it with Condidate__c record id
4. Create task record for contact record (created in point 3)
Task.WhoId = contactId
Task.WhatId = Candidate__c
Task.Subject = 'Portal Contact Setup';

The line which is commented is giving me a DML exception dont know why? i think it is not getting id there.. I know i am asking too many questions or may be silly questions but i want some clear point on these.
public static void brokeragePortal(List<Candidate_Brokerage__c> candBrokRecords){
        Map<id, Contact> contListMap = new Map<id, Contact>();
        Map<id, Account> accListMap = new Map<id, Account>();
        Map<id, Account> newAccListMap = new Map<id, Account>();
        Map<id, Task> taskListMap = new Map<id, Task>();
                
        for(Candidate_Brokerage__c brokerCand: candBrokRecords){   
            if(brokerCand.Brokerage__c != NULL){
                Account acc = new Account(name = 'Brokerage Account');
                if(!accListMap.containsKey(brokerCand.id)){
                    accListMap.put(brokerCand.id, acc);
                }                
            }
        }
        if(accListMap.values().size()>0){
            insert accListMap.values();
        }
        for(Candidate_Brokerage__c cand: candBrokRecords){
            if(cand.Brokerage__c != NULL && cand.Manage_Brokerage__c != NULL){
                Account manageBrokAcc = new Account(name = 'Manage Brokerage Account');
                if(accListMap.containsKey(cand.id)){
                    manageBrokAcc.ParentId = accListMap.get(cand.id).id;
                }
                if(!newAccListMap.containsKey(cand.id)){
                    newAccListMap.put(cand.id, manageBrokAcc);
                }
                Contact newContact = new Contact(lastName = 'John Doe');
                if(!contListMap.containsKey(cand.id)){
                    contListMap.put(cand.id, newContact);
                }
            }
        }
        if(newAccListMap.values().size()>0){
            insert newAccListMap.values();
        }
        if(contListMap.values().size()>0){
            insert contListMap.values();
        }
        for(Candidate_Brokerage__c cand: candBrokRecords){
            if(cand.Brokerage__c != NULL && cand.Manage_Brokerage__c != NULL){
                Task newTask = new Task();
                if(contListMap.containsKey(cand.Id)){
                    newTask.WhoId = contListMap.get(cand.Id).id;
                }
                //newTask.WhatId = cand.id;
                newTask.Subject = 'Portal Contact Setup';
                if(!taskListMap.containsKey(cand.Id)){
                    taskListMap.put(cand.id, newTask);
                }
            }
        }
        if(taskListMap.values().size()>0){
            insert taskListMap.values();
        }
    }
//Trigger
trigger BrokerageTrigger on Candidate_Brokerage__c (after insert) {
    if(Trigger.isAfter && Trigger.isInsert){
    	AccountContact.brokeragePortal(Trigger.new);    
    }
}

 
public static void HireContactForm(List<HireForm__c> HireList){
        List<Contact> contList = new List<Contact>();
        List<Case> CaseList = new List<Case>();
        
        for(HireForm__c hireForm: HireList){
            Contact con = new Contact();
            con.FirstName = hireForm.First_Name__c;
            con.LastName =  hireForm.Last_Name__c;
            con.Phone = hireForm.Phone__c;
            con.Email = hireForm.Email__c;
            contList.add(con);
        }
        insert contList;
        for(Contact cont: contList){
            Case cases = new Case();
            cases.Status = 'New';
            cases.ContactId = cont.Id;
            caseList.add(cases);
        }
        insert caseList;    
        
        
        for(HireForm__c hire: HireList){
            for(Case c: CaseList){
                if(hire.status__c == 'Completed'){
                    c.Status = 'Closed';
                }
                update c;
            }
            
        }
    }
//Trigger
trigger ContactFormTrigger on HireForm__c (before insert, before update, after update) {
    if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
        AccountContact.HireContactForm(Trigger.new);
    }
}

 
public static void DeadIntel(list<Contact> cont){
        Set<Id> accIds = new Set<Id>();
        for(Contact conList : cont){
            if(conList.accountId!=null){
                accIds.add(conList.accountId);    
            }
            
        }
        
        Map<Id, List<Contact>> accContactMap = new Map<Id, List<Contact>>();
        List<Account> accUpdateList = new List<Account>();
        for(Contact obj : [SELECT accountId,Dead__c
                           FROM Contact
                           WHERE accountId IN :accIds]){
                               
                               List<Contact> contLists;
                               if(accContactMap.containsKey(obj.accountId)){
                                   contLists = accContactMap.get(obj.accountId);
                               }else{
                                   contLists = new List<Contact>();
                               }
                               contLists.add(obj);
                               accContactMap.put(obj.accountId, contLists);
                           }
        for(Id accId : accContactMap.keySet()){
            Integer count_of_Dead = 0;
            Integer total_con = accContactMap.get(accId).size();
            if(accContactMap.get(accId).size() > 1){              
                for(integer i =0 ; i<accContactMap.get(accId).size(); i++)
                    if(accContactMap.get(accId)[i].Dead__c == true){
                        count_of_Dead++;
                    }
            }
            if((count_of_Dead/total_con)*100 > 70)
                accUpdateList.add(new Account(id = accId, needintel__c = true));   
        }   
        if(!accUpdateList.isEmpty()){
            update accUpdateList;
        }
    }
//Trigger
trigger UpdateContact on Contact (after update) {
if(Trigger.isUpdate && Trigger.isAfter){
        AccountContact.DeadIntel(Trigger.new);
    }
}

 
trigger InsertContact on Account (after insert, after update) {
if( Trigger.isUpdate && Trigger.isAfter){
        AccountContact.AccountBillingModify(Trigger.new);
    }
}


//Handler class

public class AccountContact{
 public static void AccountBillingModify(List<Account> acctList){
        
        Map<Id, Account> accsWithContactMap = new Map<Id, Account>([select id, BillingPostalCode, (select Id, MailingPostalCode from Contacts) 
                                                                    from account
                                                                    where id in :acctList]);
        for (Account acc: acctList){
            for(Contact con : accsWithContactMap.get(acc.Id).Contacts){
                if(acc.BillingPostalCode != con.MailingPostalCode){                    
                    acc.OutofZip__c = true;
                }
            }
        }
    }
}

 
trigger BillingAddressMod on Account (after update) {
    public static boolean flag=true;
    If(flag==true) {
        account acc = [select id, BillingPostalCode from account where id in : trigger.new];
        List<contact> contList = [Select id, MailingPostalCode from Contact];
        Set <Id> setContact = new Set<id>();
        for(Contact cont: contList){
            setContact.add(cont.MailingPostalCode);
        }
        Map<id,Contact> mapAccount = [Select MailingPostalCode from Contact where AccountId in: acc];
        
        for (contact con : contList)
        {
            if(acc.BillingPostalCode != con.MailingPostalCode)
            {
                contList.add(con);
            }
            
        }
        If(contList.size()>=1)
        {
            acc.OutofZip__c = true;   
        }
        flag=false;
        
        update acc;
        
    }
}

 

Hi,
I am trying to create an account and when the account is created a contact will be created and the checkbox should be true..

i have created an account but the checkbox remainis false and when i am again trying to create a new contact i am getting this error... UpdateContact: execution of AfterInsert caused by: System.SObjectException: Invalid field Account Id for AggregateResult Class.AccountContact.updateCheckBox: line 22, column 1 Trigger.UpdateContact: line 3, column 1

public class AccountContact{
    public static void onBefore(List<Account> acctList){
        List<Contact> conList = new List<Contact>();
        for(Account acc: acctList){
            Contact con = new Contact(AccountId = acc.ID);
            con.FirstName = 'Info';
            con.LastName = 'Default';
            con.Email = 'info@websitedomain.tld';
            acc.OnlyDefaultContact__c = TRUE;
            conList.add(con);
        }
        insert conList;
    }
    public static void updateCheckBox(List<Contact> contList){
        Set<id> accountIds = new Set<id>();
        for(Contact con: contList){
            accountIds.add(con.Accountid);
        }
        List<Account> updateAccount = new List<Account>();
        for(AggregateResult ar: [Select count(id), AccountId from Contact where AccountId IN
                                 : accountids group by AccountId having count(id)>1]){
			updateAccount.add(new Account(id = (id)ar.get('Account Id'),OnlyDefaultContact__c
                                = FALSE));
        }
    }
}

//trigger

trigger InsertContact on Account (after insert) {
    if(Trigger.isBefore && Trigger.isInsert){
    	AccountContact.onBefore(Trigger.new);
    }
}


trigger UpdateContact on Contact (after insert) {
	if(Trigger.isInsert && Trigger.isAfter){
		AccountContact.updateCheckBox(Trigger.new);
    }
}
HI, 
I am trying to call my method in the anonymous window but it is showing me (Line: 1, Column: 24 Unexpected token '('.) this error. The class is static so it is not necessary to make an object or instance of that class..
AccountContact.onBefore(Account Name='asdf');
This is my code i am inserting an account with the account name
<apex:page docType="html-5.0" showHeader="false" sidebar="false" controller="StripeCheckout" standardStylesheets="false">
    <!---->
  <head>
    <apex:slds />
    <script src="https://js.stripe.com/v3/"></script>
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
    <script type="text/javascript">
    function stripePopup(){
        console.log("inside the function")
        var stripe = Stripe("pk_test_something");
        stripe.redirectToCheckout({
        lineItems: [
        {price: '400', quantity: 1},
        ],
        mode: 'payment',
        successUrl: 'https://google.com',
        cancelUrl: 'https://tesla.com',
    })
    .then(function(result) {
        console.log(result);
    });
    }

    </script>
  </head>
    <br/>
    <h1 style="text-align:center"><b>Stripe Checkout Demo</b></h1>
      <center>
          <apex:image value="{!URLFOR($Resource.product)}"/>
      </center>
      <div class="slds-table--header-fixed_container" style="height:450px;">
          <div class="slds-scrollable_y" style="height:100%;">
          <apex:form id="ContributionRequestForm">
              <center>
                  <br/>
                  <apex:commandButton styleClass="slds-button slds-button--brand" onclick="stripePopup()" value="Pay now"/>
              </center>    
          </apex:form>
          </div>
      </div>
</apex:page>

I have made a VF page with only a Pay now button. I took help from Stripe official docs https://stripe.com/docs/js/checkout/redirect_to_checkout, but whenever I am clicking on pay now it is redirecting me back to my VF page but it is not redirecting to the Stripe Checkout page. What is wrong here? Thanks
Here is the validation rule, which is working fine, but there is one more thing i want to do that if a reporting agent is assigning any case to itself then it should be able to assign it irrespective of the status.
AND(ISCHANGED(OwnerId), NOT(OR(ISPICKVAL(Status,"Escalated"),ISPICKVAL(Status , "Re-Routed"))),NOT($Profile.Name<>"Reporting Agent"))
from this rule it is also validating that if the user agent is assigning a case to itself then it is firing this, How can i fix this?
//Handler Class
public class InvoiceClass {
    public static void invoiceProduct(List<Invoice_Product__c> invProduct){
        for(Invoice_Product__c inv : invProduct){
            inv.Total_Price__c = inv.Price__c * inv.Quantity__c;
        }
    }
    public static void invoiceAmountUpdate(List<Invoice_Product__c> invProduct ){
        Set<id> invoiceIds = new Set<id>();
        for(Invoice_Product__c invPro : invProduct){
            if(invPro.InvoiceLookUp__c != Null){
                invoiceIds.add(invPro.InvoiceLookUp__c);   
            }
        }
        List<Invoice__c> invoices = [Select id, Total_Amount__c, (Select id, Total_Price__c
                                                                  From Invoice_Products__r)
                                     From Invoice__c where id in : invoiceIds];
        for(Invoice__c inv: invoices){
            inv.Total_Amount__c = 0;
            for(Invoice_Product__c invProd : inv.Invoice_Products__r){
                inv.Total_Amount__c += invProd.Total_Price__c;
            }
        }
        if(invoices != Null){
            update invoices;
        }
    }
}
//trigger
trigger InvoiceProductTrigger on Invoice_Product__c (before insert, before update, after insert, after update, after delete) {
    if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
        InvoiceClass.invoiceProduct(Trigger.new);
    }
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)){
        InvoiceClass.invoiceAmountUpdate(Trigger.new);
    } 
    if(Trigger.isAfter && Trigger.isDelete){
        InvoiceClass.invoiceAmountUpdate(Trigger.old);
    }
    if(Trigger.isAfter && Trigger.isUpdate){
        InvoiceClass.invoiceAmountUpdate(Trigger.old);
    }
}

 
Create two field on Account: 1 - Amount X (Number), 2 - Amount Y (Number).
Create a two fields on Contact: 1 - Amount Type (Picklist: Amount X, Amount Y), 2 - Amount (Number)
You have to rollup amount in the correct field on account record and it depends on the Amount Type field on Contact.

I also need to bulkify this code.
Create object : Candidate__c
Fields : (All Text fields)
First Name
Last Name
Email
Brokerage
Manage Brokerage
Candidate Status (Webinar - Attended , Webinar -Not Attended)
User Created ( checkbox)


On insert:
1. Create Account if Brokerage !=null
2. Create another account if Manage Brokerage != null and set parentId = Brokerage account id (created in 1 point)
3. Create new contact record and set accountId = Manage Brokerage account id (created in 2 point)
   create new field candidate__c(lookup) on contact and fill it with Condidate__c record id
4. Create task record for contact record (created in point 3)
Task.WhoId = contactId
Task.WhatId = Candidate__c
Task.Subject = 'Portal Contact Setup';

The line which is commented is giving me a DML exception dont know why? i think it is not getting id there.. I know i am asking too many questions or may be silly questions but i want some clear point on these.
public static void brokeragePortal(List<Candidate_Brokerage__c> candBrokRecords){
        Map<id, Contact> contListMap = new Map<id, Contact>();
        Map<id, Account> accListMap = new Map<id, Account>();
        Map<id, Account> newAccListMap = new Map<id, Account>();
        Map<id, Task> taskListMap = new Map<id, Task>();
                
        for(Candidate_Brokerage__c brokerCand: candBrokRecords){   
            if(brokerCand.Brokerage__c != NULL){
                Account acc = new Account(name = 'Brokerage Account');
                if(!accListMap.containsKey(brokerCand.id)){
                    accListMap.put(brokerCand.id, acc);
                }                
            }
        }
        if(accListMap.values().size()>0){
            insert accListMap.values();
        }
        for(Candidate_Brokerage__c cand: candBrokRecords){
            if(cand.Brokerage__c != NULL && cand.Manage_Brokerage__c != NULL){
                Account manageBrokAcc = new Account(name = 'Manage Brokerage Account');
                if(accListMap.containsKey(cand.id)){
                    manageBrokAcc.ParentId = accListMap.get(cand.id).id;
                }
                if(!newAccListMap.containsKey(cand.id)){
                    newAccListMap.put(cand.id, manageBrokAcc);
                }
                Contact newContact = new Contact(lastName = 'John Doe');
                if(!contListMap.containsKey(cand.id)){
                    contListMap.put(cand.id, newContact);
                }
            }
        }
        if(newAccListMap.values().size()>0){
            insert newAccListMap.values();
        }
        if(contListMap.values().size()>0){
            insert contListMap.values();
        }
        for(Candidate_Brokerage__c cand: candBrokRecords){
            if(cand.Brokerage__c != NULL && cand.Manage_Brokerage__c != NULL){
                Task newTask = new Task();
                if(contListMap.containsKey(cand.Id)){
                    newTask.WhoId = contListMap.get(cand.Id).id;
                }
                //newTask.WhatId = cand.id;
                newTask.Subject = 'Portal Contact Setup';
                if(!taskListMap.containsKey(cand.Id)){
                    taskListMap.put(cand.id, newTask);
                }
            }
        }
        if(taskListMap.values().size()>0){
            insert taskListMap.values();
        }
    }
//Trigger
trigger BrokerageTrigger on Candidate_Brokerage__c (after insert) {
    if(Trigger.isAfter && Trigger.isInsert){
    	AccountContact.brokeragePortal(Trigger.new);    
    }
}

 
public static void HireContactForm(List<HireForm__c> HireList){
        List<Contact> contList = new List<Contact>();
        List<Case> CaseList = new List<Case>();
        
        for(HireForm__c hireForm: HireList){
            Contact con = new Contact();
            con.FirstName = hireForm.First_Name__c;
            con.LastName =  hireForm.Last_Name__c;
            con.Phone = hireForm.Phone__c;
            con.Email = hireForm.Email__c;
            contList.add(con);
        }
        insert contList;
        for(Contact cont: contList){
            Case cases = new Case();
            cases.Status = 'New';
            cases.ContactId = cont.Id;
            caseList.add(cases);
        }
        insert caseList;    
        
        
        for(HireForm__c hire: HireList){
            for(Case c: CaseList){
                if(hire.status__c == 'Completed'){
                    c.Status = 'Closed';
                }
                update c;
            }
            
        }
    }
//Trigger
trigger ContactFormTrigger on HireForm__c (before insert, before update, after update) {
    if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isBefore){
        AccountContact.HireContactForm(Trigger.new);
    }
}

 
Hi, I trying to put an action on my custom object list view layout, but the action not appearing as an option, and when I created one from the layout edit page not worked too. I'm using lightning, some one please help me?
Create object : Candidate__c
Fields : (All Text fields)
First Name
Last Name
Email
Brokerage
Manage Brokerage
Candidate Status (Webinar - Attended , Webinar -Not Attended)
User Created ( checkbox)


On insert:
1. Create Account if Brokerage !=null
2. Create another account if Manage Brokerage != null and set parentId = Brokerage account id (created in 1 point)
3. Create new contact record and set accountId = Manage Brokerage account id (created in 2 point)
   create new field candidate__c(lookup) on contact and fill it with Condidate__c record id
4. Create task record for contact record (created in point 3)
Task.WhoId = contactId
Task.WhatId = Candidate__c
Task.Subject = 'Portal Contact Setup';
 
  • July 19, 2018
  • Like
  • 1